forked from auth0/express-openid-connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom-routes.js
50 lines (41 loc) · 1.2 KB
/
custom-routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const express = require('express');
const { auth, requiresAuth } = require('../');
const app = express();
app.use(
auth({
idpLogout: true,
authRequired: false,
routes: {
// Pass custom options to the login method by overriding the default login route
login: false,
// Pass a custom path to the postLogoutRedirect to redirect users to a different
// path after login, this should be registered on your authorization server.
postLogoutRedirect: '/custom-logout',
callback: false,
},
})
);
app.get('/', (req, res) => res.send('Welcome!'));
app.get('/profile', requiresAuth(), (req, res) =>
res.send(`hello ${req.oidc.user.sub}`)
);
app.get('/login', (req, res) =>
res.oidc.login({
returnTo: '/profile',
authorizationParams: {
redirect_uri: 'http://localhost:3000/callback',
},
})
);
app.get('/custom-logout', (req, res) => res.send('Bye!'));
app.get('/callback', (req, res) =>
res.oidc.callback({
redirectUri: 'http://localhost:3000/callback',
})
);
app.post('/callback', express.urlencoded({ extended: false }), (req, res) =>
res.oidc.callback({
redirectUri: 'http://localhost:3000/callback',
})
);
module.exports = app;