Skip to content

Commit 58a9b24

Browse files
committed
logout example
1 parent 83ba908 commit 58a9b24

File tree

3 files changed

+31
-72
lines changed

3 files changed

+31
-72
lines changed

001-oidc-local-test/openid_connect.js

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -275,33 +275,29 @@ function validateIdToken(r) {
275275
}
276276
}
277277

278-
//
279-
// Default RP-Initiated or Custom Logout w/ OP.
280-
//
281-
// - An RP requests that the OP log out the end-user by redirecting the
282-
// end-user's User Agent to the OP's Logout endpoint.
283-
// - https://openid.net/specs/openid-connect-rpinitiated-1_0.html#RPLogout
284-
// - https://openid.net/specs/openid-connect-rpinitiated-1_0.html#RedirectionAfterLogout
285-
//
278+
// Default RP-Initiated or Custom Logout w/ OP as per:
279+
// https://openid.net/specs/openid-connect-rpinitiated-1_0.html#RPLogout
280+
// https://openid.net/specs/openid-connect-rpinitiated-1_0.html#RedirectionAfterLogout
281+
// An RP requests that the OP log out the end-user by redirecting the end-user's
282+
// User Agent to the OP's Logout endpoint.
286283
function logout(r) {
287284
r.log("OIDC logout for " + r.variables.cookie_auth_token);
288-
var idToken = r.variables.session_jwt;
289-
var queryParams = '?post_logout_redirect_uri=' +
290-
r.variables.redirect_base +
291-
r.variables.oidc_logout_redirect +
292-
'&id_token_hint=' + idToken;
293-
if (r.variables.oidc_logout_query_params_option == REPLACE_PARAMS) {
285+
var queryParams = '';
286+
if (r.variables.oidc_logout_query_params) {
294287
queryParams = '?' + r.variables.oidc_logout_query_params;
295-
} else if (r.variables.oidc_logout_query_params_option == EXTRA_PARAMS) {
296-
queryParams += '&' + r.variables.oidc_logout_query_params;
297-
}
288+
}
298289
r.variables.request_id = '-';
299290
r.variables.session_jwt = '-';
300291
r.variables.access_token = '-';
301292
r.variables.refresh_token = '-';
302293
r.return(302, r.variables.oidc_logout_endpoint + queryParams);
303294
}
304295

296+
// Redirect URI after logged-out from the OP.
297+
function redirectPostLogout(r) {
298+
r.return(302, r.variables.oidc_logout_landing_page);
299+
}
300+
305301
function getQueryParamsAuthZ(r) {
306302
// Choose a nonce for this flow for the client, and hash it for the IdP
307303
var noncePlain = r.variables.request_id;
@@ -356,17 +352,6 @@ function redirectPostLogin(r) {
356352
}
357353
}
358354

359-
//
360-
// Redirect URI after logged-out from the OP.
361-
//
362-
function redirectPostLogout(r) {
363-
if (r.variables.post_logout_return_uri) {
364-
r.return(302, r.variables.post_logout_return_uri);
365-
} else {
366-
r.return(302, r.variables.redirect_base + r.variables.cookie_auth_redir);
367-
}
368-
}
369-
370355
//
371356
// Return necessary user info claims after receiving and extracting all claims
372357
// that are received from the OpenID Connect Provider(OP).

001-oidc-local-test/openid_connect.server_conf

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,24 @@
9797
}
9898

9999
location = /_logout {
100-
# This location is a RP's callback URI that is the default value of
101-
# $oidc_logout_redirect which is called by OP after successful logout.
100+
# This location is a RP's callback URI which is called by the IdP after
101+
# successful logout from the IdP by calling $oidc_logout_endpoint.
102102

103103
# Clean cookies
104104
add_header Set-Cookie "auth_token=; $oidc_cookie_flags"; # Send empty cookie
105105
add_header Set-Cookie "auth_redir=; $oidc_cookie_flags"; # Erase original cookie
106106
add_header Set-Cookie "auth_nonce=; $oidc_cookie_flags";
107107

108-
# Enable one of the following examples.
109-
110-
# Example 1. Built-in, simple logout page
111-
#default_type text/plain;
112-
#return 200 "Logged out\n";
113-
114-
# Example 2. Redirect to either the landing page or custom logout page
115-
# using the map of $post_logout_return_uri.
116108
js_content oidc.redirectPostLogout;
117109
}
118110

111+
location = /logout_page {
112+
# This location is a default value of $oidc_logout_landing_page as a
113+
# Built-in, simple logout page in case it wasn't configured.
114+
default_type text/plain;
115+
return 200 "Logged out\n";
116+
}
117+
119118
location @oidc_error {
120119
# This location is called when oidcAuth() or oidcCodeExchange() returns an error
121120
status_zone "OIDC error";

001-oidc-local-test/openid_connect_configuration.conf

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,12 @@ map $host $oidc_logout_endpoint {
3838
default "http://host.docker.internal:8080/auth/realms/master/protocol/openid-connect/logout";
3939
}
4040

41-
map $host $oidc_logout_query_params_option {
42-
# 0: default query params for the RP-initiated logout
43-
# 1: extra query params is added after the default query params
44-
# 2: replace default query params with custom query params
45-
default 0;
46-
}
47-
4841
map $host $oidc_logout_query_params {
49-
# Each IdP use different query params of the $oidc_logout_endpoint. For
50-
# example, The Amazon Cognito requires `client_id` and `logout_uri`. The
51-
# Auth0 requires `client_id` and `returnTo`. If this option is empty, then
52-
# `post_logout_redirect_uri` and `id_token_hint` are used as default query
53-
# params, and the AzureAD/Okta/Keycloak/OneLogin/PingIdentity use them.
54-
default "";
55-
# www.example.com "client_id=$oidc_client&logout_uri=$redirect_base/_logout";
42+
# Each IdP may use different query params of the $oidc_logout_endpoint. For
43+
# example, Amazon Cognito requires `client_id` and `logout_uri`, and Auth0
44+
# requires `client_id` and `returnTo` instead of the default query params.
45+
default "post_logout_redirect_uri=$redirect_base/_logout&id_token_hint=$session_jwt";
46+
#www.example.com "client_id=$oidc_client&logout_uri=$redirect_base/_logout";
5647
}
5748

5849
map $host $oidc_userinfo_endpoint {
@@ -93,26 +84,10 @@ map $host $oidc_landing_page {
9384
www.example.com $redirect_base;
9485
}
9586

96-
map $host $oidc_logout_redirect {
97-
# This is a RP's callback URI which is called by OP after successful logout.
98-
default "/_logout"; # Built-in, simple logout page
99-
}
100-
101-
map $host $post_logout_return_uri {
102-
# Where to send browser after the RP requests /logout to the OP, and after
103-
# the RP (/_logout) is called by the OP and cleans cookies. The following
104-
# If this is empty, then the RP redirects to $request_uri.
105-
106-
default "";
107-
108-
# Edit if you want to redirect to the landing page
109-
www.example.com $oidc_landing_page;
110-
111-
# Edit if you want to redirect to a custom logout page
112-
#www.example.com $redirect_base/signout;
113-
114-
# Edit if you want to redirect to an another complete URL
115-
#www.example.com https://www.nginx.com;
87+
map $host $oidc_logout_landing_page {
88+
# Where to redirect browser after successful logout from the IdP.
89+
default "$redirect_base/logout_page"; # Built-in, simple logout page
90+
www.example.com $redirect_base;
11691
}
11792

11893
map $host $oidc_hmac_key {

0 commit comments

Comments
 (0)