Skip to content

Commit 4c467c4

Browse files
barrbrainctron
authored andcommitted
feat: accept audience from scope audience:server:client_id
1 parent 48db7e6 commit 4c467c4

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/cmd/create/public.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
cmd::create::CreateCommon,
33
config::{Client, ClientType, Config},
44
http::{HttpOptions, create_client},
5-
oidc::{extra_scopes, refresh_token_request},
5+
oidc::{extra_scopes, other_audiences, refresh_token_request},
66
server::{Bind, Server},
77
utils::OrNone,
88
};
@@ -221,9 +221,16 @@ Open the following URL in your browser and perform the interactive login process
221221
// check ID token
222222

223223
if let Some(id_token) = token.extra_fields().id_token() {
224+
let scopes = self.common.scope.as_deref();
225+
let verifier =
226+
client
227+
.id_token_verifier()
228+
.set_other_audience_verifier_fn(move |other| {
229+
other_audiences(scopes).any(|aud| other == &aud)
230+
});
224231
id_token
225232
.clone()
226-
.into_claims(&client.id_token_verifier(), &nonce)
233+
.into_claims(&verifier, &nonce)
227234
.context("failed to verify ID token")?;
228235
}
229236

src/oidc.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use anyhow::{anyhow, bail};
88
use biscuit::{Empty, jws::Compact};
99
use oauth2::{EndpointMaybeSet, EndpointNotSet, EndpointSet, RefreshToken};
1010
use openidconnect::{
11-
ClientId, ClientSecret, IssuerUrl, Scope,
11+
Audience, ClientId, ClientSecret, IssuerUrl, Scope,
1212
core::{CoreClient, CoreProviderMetadata, CoreTokenResponse},
1313
};
1414
use time::OffsetDateTime;
@@ -103,6 +103,18 @@ pub fn extra_scopes(scope: Option<&str>) -> impl Iterator<Item = Scope> {
103103
.map(|s| Scope::new(s.into()))
104104
}
105105

106+
/// Other audiences specified in scope may be implicitly trusted.
107+
/// The `audience:server:client_id:{CLIENT_ID}` format originates with GoogleAuthUtil.
108+
/// See <https://github.com/ctron/oidc-cli/pull/14> for context and
109+
/// <https://dexidp.io/docs/configuration/custom-scopes-claims-clients/>.
110+
pub fn other_audiences(scope: Option<&str>) -> impl Iterator<Item = Audience> {
111+
scope
112+
.into_iter()
113+
.flat_map(|s| s.split(' '))
114+
.filter_map(|s| s.strip_prefix("audience:server:client_id:"))
115+
.map(|aud| Audience::new(aud.into()))
116+
}
117+
106118
pub fn check_refresh_token_expiration(refresh_token: &str) -> anyhow::Result<()> {
107119
if let Ok(token) =
108120
Compact::<RefreshTokenClaims, Empty>::new_encoded(refresh_token).unverified_payload()

0 commit comments

Comments
 (0)