Skip to content

Commit

Permalink
check for headers as part of AuthorizeContex ValidateRequest implemen…
Browse files Browse the repository at this point in the history
…tation
  • Loading branch information
calebbourg committed Nov 7, 2024
1 parent 9895db9 commit 4a28908
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions rama-http/src/layer/auth/require_authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
//! Custom validation can be made by implementing [`ValidateRequest`].

use base64::Engine as _;
use std::{fmt, marker::PhantomData, ops::Deref};
use std::{fmt, marker::PhantomData};

use crate::layer::validate_request::{
ValidateRequest, ValidateRequestHeader, ValidateRequestHeaderLayer,
Expand All @@ -64,6 +64,8 @@ use crate::{
};
use rama_core::Context;

use rama_net::user::UserId;

const BASE64: base64::engine::GeneralPurpose = base64::engine::general_purpose::STANDARD;

impl<S, ResBody> ValidateRequestHeader<S, AuthorizeContext<Basic<ResBody>>> {
Expand Down Expand Up @@ -284,15 +286,15 @@ where
ctx: Context<S>,
req: Request<B>,
) -> Result<(Context<S>, Request<B>), Response<Self::ResponseBody>> {
self.credential.validate(ctx, req).await
}
}
match req.headers().get(header::AUTHORIZATION) {
Some(_) => self.credential.validate(ctx, req).await,
None if self.allow_anonymous => {
ctx.insert(UserId::anonymous());

impl<C> Deref for AuthorizeContext<C> {
type Target = C;

fn deref(&self) -> &Self::Target {
&self.credential
Ok((ctx, req))
}
None => self.credential.validate(ctx, req).await,
}
}
}

Expand Down

0 comments on commit 4a28908

Please sign in to comment.