Skip to content

Commit 8f263e1

Browse files
Shield OIDC: Add support for params
1 parent 9f439fb commit 8f263e1

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

examples/leptos-axum/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async fn main() {
4545
"client1",
4646
)
4747
.client_secret("xcpQsaGbRILTljPtX4npjmYMBjKrariJ")
48-
.redirect_url(&format!(
48+
.redirect_url(format!(
4949
"http://localhost:{}/api/auth/sign-in/callback/oidc/keycloak",
5050
addr.port()
5151
))

packages/providers/shield-oidc/src/provider.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use chrono::{DateTime, Duration, Utc};
33
use openidconnect::{
44
core::{CoreAuthenticationFlow, CoreGenderClaim, CoreTokenResponse},
55
reqwest::async_http_client,
6+
url::form_urlencoded::parse,
67
AccessToken, AuthorizationCode, CsrfToken, EmptyAdditionalClaims, Nonce, OAuth2TokenResponse,
78
PkceCodeChallenge, PkceCodeVerifier, Scope, TokenResponse, UserInfoClaims,
89
};
@@ -221,6 +222,15 @@ impl<U: User> Provider for OidcProvider<U> {
221222
authorization_request.add_scopes(scopes.into_iter().map(Scope::new));
222223
}
223224

225+
if let Some(authorization_url_params) = subprovider.authorization_url_params {
226+
let params = parse(authorization_url_params.trim_start_matches('?').as_bytes());
227+
228+
for (name, value) in params {
229+
authorization_request =
230+
authorization_request.add_extra_param(name.into_owned(), value.into_owned());
231+
}
232+
}
233+
224234
let (auth_url, csrf_token, nonce) = authorization_request.url();
225235

226236
{
@@ -292,6 +302,15 @@ impl<U: User> Provider for OidcProvider<U> {
292302
return Err(ShieldError::Validation("Missing PKCE verifier.".to_owned()));
293303
}
294304

305+
if let Some(token_url_params) = subprovider.token_url_params {
306+
let params = parse(token_url_params.trim_start_matches('?').as_bytes());
307+
308+
for (name, value) in params {
309+
token_request =
310+
token_request.add_extra_param(name.into_owned(), value.into_owned());
311+
}
312+
}
313+
295314
let token_response = token_request
296315
.request_async(async_http_client)
297316
.await
@@ -414,6 +433,18 @@ impl<U: User> Provider for OidcProvider<U> {
414433
};
415434

416435
if let Some(revocation_request) = revocation_request {
436+
let mut revocation_request = revocation_request;
437+
438+
if let Some(revocation_url_params) = subprovider.revocation_url_params {
439+
let params =
440+
parse(revocation_url_params.trim_start_matches('?').as_bytes());
441+
442+
for (name, value) in params {
443+
revocation_request = revocation_request
444+
.add_extra_param(name.into_owned(), value.into_owned());
445+
}
446+
}
447+
417448
revocation_request
418449
.request_async(async_http_client)
419450
.await

0 commit comments

Comments
 (0)