Skip to content

Commit fe88c96

Browse files
committed
Add OIDC landing page and login endpoint
1 parent 6ad8ec6 commit fe88c96

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

openid_connect.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
var newSession = false; // Used by oidcAuth() and validateIdToken()
77

8-
export default {auth, codeExchange, validateIdToken, logout};
8+
export default {auth, codeExchange, validateIdToken, logout, redirectPostLogin};
99

1010
function retryOriginalRequest(r) {
1111
delete r.headersOut["WWW-Authenticate"]; // Remove evidence of original failed auth_jwt
@@ -188,7 +188,7 @@ function codeExchange(r) {
188188
r.log("OIDC success, creating session " + r.variables.request_id);
189189
r.variables.new_session = tokenset.id_token; // Create key-value store entry
190190
r.headersOut["Set-Cookie"] = "auth_token=" + r.variables.request_id + "; " + r.variables.oidc_cookie_flags;
191-
r.return(302, r.variables.redirect_base + r.variables.cookie_auth_redir);
191+
redirectPostLogin();
192192
}
193193
);
194194
} catch (e) {
@@ -253,6 +253,15 @@ function validateIdToken(r) {
253253
}
254254
}
255255

256+
// Redirect URI after successful login from the OP.
257+
function redirectPostLogin(r) {
258+
if (r.variables.oidc_landing_page) {
259+
r.return(302, r.variables.oidc_landing_page);
260+
} else {
261+
r.return(302, r.variables.redirect_base + r.variables.cookie_auth_redir);
262+
}
263+
}
264+
256265
function logout(r) {
257266
r.log("OIDC logout for " + r.variables.cookie_auth_token);
258267
r.variables.session_jwt = "-";

openid_connect.server_conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@
6666
error_page 500 502 504 @oidc_error;
6767
}
6868

69+
location = /login {
70+
# This location can be called by SPA for scenarios where `/` location is
71+
# proxied to SPA landing page that doesn't need to be started with user
72+
# authentication, and a user clicks on login button to start OIDC flow.
73+
auth_jwt "" token=$session_jwt;
74+
error_page 401 = @do_oidc_flow;
75+
76+
auth_jwt_key_file $oidc_jwt_keyfile; # Enable when using filename
77+
#auth_jwt_key_request /_jwks_uri; # Enable when using URL
78+
}
79+
6980
location = /logout {
7081
status_zone "OIDC logout";
7182
add_header Set-Cookie "auth_token=; $oidc_cookie_flags"; # Send empty cookie

openid_connect_configuration.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ map $host $oidc_scopes {
4444
default "openid+profile+email+offline_access";
4545
}
4646

47+
map $host $oidc_landing_page {
48+
# Where to send browser after successful login. If empty, redirects User
49+
# Agent to $request_uri.
50+
default "";
51+
#www.example.com $redirect_base;
52+
}
53+
4754
map $host $oidc_logout_redirect {
4855
# Where to send browser after requesting /logout location. This can be
4956
# replaced with a custom logout page, or complete URL.

0 commit comments

Comments
 (0)