5
5
*/
6
6
var newSession = false ; // Used by oidcAuth() and validateIdToken()
7
7
8
+ const EXTRA_PARAMS = 1 ;
9
+ const REPLACE_PARAMS = 2 ;
10
+
8
11
export default { auth, codeExchange, validateIdToken, logout} ;
9
12
10
13
function retryOriginalRequest ( r ) {
@@ -48,7 +51,7 @@ function auth(r, afterSyncCheck) {
48
51
return ;
49
52
}
50
53
// Redirect the client to the IdP login page with the cookies we need for state
51
- r . return ( 302 , r . variables . oidc_authz_endpoint + getAuthZArgs ( r ) ) ;
54
+ r . return ( 302 , r . variables . oidc_authz_endpoint + getQueryParamsAuthZ ( r ) ) ;
52
55
return ;
53
56
}
54
57
@@ -260,18 +263,15 @@ function logout(r) {
260
263
r . return ( 302 , r . variables . oidc_logout_redirect ) ;
261
264
}
262
265
263
- function getAuthZArgs ( r ) {
266
+ function getQueryParamsAuthZ ( r ) {
264
267
// Choose a nonce for this flow for the client, and hash it for the IdP
265
268
var noncePlain = r . variables . request_id ;
266
269
var c = require ( 'crypto' ) ;
267
270
var h = c . createHmac ( 'sha256' , r . variables . oidc_hmac_key ) . update ( noncePlain ) ;
268
271
var nonceHash = h . digest ( 'base64url' ) ;
269
- var authZArgs = "?response_type=code&scope=" + r . variables . oidc_scopes + "&client_id=" + r . variables . oidc_client + "&redirect_uri=" + r . variables . redirect_base + r . variables . redir_location + "&nonce=" + nonceHash ;
270
-
271
- if ( r . variables . oidc_authz_extra_args ) {
272
- authZArgs += "&" + r . variables . oidc_authz_extra_args ;
273
- }
272
+ var queryParams = "?response_type=code&scope=" + r . variables . oidc_scopes + "&client_id=" + r . variables . oidc_client + "&redirect_uri=" + r . variables . redirect_base + r . variables . redir_location + "&nonce=" + nonceHash ;
274
273
274
+ r . variables . nonce_hash = nonceHash ;
275
275
r . headersOut [ 'Set-Cookie' ] = [
276
276
"auth_redir=" + r . variables . request_uri + "; " + r . variables . oidc_cookie_flags ,
277
277
"auth_nonce=" + noncePlain + "; " + r . variables . oidc_cookie_flags
@@ -282,12 +282,18 @@ function getAuthZArgs(r) {
282
282
r . variables . pkce_id = c . createHash ( 'sha256' ) . update ( String ( Math . random ( ) ) ) . digest ( 'base64url' ) ;
283
283
var pkce_code_challenge = c . createHash ( 'sha256' ) . update ( pkce_code_verifier ) . digest ( 'base64url' ) ;
284
284
r . variables . pkce_code_verifier = pkce_code_verifier ;
285
+ r . variables . pkce_code_challenge = pkce_code_challenge ;
285
286
286
- authZArgs += "&code_challenge_method=S256&code_challenge=" + pkce_code_challenge + "&state=" + r . variables . pkce_id ;
287
+ queryParams += "&code_challenge_method=S256&code_challenge=" + pkce_code_challenge + "&state=" + r . variables . pkce_id ;
287
288
} else {
288
- authZArgs += "&state=0" ;
289
+ queryParams += "&state=0" ;
290
+ }
291
+ if ( r . variables . oidc_authz_query_params_option == REPLACE_PARAMS ) {
292
+ queryParams = '?' + r . variables . oidc_authz_query_params ;
293
+ } else if ( r . variables . oidc_authz_query_params_option == EXTRA_PARAMS ) {
294
+ queryParams += '&' + r . variables . oidc_authz_query_params ;
289
295
}
290
- return authZArgs ;
296
+ return queryParams ;
291
297
}
292
298
293
299
function idpClientAuth ( r ) {
0 commit comments