Skip to content

Commit 108564c

Browse files
committed
feat: add login endpoint
1 parent 6ad8ec6 commit 108564c

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

frontend.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ server {
3131

3232
access_log /var/log/nginx/access.log main_jwt;
3333
}
34+
35+
location = /login {
36+
# This location can be called by SPA to start OIDC flow via login button
37+
# when a SPA's landing page need to be started without OIDC flow.
38+
auth_jwt "" token=$session_jwt;
39+
error_page 401 = @do_oidc_flow;
40+
41+
auth_jwt_key_file $oidc_jwt_keyfile; # Enable when using filename
42+
#auth_jwt_key_request /_jwks_uri; # Enable when using URL
43+
44+
# Redirect to the the landing page after successful login to AS.
45+
js_content oidc.redirectPostLogin;
46+
access_log /var/log/nginx/access.log main_jwt;
47+
}
3448
}
3549

3650
# vim: syntax=nginx

openid_connect.js

Lines changed: 10 additions & 1 deletion
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
@@ -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_configuration.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ 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. This option is only
49+
# recommended for scenarios where a landing page shows default information
50+
# without login, and the RP redirects to the landing page after successful
51+
# login from the OP. If this is empty, then the RP redirects to $request_uri.
52+
default "";
53+
#www.example.com $redirect_base;
54+
}
55+
4756
map $host $oidc_logout_redirect {
4857
# Where to send browser after requesting /logout location. This can be
4958
# replaced with a custom logout page, or complete URL.

0 commit comments

Comments
 (0)