Skip to content
This repository was archived by the owner on Apr 19, 2025. It is now read-only.

Commit 28aaf14

Browse files
committed
update cookies
1 parent f8b4320 commit 28aaf14

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

config.js

+1-17
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,6 @@ exports.creds = {
5353
// Required to set to true if the `verify` function has 'req' as the first parameter
5454
passReqToCallback: false,
5555

56-
// Recommended to set to true. By default we save state in express session, if this option is set to true, then
57-
// we encrypt state and save it in cookie instead. This option together with { session: false } allows your app
58-
// to be completely express session free.
59-
useCookieInsteadOfSession: true,
60-
61-
// Required if `useCookieInsteadOfSession` is set to true. You can provide multiple set of key/iv pairs for key
62-
// rollover purpose. We always use the first set of key/iv pair to encrypt cookie, but we will try every set of
63-
// key/iv pair to decrypt cookie. Key can be any string of length 32, and iv can be any string of length 12.
64-
// Example: openssl rand -base64 12 && openssl rand -base64 32
65-
cookieEncryptionKeys: [
66-
{
67-
'key': process.env.NODE_ENV == "development" ? "TfGVn2Sn3WjFk3GNzvIvOw8aXh16NqFC" : process.env.COOKIE_KEY, // len 32
68-
'iv': process.env.NODE_ENV == "development" ? "C1fRcgVZs1K7" : process.env.COOKIE_IV // len 12
69-
},
70-
],
71-
7256
// The additional scopes we want besides 'openid'.
7357
// 'profile' scope is required, the rest scopes are optional.
7458
// (1) if you want to receive refresh_token, use 'offline_access' scope
@@ -79,7 +63,7 @@ exports.creds = {
7963
loggingLevel: 'error',
8064

8165
// Optional. The lifetime of nonce in session or cookie, the default value is 3600 (seconds).
82-
nonceLifetime: null,
66+
nonceLifetime: 3600,
8367

8468
// Optional. The max amount of nonce saved in session or cookie, the default value is 10.
8569
nonceMaxAmount: 5,

index.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ function getRandomURL() {
6161
const secret = process.env.COOKIE_KEY || "secret";
6262
app.use(session({
6363
secret: secret,
64-
resave: false,
65-
saveUninitialized: true,
6664
}));
6765

6866
//-----------------------------------------------------------------------------
@@ -264,7 +262,6 @@ app.get('/#',
264262
resourceURL: config.resourceURL, // optional. Provide a value if you want to specify the resource.
265263
customState: 'my_state', // optional. Provide a value if you want to provide custom state value.
266264
failureRedirect: '/error',
267-
useCookieInsteadOfSession: true,
268265
domain_hint: config.branding.domainHint
269266
}
270267
)(req, res, next);
@@ -314,9 +311,10 @@ app.post('/auth/openid/return',
314311

315312
// 'logout' route, logout from passport, and destroy the session with AAD.
316313
app.get('/logout', function(req, res){
317-
res.clearCookie('connect.sid');
318-
res.clearCookie('session');
319-
res.clearCookie('session.sig');
314+
res.clearCookie('connect.sid', {path:'/'});
315+
res.clearCookie('session', {path:'/'});
316+
res.clearCookie('session.sig', {path:'/'});
317+
req.session=null;
320318
res.redirect('/');
321319
});
322320

@@ -343,7 +341,12 @@ app.use(async (req, res, next) => {
343341
// begin business logic
344342

345343
app.get('/', async function (req, res) {
344+
346345
if (req.isAuthenticated()) { return res.redirect('/create') }
346+
res.clearCookie('connect.sid', {path:'/'});
347+
res.clearCookie('session', {path:'/'});
348+
res.clearCookie('session.sig', {path:'/'});
349+
347350
res.render('home.html', {partials, productName: config.branding.title, logoPath: config.branding.logoPath, copyrightOwner: config.branding.copyrightOwner, statusURL: config.branding.statusURL, orgHome: config.branding.orgHome,loginProvider: config.branding.loginProvider});
348351
return
349352
})

view/components/fullNavbar.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
</ul>
1818
<div class="dropstart dropdown-menu-md">
1919
<a href="#" class="d-block text-white text-decoration-none dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
20-
Signed in as: {{name}}
20+
Welcome {{name}}!
2121
</a>
2222
<ul class="dropdown-menu text-small">
2323
<li><a class="dropdown-item disabled" href="#">Email: {{email}}</a></li>
2424
<li><hr class="dropdown-divider"></li>
25-
<li><a class="dropdown-item" href="/logout">Logout</a></li>
25+
<li><a class="dropdown-item text-dark" href="/logout">Logout</a></li>
2626
</ul>
2727
</div>
2828
</div>

0 commit comments

Comments
 (0)