|
1 | 1 | /* |
2 | 2 | * JavaScript functions for providing OpenID Connect with NGINX Plus |
3 | | - * |
| 3 | + * |
4 | 4 | * Copyright (C) 2020 Nginx, Inc. |
5 | 5 | */ |
6 | 6 | var newSession = false; // Used by oidcAuth() and validateIdToken() |
7 | 7 |
|
8 | | -export default {auth, codeExchange, validateIdToken, logout}; |
| 8 | +export default {auth, codeExchange, validateIdToken, logout, redirectPostLogout}; |
9 | 9 |
|
10 | 10 | function retryOriginalRequest(r) { |
11 | 11 | delete r.headersOut["WWW-Authenticate"]; // Remove evidence of original failed auth_jwt |
@@ -51,7 +51,7 @@ function auth(r, afterSyncCheck) { |
51 | 51 | r.return(302, r.variables.oidc_authz_endpoint + getAuthZArgs(r)); |
52 | 52 | return; |
53 | 53 | } |
54 | | - |
| 54 | + |
55 | 55 | // Pass the refresh token to the /_refresh location so that it can be |
56 | 56 | // proxied to the IdP in exchange for a new id_token |
57 | 57 | r.subrequest("/_refresh", "token=" + r.variables.refresh_token, |
@@ -266,10 +266,17 @@ function validateIdToken(r) { |
266 | 266 |
|
267 | 267 | function logout(r) { |
268 | 268 | r.log("OIDC logout for " + r.variables.cookie_auth_token); |
269 | | - r.variables.session_jwt = "-"; |
270 | | - r.variables.access_token = "-"; |
271 | | - r.variables.refresh_token = "-"; |
272 | | - r.return(302, r.variables.oidc_logout_redirect); |
| 269 | + var logoutArgs = "?post_logout_redirect_uri=" + r.variables.redirect_base + r.variables.oidc_logout_redirect + "&id_token_hint=" + r.variables.session_jwt; |
| 270 | + |
| 271 | + r.variables.session_jwt = '-'; |
| 272 | + r.variables.access_token = '-'; |
| 273 | + r.variables.refresh_token = '-'; |
| 274 | + r.return(302, r.variables.oidc_logout_endpoint + logoutArgs); |
| 275 | +} |
| 276 | + |
| 277 | +// Redirect URL after logged-out from the IDP. |
| 278 | +function redirectPostLogout(r) { |
| 279 | + r.return(302, r.variables.redir_post_logout); |
273 | 280 | } |
274 | 281 |
|
275 | 282 | function getAuthZArgs(r) { |
@@ -311,5 +318,5 @@ function idpClientAuth(r) { |
311 | 318 | return "code=" + r.variables.arg_code + "&code_verifier=" + r.variables.pkce_code_verifier; |
312 | 319 | } else { |
313 | 320 | return "code=" + r.variables.arg_code + "&client_secret=" + r.variables.oidc_client_secret; |
314 | | - } |
| 321 | + } |
315 | 322 | } |
0 commit comments