Repository navigation
Make unathenticated callers the exception - #649
augustuswm wants to merge 6 commits into
Conversation
| header | ||
| .to_str() | ||
| .ok() | ||
| .and_then(|value| value.strip_prefix("Bearer ")) |
There was a problem hiding this comment.
nit: this should technically be case-insensitive. link
| } | ||
|
|
||
| pub fn builtin_unauthenticated_caller(&self) -> Caller<T> { | ||
| fn builtin_unauthenticated_caller(&self) -> Caller<T> { |
There was a problem hiding this comment.
Was it intentional to make this no longer pub? (rfd-api uses it)
There was a problem hiding this comment.
I was intending to yes, but let me see how rfd-api is using it. I can revert this if the needed.
| } | ||
|
|
||
| pub trait UnauthenticatedCaller<T> { | ||
| /// Call to allow an unathenticated caller to be returned. |
There was a problem hiding this comment.
spelling: s/unathenticated/unauthenticated/
| VContextCallerError::Auth(inner) => inner.into(), | ||
| VContextCallerError::Caller(inner) => inner.into(), | ||
| VContextCallerError::Unauthenticated(_) => { | ||
| client_error(ClientErrorStatusCode::UNAUTHORIZED, "Unauthenticated") |
There was a problem hiding this comment.
nit: Could use unauthorized() helper.
| { | ||
| // Ensure there is a bearer, without it there is nothing else to do | ||
| let bearer = BearerAuth::from_request(rqctx).await.map_err(|err| { | ||
| tracing::info!(?err, "Failed to extract bearer auth"); |
There was a problem hiding this comment.
nit: Remove this or change to debug otherwise it'll generate duplicate info loglines for invalid bearer tokens. (bearer.rs:38)
| { | ||
| // Ensure there is a bearer, without it there is nothing else to do | ||
| let bearer = BearerAuth::from_request(rqctx).await.map_err(|err| { | ||
| tracing::info!(?err, "Failed to extract bearer auth"); |
There was a problem hiding this comment.
nit: Doubled log line. Drop to debug or remove. (bearer.rs:38)
| /// Extracting a bearer token should never fail, it should always return `Ok(BearerAuth(Some(token))))` | ||
| /// or `Ok(BearerAuth(None))`. `None` will be returned in any of the cases that a valid string can not | ||
| /// be extracted. This extractor is not responsible for checking the value of the token. | ||
| fn bearer_from_header(header: Option<&HeaderValue>) -> Result<BearerAuth, HttpError> { |
There was a problem hiding this comment.
nit: this may just be personal preference, but considering this function can only be expected to work when the arg is header::AUTHORIZATION I'd just have it take request headers as the param instead. Taking an Option as a param when None can't succeed seems weird to me.
fn bearer_from_headers(headers: &HeaderMap<HeaderValue>) -> Result<BearerAuth, HttpError> {
But it is a private fn and maybe that makes the tests a little more annoying. 🤷
There was a problem hiding this comment.
Yeah, I think making it take a map makes sense. I really dislike the option argument as well (it doesn't make sense as you note). I think it is just one of those frustrations of not being able to create a synthetic request context in tests.
Currently by default anyone that calls
get_callergets back either an authenticated or unauthenticated caller. In either case they only carry the permissions assigned to them. This means that a downstream application has to do their own work to check if the caller is authenticated if they want to have a 401 gate. This is a breaking change that changes that behavior. Instead we now emit a 401 by default ifget_callerfails to extract an authenticated caller. For the case where someone wants to accept an unauthenticated caller they can explicitly request if via:Anyone that does not need unauthenticated callers does not need to make any changes.