Skip to content

Commit 350b8b9

Browse files
feat(auth): make unsafe_find_jwt_provider generic (#2559)
1 parent 386d420 commit 350b8b9

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/libs/auth/src/openid/impls.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::openid::jwt::types::cert::Jwks;
2+
use crate::openid::jwt::types::provider::JwtIssuers;
23
use crate::openid::types::provider::{OpenIdCertificate, OpenIdDelegationProvider, OpenIdProvider};
34
use junobuild_shared::data::version::next_version;
45
use junobuild_shared::ic::api::time;
@@ -48,6 +49,12 @@ impl OpenIdDelegationProvider {
4849
}
4950
}
5051

52+
impl JwtIssuers for OpenIdDelegationProvider {
53+
fn issuers(&self) -> &[&'static str] {
54+
self.issuers()
55+
}
56+
}
57+
5158
impl Versioned for OpenIdCertificate {
5259
fn version(&self) -> Option<Version> {
5360
self.version

src/libs/auth/src/openid/jwt/provider.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
use crate::openid::jwt::header::decode_jwt_header;
22
use crate::openid::jwt::types::errors::JwtFindProviderError;
3+
use crate::openid::jwt::types::provider::JwtIssuers;
34
use crate::openid::jwt::types::token::UnsafeClaims;
4-
use crate::openid::types::provider::OpenIdDelegationProvider;
5-
use crate::state::types::config::{OpenIdAuthProviderConfig, OpenIdAuthProviders};
65
use jsonwebtoken::dangerous;
6+
use std::collections::BTreeMap;
77

88
/// ⚠️ **Warning:** This function decodes the JWT payload *without verifying its signature*.
99
/// Use only to inspect claims (e.g., `iss`) before performing a verified decode.
10-
pub fn unsafe_find_jwt_provider<'a>(
11-
providers: &'a OpenIdAuthProviders,
10+
pub fn unsafe_find_jwt_provider<'a, Provider, Config>(
11+
providers: &'a BTreeMap<Provider, Config>,
1212
jwt: &str,
13-
) -> Result<(OpenIdDelegationProvider, &'a OpenIdAuthProviderConfig), JwtFindProviderError> {
13+
) -> Result<(Provider, &'a Config), JwtFindProviderError>
14+
where
15+
Provider: Clone + JwtIssuers,
16+
{
1417
// 1) Header sanity check
1518
decode_jwt_header(jwt).map_err(JwtFindProviderError::from)?;
1619

src/libs/auth/src/openid/jwt/types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,9 @@ pub(crate) mod errors {
176176
BadClaim(String),
177177
}
178178
}
179+
180+
pub mod provider {
181+
pub trait JwtIssuers {
182+
fn issuers(&self) -> &[&'static str];
183+
}
184+
}

0 commit comments

Comments
 (0)