Skip to content

Commit c5ca149

Browse files
committed
Address comments
1 parent 7c4f1de commit c5ca149

File tree

18 files changed

+42
-46
lines changed

18 files changed

+42
-46
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/config/src/sections/upstream_oauth2.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,23 @@ fn is_default_true(value: &bool) -> bool {
399399
}
400400

401401
#[allow(clippy::ref_option)]
402-
fn is_signed_response_alg_default(signed_response_alg: &Option<JsonWebSignatureAlg>) -> bool {
402+
fn is_signed_response_alg_default(signed_response_alg: &JsonWebSignatureAlg) -> bool {
403403
*signed_response_alg == signed_response_alg_default()
404404
}
405405

406+
#[allow(clippy::ref_option)]
407+
fn is_optional_signed_response_alg_default(optional_signed_response_alg: &Option<JsonWebSignatureAlg>) -> bool {
408+
*optional_signed_response_alg == optional_signed_response_alg_default()
409+
}
410+
406411
#[allow(clippy::unnecessary_wraps)]
407-
fn signed_response_alg_default() -> Option<JsonWebSignatureAlg> {
408-
Some(JsonWebSignatureAlg::Rs256)
412+
fn signed_response_alg_default() -> JsonWebSignatureAlg {
413+
JsonWebSignatureAlg::Rs256
414+
}
415+
416+
#[allow(clippy::unnecessary_wraps)]
417+
fn optional_signed_response_alg_default() -> Option<JsonWebSignatureAlg> {
418+
Some(signed_response_alg_default())
409419
}
410420

411421
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
@@ -485,13 +495,12 @@ pub struct Provider {
485495
/// Expected signature for the JWT payload returned by the token
486496
/// authentication endpoint.
487497
///
488-
/// If null, the response is expected to be an unsigned JSON payload.
489498
/// Defaults to `RS256`.
490499
#[serde(
491500
default = "signed_response_alg_default",
492501
skip_serializing_if = "is_signed_response_alg_default"
493502
)]
494-
pub id_token_signed_response_alg: Option<JsonWebSignatureAlg>,
503+
pub id_token_signed_response_alg: JsonWebSignatureAlg,
495504

496505
/// The scopes to request from the provider
497506
pub scope: String,
@@ -524,8 +533,8 @@ pub struct Provider {
524533
/// If null, the response is expected to be an unsigned JSON payload.
525534
/// Defaults to `RS256`.
526535
#[serde(
527-
default = "signed_response_alg_default",
528-
skip_serializing_if = "is_signed_response_alg_default"
536+
default = "optional_signed_response_alg_default",
537+
skip_serializing_if = "is_optional_signed_response_alg_default"
529538
)]
530539
pub userinfo_signed_response_alg: Option<JsonWebSignatureAlg>,
531540

crates/data-model/src/upstream_oauth2/provider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub struct UpstreamOAuthProvider {
235235
pub encrypted_client_secret: Option<String>,
236236
pub token_endpoint_signing_alg: Option<JsonWebSignatureAlg>,
237237
pub token_endpoint_auth_method: TokenAuthMethod,
238-
pub id_token_signed_response_alg: Option<JsonWebSignatureAlg>,
238+
pub id_token_signed_response_alg: JsonWebSignatureAlg,
239239
pub response_mode: ResponseMode,
240240
pub created_at: DateTime<Utc>,
241241
pub disabled_at: Option<DateTime<Utc>>,

crates/handlers/src/upstream_oauth2/cache.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ mod tests {
289289
use mas_data_model::{
290290
UpstreamOAuthProviderClaimsImports, UpstreamOAuthProviderTokenAuthMethod,
291291
};
292+
use mas_iana::jose::JsonWebSignatureAlg;
292293
use mas_storage::{clock::MockClock, Clock};
293294
use oauth2_types::scope::{Scope, OPENID};
294295
use ulid::Ulid;
@@ -411,7 +412,7 @@ mod tests {
411412
token_endpoint_signing_alg: None,
412413
token_endpoint_auth_method: UpstreamOAuthProviderTokenAuthMethod::None,
413414
response_mode: mas_data_model::UpstreamOAuthProviderResponseMode::Query,
414-
id_token_signed_response_alg: None,
415+
id_token_signed_response_alg: JsonWebSignatureAlg::Rs256,
415416
created_at: clock.now(),
416417
disabled_at: None,
417418
claims_imports: UpstreamOAuthProviderClaimsImports::default(),

crates/handlers/src/upstream_oauth2/callback.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ pub(crate) async fn handler(
278278

279279
let mut context = AttributeMappingContext::new();
280280
if let Some(id_token) = token_response.id_token.as_ref() {
281-
if let Some(signed_response_alg) = &provider.id_token_signed_response_alg {
282281
jwks = Some(
283282
mas_oidc_client::requests::jose::fetch_jwks(
284283
&client,
@@ -290,7 +289,7 @@ pub(crate) async fn handler(
290289
let id_token_verification_data = JwtVerificationData {
291290
issuer: &provider.issuer,
292291
jwks: &jwks.clone().unwrap(),
293-
signing_algorithm: signed_response_alg,
292+
signing_algorithm: &provider.id_token_signed_response_alg,
294293
client_id: &provider.client_id,
295294
};
296295

@@ -329,11 +328,6 @@ pub(crate) async fn handler(
329328
.map_err(mas_oidc_client::error::IdTokenError::from)?;
330329

331330
context = context.with_id_token_claims(claims);
332-
} else {
333-
let claims = serde_json::from_str(id_token)
334-
.map_err(mas_oidc_client::error::IdTokenError::from)?;
335-
context = context.with_id_token_claims(claims);
336-
}
337331
}
338332

339333
if let Some(extra_callback_parameters) = extra_callback_parameters.clone() {

crates/handlers/src/upstream_oauth2/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ mod tests {
922922
scope: Scope::from_iter([OPENID]),
923923
token_endpoint_auth_method: UpstreamOAuthProviderTokenAuthMethod::None,
924924
token_endpoint_signing_alg: None,
925-
id_token_signed_response_alg: None,
925+
id_token_signed_response_alg: JsonWebSignatureAlg::Rs256,
926926
client_id: "client".to_owned(),
927927
encrypted_client_secret: None,
928928
claims_imports,

crates/handlers/src/views/login.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ mod test {
346346
use mas_data_model::{
347347
UpstreamOAuthProviderClaimsImports, UpstreamOAuthProviderTokenAuthMethod,
348348
};
349+
use mas_iana::jose::JsonWebSignatureAlg;
349350
use mas_router::Route;
350351
use mas_storage::{
351352
upstream_oauth2::{UpstreamOAuthProviderParams, UpstreamOAuthProviderRepository},
@@ -403,7 +404,7 @@ mod test {
403404
scope: [OPENID].into_iter().collect(),
404405
token_endpoint_auth_method: UpstreamOAuthProviderTokenAuthMethod::None,
405406
token_endpoint_signing_alg: None,
406-
id_token_signed_response_alg: None,
407+
id_token_signed_response_alg: JsonWebSignatureAlg::Rs256,
407408
fetch_userinfo: false,
408409
userinfo_signed_response_alg: None,
409410
client_id: "client".to_owned(),
@@ -443,7 +444,7 @@ mod test {
443444
scope: [OPENID].into_iter().collect(),
444445
token_endpoint_auth_method: UpstreamOAuthProviderTokenAuthMethod::None,
445446
token_endpoint_signing_alg: None,
446-
id_token_signed_response_alg: None,
447+
id_token_signed_response_alg: JsonWebSignatureAlg::Rs256,
447448
fetch_userinfo: false,
448449
userinfo_signed_response_alg: None,
449450
client_id: "client".to_owned(),

crates/oidc-client/src/error.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ pub enum IdTokenError {
200200
/// one we got before.
201201
#[error("wrong authentication time")]
202202
WrongAuthTime,
203-
204-
#[error(transparent)]
205-
/// TODO
206-
Deserialize(#[from] serde_json::Error),
207203
}
208204

209205
/// All errors that can occur when adding client credentials to the request.

crates/storage-pg/.sqlx/query-1d758df58ccfead4cb39ee8f88f60b382b7881e9c4ead31ff257ff5ff4414b6e.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/storage-pg/.sqlx/query-27d6f228a9a608b5d03d30cb4074be94dc893df9107e982583aa954b5067dfd1.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)