@@ -6,7 +6,8 @@ use rocket::serde::json::serde_json;
6
6
7
7
use openidconnect:: {
8
8
AccessToken , AdditionalClaims , AuthenticationFlow , Client , ClientId , ClientSecret , CsrfToken ,
9
- IdToken , IssuerUrl , Nonce , RedirectUrl , Scope , UserInfoClaims ,
9
+ IdToken , IssuerUrl , Nonce , PkceCodeChallenge , PkceCodeVerifier , RedirectUrl , Scope ,
10
+ UserInfoClaims ,
10
11
} ;
11
12
12
13
use openidconnect:: core:: {
@@ -68,11 +69,13 @@ type OidcAppClient = Client<
68
69
> ;
69
70
70
71
// Basic data used by the OIDC Client
72
+
71
73
pub struct OidcFlow {
72
74
pub client : OidcAppClient ,
73
75
pub auth_url : url:: Url ,
74
76
pub csrf_state : CsrfToken ,
75
77
pub nonce : Nonce ,
78
+ pub pkce_verifier_secret : String ,
76
79
}
77
80
78
81
// OIDC Session cookie stores OIDC tokens and additional information, such as roles, in a cookie.
@@ -171,14 +174,15 @@ impl OidcFlow {
171
174
for scope in scopes {
172
175
authorize_url = authorize_url. add_scope ( Scope :: new ( scope) ) ;
173
176
}
174
- let ( auth_url , csrf_state , nonce ) = authorize_url
175
- // This example is requesting access to the the user's profile including email.
176
- . url ( ) ;
177
+ // Generate a PKCE challenge.
178
+ let ( pkce_challenge , pkce_verifier ) = PkceCodeChallenge :: new_random_sha256 ( ) ;
179
+ let ( auth_url , csrf_state , nonce ) = authorize_url . url ( ) ;
177
180
Ok ( OidcFlow {
178
181
client,
179
182
auth_url,
180
183
csrf_state,
181
184
nonce,
185
+ pkce_verifier_secret : pkce_verifier. into_secret ( ) ,
182
186
} )
183
187
}
184
188
}
0 commit comments