Struct workstreams_api::auth::Authorization
source · [−]pub struct Authorization {
resources: Vec<String>,
issued_at: String,
expiration_time: Option<String>,
not_before: Option<String>,
pub address: H160,
}
Expand description
An authorization is issued to a particular address based on the fields included in the AuthRequest message. With the Resources vecotr, the API can have even more granular control over the access control of a particular address. All the fields are populated by a AuthRequest.message, from the fields with the same name.
Fields
resources: Vec<String>
issued_at: String
expiration_time: Option<String>
not_before: Option<String>
address: H160
Implementations
sourceimpl Authorization
impl Authorization
sourcepub async fn parse_request(req: &Request) -> Result<String>
pub async fn parse_request(req: &Request) -> Result<String>
Parses a worker::Request for an authentication token, serialized as a JSON object in the body of the request. The authentication token is used to retrieve the related Authorization and verify that the token-holder can access the particular resource.
sourcepub async fn get<T>(env: &Env, token: T) -> Result<Option<Authorization>> where
T: Into<String>,
pub async fn get<T>(env: &Env, token: T) -> Result<Option<Authorization>> where
T: Into<String>,
Get an authorizsation from the Cloudflare KV store, based on a token. The token is retrived from the request with parse_request and used as the key to find the Authorization struct.
sourcepub async fn create(env: &Env, auth: AuthRequest) -> Result<String>
pub async fn create(env: &Env, auth: AuthRequest) -> Result<String>
Creates an Authorization in the Cloudflare KC store based on an AuthRequest. After the message is verified against the signature, the authorization is tied to the address that signed the message. The message is converted to bytes and hashed with a pseudorandomly generated salt. The hash is used as the KEY of the Authorization and returned to the user to be used as a token.
For better UX, we return the token in the form of a cookie that can be used by the web application.
The Authorization value is set to expire at the Cloduflare KV store at the same time that
it expires as an Authorization, defined in the expiration_time
field of the
SIWE::Message. That way, we don’t have to deal with stale records, but Cloudflare takes
care of it. After it expires, the token will no longer be usable and the user will have to
Authorize again and use a new token.
Trait Implementations
sourceimpl Debug for Authorization
impl Debug for Authorization
sourceimpl<'de> Deserialize<'de> for Authorization
impl<'de> Deserialize<'de> for Authorization
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Serialize for Authorization
impl Serialize for Authorization
Auto Trait Implementations
impl RefUnwindSafe for Authorization
impl Send for Authorization
impl Sync for Authorization
impl Unpin for Authorization
impl UnwindSafe for Authorization
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
impl<T> ToRawKvValue for T where
T: Serialize,
impl<T> ToRawKvValue for T where
T: Serialize,
fn raw_kv_value(&self) -> Result<JsValue, KvError>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more