mirror of
https://github.com/wassname/talk.git
synced 2026-08-10 12:41:02 +08:00
Added new cookie config params
This commit is contained in:
@@ -14,7 +14,7 @@ require('env-rewrite').rewrite();
|
||||
const CONFIG = {
|
||||
|
||||
// WEBPACK indicates when webpack is currently building.
|
||||
WEBPACK: process.env.WEBPACK === 'true',
|
||||
WEBPACK: process.env.WEBPACK === 'TRUE',
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// JWT based configuration
|
||||
@@ -24,8 +24,17 @@ const CONFIG = {
|
||||
// application.
|
||||
JWT_SECRET: process.env.TALK_JWT_SECRET || null,
|
||||
|
||||
// JWT_SECRETS is used when key rotation is available.
|
||||
JWT_SECRETS: process.env.TALK_JWT_SECRETS || null,
|
||||
|
||||
// JWT_COOKIE_NAME is the name of the cookie optionally containing the JWT
|
||||
// token.
|
||||
JWT_COOKIE_NAME: process.env.TALK_JWT_COOKIE_NAME || 'authorization',
|
||||
|
||||
// JWT_CLEAR_COOKIE_LOGOUT specifies whether the named cookie should be
|
||||
// cleared when the user is logged out.
|
||||
JWT_CLEAR_COOKIE_LOGOUT: process.env.JWT_CLEAR_COOKIE_LOGOUT ? process.env.JWT_CLEAR_COOKIE_LOGOUT !== 'FALSE' : true,
|
||||
|
||||
// JWT_AUDIENCE is the value for the audience claim for the tokens that will be
|
||||
// verified when decoding. If `JWT_AUDIENCE` is not in the environment, then it
|
||||
// will default to `talk`.
|
||||
|
||||
+10
-4
@@ -21,7 +21,9 @@ const {
|
||||
JWT_AUDIENCE,
|
||||
JWT_ALG,
|
||||
RECAPTCHA_SECRET,
|
||||
RECAPTCHA_ENABLED
|
||||
RECAPTCHA_ENABLED,
|
||||
JWT_COOKIE_NAME,
|
||||
JWT_CLEAR_COOKIE_LOGOUT
|
||||
} = require('../config');
|
||||
|
||||
const {
|
||||
@@ -45,7 +47,7 @@ const GenerateToken = (user) => {
|
||||
const SetTokenForSafari = (req, res, token) => {
|
||||
const browser = bowser._detect(req.headers['user-agent']);
|
||||
if (browser.ios || browser.safari) {
|
||||
res.cookie('authorization', token, {
|
||||
res.cookie(JWT_COOKIE_NAME, token, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
expires: new Date(Date.now() + ms(JWT_EXPIRY))
|
||||
@@ -159,7 +161,11 @@ const HandleLogout = (req, res, next) => {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.clearCookie('authorization');
|
||||
// Only clear the cookie on logout if enabled.
|
||||
if (JWT_CLEAR_COOKIE_LOGOUT) {
|
||||
res.clearCookie(JWT_COOKIE_NAME);
|
||||
}
|
||||
|
||||
res.status(204).end();
|
||||
});
|
||||
};
|
||||
@@ -199,7 +205,7 @@ let cookieExtractor = function(req) {
|
||||
let token = null;
|
||||
|
||||
if (req && req.cookies) {
|
||||
token = req.cookies['authorization'];
|
||||
token = req.cookies[JWT_COOKIE_NAME];
|
||||
}
|
||||
|
||||
return token;
|
||||
|
||||
Reference in New Issue
Block a user