-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split up #735: auth.rs
refactors
#871
Conversation
…r' into zeke/noa-router-shuffle
auth.rs
changesauth.rs
refactor
auth.rs
refactorauth.rs
refactors
#[derive(Clone, Deserialize)] | ||
pub struct SpacetimeCreds { | ||
token: String, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am told this is not (de)serialized anywhere besides via the corresponding trait [1]
pub struct SpacetimeAuth { | ||
pub creds: SpacetimeCreds, | ||
pub identity: Identity, | ||
} | ||
|
||
pub struct SpacetimeAuthHeader { | ||
pub auth: Option<SpacetimeAuth>, | ||
impl SpacetimeAuth { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review note: this block was just moved from below, unchanged, so it's next to the struct
definition.
let Some(creds) = SpacetimeCreds::from_request_parts(parts)? else { | ||
return Ok(Self { auth: None }); | ||
}; | ||
let claims = creds.decode_token(state.public_key())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub enum AuthorizationRejection { | ||
Jwt(JwtError), | ||
Header(headers::Error), | ||
Required, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this used to be AuthorizationRejectionReason
below, but was moved up and refactored
Jwt(JwtErrorKind), | ||
Header(TypedHeaderRejection), | ||
MalformedTokenQueryString, | ||
CantDecodeAuthorizationToken, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crates/client-api/src/auth.rs
Outdated
Ok(None) => Ok(()), | ||
Err(e) => Err(e), | ||
}; | ||
if let Ok(Query(creds)) = Query::<Self>::try_from_uri(&parts.uri) { | ||
return Ok(Some(creds)); | ||
} | ||
res.map(|()| None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok(None) => Ok(()), | |
Err(e) => Err(e), | |
}; | |
if let Ok(Query(creds)) = Query::<Self>::try_from_uri(&parts.uri) { | |
return Ok(Some(creds)); | |
} | |
res.map(|()| None) | |
r @ Ok(None) => r, | |
Err(e) => Err(e), | |
}; | |
if let Ok(q @ Query(_)) = Query::<Self>::try_from_uri(&parts.uri) { | |
return Ok(q); | |
} | |
res |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, thank you for drafting this!
pub fn decode_token(&self, public_key: &DecodingKey) -> Result<SpacetimeIdentityClaims, JwtError> { | ||
decode_token(public_key, self.token()).map(|x| x.claims) | ||
} | ||
pub fn encode_token(private_key: &EncodingKey, identity: Identity) -> Result<Self, JwtError> { | ||
let token = encode_token(private_key, identity)?; | ||
let headers::Authorization(basic) = headers::Authorization::basic(TOKEN_USERNAME, &token); | ||
Ok(Self(basic)) | ||
Ok(Self { token }) | ||
} | ||
|
||
fn from_request_parts(parts: &request::Parts) -> Result<Option<Self>, headers::Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs for these?
pub async fn alloc(ctx: &(impl NodeDelegate + ControlStateDelegate + ?Sized)) -> axum::response::Result<Self> { | ||
let identity = ctx.create_identity().await.map_err(log_and_500)?; | ||
let creds = SpacetimeCreds::encode_token(ctx.private_key(), identity).map_err(log_and_500)?; | ||
Ok(Self { creds, identity }) | ||
} | ||
|
||
pub fn into_headers(self) -> (TypedHeader<SpacetimeIdentity>, TypedHeader<SpacetimeIdentityToken>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs?
This got left behind - I'm good with these changes and I'll rebase #735 on top of them |
(and add docs) |
Description of Changes
Splitting apart PRs, i.e. shamelessly stealing Noa's
auth.rs
changes from #735.API and ABI breaking changes
No. This is expected to not change any user-facing behavior.
Expected complexity level and risk
2?