diff options
Diffstat (limited to 'src/auth.rs')
-rw-r--r-- | src/auth.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/auth.rs b/src/auth.rs index 6879bb6e..e23aa32d 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -825,3 +825,26 @@ impl<'r> FromRequest<'r> for ClientIp { }) } } + +pub struct WsAccessTokenHeader { + pub access_token: Option<String>, +} + +#[rocket::async_trait] +impl<'r> FromRequest<'r> for WsAccessTokenHeader { + type Error = (); + + async fn from_request(request: &'r Request<'_>) -> Outcome<Self, Self::Error> { + let headers = request.headers(); + + // Get access_token + let access_token = match headers.get_one("Authorization") { + Some(a) => a.rsplit("Bearer ").next().map(String::from), + None => None, + }; + + Outcome::Success(Self { + access_token, + }) + } +} |