@igxjs/node-components 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/components/session.js +21 -8
- package/index.d.ts +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ flexRouter.mount(app, '');
|
|
|
78
78
|
import { JwtManager } from '@igxjs/node-components';
|
|
79
79
|
|
|
80
80
|
// Constructor uses UPPERCASE naming with JWT_ prefix
|
|
81
|
-
const jwt = new JwtManager({
|
|
81
|
+
const jwt = new JwtManager({ JWT_EXPIRATION_TIME: 64800 });
|
|
82
82
|
const SECRET = process.env.JWT_SECRET;
|
|
83
83
|
|
|
84
84
|
// Create token (encrypt method uses camelCase for per-call options)
|
|
@@ -127,7 +127,7 @@ Uses traditional server-side session cookies. When a user authenticates via SSO,
|
|
|
127
127
|
|
|
128
128
|
**Configuration:**
|
|
129
129
|
- `SESSION_MODE`: `SessionMode.SESSION` (default) - Uses session-based authentication
|
|
130
|
-
- `SESSION_AGE`: Session timeout in
|
|
130
|
+
- `SESSION_AGE`: Session timeout in seconds (default: 64800 = 18 hours)
|
|
131
131
|
- `REDIS_URL`: Redis connection string for session storage
|
|
132
132
|
|
|
133
133
|
**Auth Methods:**
|
|
@@ -182,7 +182,7 @@ fetch('/api/protected', {
|
|
|
182
182
|
| `SSO_SUCCESS_URL` | string | - | Redirect URL after successful login (token mode) |
|
|
183
183
|
| `SSO_FAILURE_URL` | string | - | Redirect URL after failed login (token mode) |
|
|
184
184
|
| `SESSION_MODE` | string | `SessionMode.SESSION` | Authentication mode: `SessionMode.SESSION` or `SessionMode.TOKEN` |
|
|
185
|
-
| `SESSION_AGE` | number |
|
|
185
|
+
| `SESSION_AGE` | number | 64800 | Session timeout in seconds (default: 64800 = 18 hours) |
|
|
186
186
|
| `SESSION_COOKIE_PATH` | string | `'/'` | Session cookie path |
|
|
187
187
|
| `SESSION_SECRET` | string | - | Session/JWT secret key |
|
|
188
188
|
| `SESSION_PREFIX` | string | `'ibmid:'` | Redis session/key prefix |
|
package/components/session.js
CHANGED
|
@@ -58,7 +58,7 @@ export class SessionConfig {
|
|
|
58
58
|
/** @type {string} */
|
|
59
59
|
SSO_FAILURE_URL;
|
|
60
60
|
|
|
61
|
-
/** @type {number} Session age in
|
|
61
|
+
/** @type {number} Session age in seconds (default: 64800 = 18 hours) */
|
|
62
62
|
SESSION_AGE;
|
|
63
63
|
/**
|
|
64
64
|
* @type {string} Session cookie path
|
|
@@ -181,8 +181,8 @@ export class SessionManager {
|
|
|
181
181
|
this.#config = {
|
|
182
182
|
// Session Mode
|
|
183
183
|
SESSION_MODE: config.SESSION_MODE || SessionMode.SESSION,
|
|
184
|
-
// Session
|
|
185
|
-
SESSION_AGE: config.SESSION_AGE ||
|
|
184
|
+
// Session - SESSION_AGE is now in seconds (default: 64800 = 18 hours)
|
|
185
|
+
SESSION_AGE: config.SESSION_AGE || 64800,
|
|
186
186
|
SESSION_COOKIE_PATH: config.SESSION_COOKIE_PATH || '/',
|
|
187
187
|
SESSION_SECRET: config.SESSION_SECRET,
|
|
188
188
|
SESSION_PREFIX: config.SESSION_PREFIX || 'ibmid:',
|
|
@@ -253,6 +253,15 @@ export class SessionManager {
|
|
|
253
253
|
return this.#config.SESSION_KEY;
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
+
/**
|
|
257
|
+
* Get session age in milliseconds (for express-session cookie maxAge)
|
|
258
|
+
* @returns {number} Returns the session age in milliseconds
|
|
259
|
+
* @private
|
|
260
|
+
*/
|
|
261
|
+
#getSessionAgeInMilliseconds() {
|
|
262
|
+
return Math.round(this.#config.SESSION_AGE * 1000);
|
|
263
|
+
}
|
|
264
|
+
|
|
256
265
|
/**
|
|
257
266
|
* Get Redis key for token storage
|
|
258
267
|
* @param {string} email User email
|
|
@@ -300,7 +309,8 @@ export class SessionManager {
|
|
|
300
309
|
async #generateAndStoreToken(user) {
|
|
301
310
|
// Generate unique token ID for this device/session
|
|
302
311
|
const tid = crypto.randomUUID();
|
|
303
|
-
|
|
312
|
+
// SESSION_AGE is already in seconds
|
|
313
|
+
const ttlSeconds = this.#config.SESSION_AGE;
|
|
304
314
|
// Create JWT token with only email and tid (minimal payload)
|
|
305
315
|
const token = await this.#jwtManager.encrypt(
|
|
306
316
|
{ email: user.email, tid },
|
|
@@ -489,7 +499,7 @@ export class SessionManager {
|
|
|
489
499
|
return res.json({
|
|
490
500
|
token: newToken,
|
|
491
501
|
user,
|
|
492
|
-
expiresIn:
|
|
502
|
+
expiresIn: this.#config.SESSION_AGE, // Already in seconds
|
|
493
503
|
tokenType: 'Bearer'
|
|
494
504
|
});
|
|
495
505
|
} catch (error) {
|
|
@@ -667,7 +677,10 @@ export class SessionManager {
|
|
|
667
677
|
*/
|
|
668
678
|
async setup(app, updateUser) {
|
|
669
679
|
this.#redisManager = new RedisManager();
|
|
670
|
-
this.#jwtManager = new JwtManager(
|
|
680
|
+
this.#jwtManager = new JwtManager({
|
|
681
|
+
...this.#config,
|
|
682
|
+
JWT_EXPIRATION_TIME: this.#config.SESSION_AGE, // SESSION_AGE is already in seconds
|
|
683
|
+
});
|
|
671
684
|
// Identity Provider Request
|
|
672
685
|
this.#idpRequest = axios.create({
|
|
673
686
|
baseURL: this.#config.SSO_ENDPOINT_URL,
|
|
@@ -686,7 +699,7 @@ export class SessionManager {
|
|
|
686
699
|
// Redis Session
|
|
687
700
|
this.#logger.log('### Using Redis as the Session Store ###');
|
|
688
701
|
return session({
|
|
689
|
-
cookie: { maxAge: this.#
|
|
702
|
+
cookie: { maxAge: this.#getSessionAgeInMilliseconds(), path: this.#config.SESSION_COOKIE_PATH, sameSite: false },
|
|
690
703
|
store: new RedisStore({ client: this.#redisManager.getClient(), prefix: this.#config.SESSION_PREFIX, disableTouch: true }),
|
|
691
704
|
resave: false, saveUninitialized: false,
|
|
692
705
|
secret: this.#config.SESSION_SECRET,
|
|
@@ -702,7 +715,7 @@ export class SessionManager {
|
|
|
702
715
|
this.#logger.log('### Using Memory as the Session Store ###');
|
|
703
716
|
const MemoryStore = memStore(session);
|
|
704
717
|
return session({
|
|
705
|
-
cookie: { maxAge: this.#
|
|
718
|
+
cookie: { maxAge: this.#getSessionAgeInMilliseconds(), path: this.#config.SESSION_COOKIE_PATH, sameSite: false },
|
|
706
719
|
store: new MemoryStore({}),
|
|
707
720
|
resave: false, saveUninitialized: false,
|
|
708
721
|
secret: this.#config.SESSION_SECRET,
|
package/index.d.ts
CHANGED
|
@@ -122,9 +122,9 @@ export interface SessionConfig {
|
|
|
122
122
|
SESSION_MODE?: string;
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
|
-
* Session expiration time in
|
|
126
|
-
* @example
|
|
127
|
-
* @default
|
|
125
|
+
* Session expiration time in seconds
|
|
126
|
+
* @example 3600 (1 hour) or 86400 (24 hours) or 64800 (18 hours)
|
|
127
|
+
* @default 64800 (18 hours)
|
|
128
128
|
*/
|
|
129
129
|
SESSION_AGE?: number;
|
|
130
130
|
|