@hemia/auth-sdk 0.0.13 → 0.0.15
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.
|
@@ -182,7 +182,7 @@ let AuthService = class AuthService {
|
|
|
182
182
|
if (!response.data.data?.access_token) {
|
|
183
183
|
throw new InternalServerError('No access token received from SSO', 'invalid_token_response');
|
|
184
184
|
}
|
|
185
|
-
const { access_token, refresh_token, id_token, expires_in, session_id } = response.data.data;
|
|
185
|
+
const { access_token, refresh_token, id_token, expires_in, session_id, session_expires_in } = response.data.data;
|
|
186
186
|
const sessionId = randomBytes(16).toString('hex');
|
|
187
187
|
const sessionData = {
|
|
188
188
|
accessToken: access_token,
|
|
@@ -192,7 +192,8 @@ let AuthService = class AuthService {
|
|
|
192
192
|
createdAt: new Date().toISOString(),
|
|
193
193
|
sessionId: session_id
|
|
194
194
|
};
|
|
195
|
-
|
|
195
|
+
const expiresSession = Date.now() + (session_expires_in ? session_expires_in * 1000 : 0);
|
|
196
|
+
await this.storage.set(`x-session:${sessionId}`, sessionData, expiresSession);
|
|
196
197
|
return {
|
|
197
198
|
sessionId,
|
|
198
199
|
expiresIn: expires_in,
|
|
@@ -276,23 +277,23 @@ let AuthService = class AuthService {
|
|
|
276
277
|
}
|
|
277
278
|
const claimsId = this.jwtManager.decode(session.idToken, true);
|
|
278
279
|
return {
|
|
279
|
-
aud: claimsAccess.aud,
|
|
280
|
-
iss: claimsAccess.iss || '',
|
|
281
|
-
exp: claimsAccess.exp || 0,
|
|
282
|
-
iat: claimsAccess.iat || 0,
|
|
283
|
-
sub: claimsAccess.sub || '',
|
|
280
|
+
aud: claimsAccess.payload.aud,
|
|
281
|
+
iss: claimsAccess.payload.iss || '',
|
|
282
|
+
exp: claimsAccess.payload.exp || 0,
|
|
283
|
+
iat: claimsAccess.payload.iat || 0,
|
|
284
|
+
sub: claimsAccess.payload.sub || '',
|
|
284
285
|
user: {
|
|
285
|
-
id: claimsId
|
|
286
|
-
name: claimsId
|
|
287
|
-
email: claimsId
|
|
288
|
-
given_name: claimsId
|
|
289
|
-
family_name: claimsId
|
|
290
|
-
picture: claimsId?.picture
|
|
286
|
+
id: claimsId.payload.sub || '',
|
|
287
|
+
name: claimsId.payload.name || '',
|
|
288
|
+
email: claimsId.payload.email || '',
|
|
289
|
+
given_name: claimsId.payload.given_name,
|
|
290
|
+
family_name: claimsId.payload.family_name,
|
|
291
|
+
picture: claimsId.payload?.picture
|
|
291
292
|
},
|
|
292
|
-
permissions: claimsAccess.permissions,
|
|
293
|
+
permissions: claimsAccess.payload.permissions,
|
|
293
294
|
context: {
|
|
294
|
-
...claimsAccess['https://hemia.mx/context'],
|
|
295
|
-
...claimsId
|
|
295
|
+
...claimsAccess.payload['https://hemia.mx/context'],
|
|
296
|
+
...claimsId.payload['https://hemia.mx/context']
|
|
296
297
|
}
|
|
297
298
|
};
|
|
298
299
|
}
|
|
@@ -363,7 +364,7 @@ let AuthService = class AuthService {
|
|
|
363
364
|
if (!response.data.data) {
|
|
364
365
|
throw new InternalServerError('No token data received from SSO during refresh', 'invalid_token_response');
|
|
365
366
|
}
|
|
366
|
-
const { access_token, refresh_token, id_token, expires_in, session_id } = response.data.data;
|
|
367
|
+
const { access_token, refresh_token, id_token, expires_in, session_id, session_expires_in } = response.data.data;
|
|
367
368
|
const updatedSession = {
|
|
368
369
|
accessToken: access_token,
|
|
369
370
|
refreshToken: refresh_token || session.refreshToken,
|
|
@@ -372,7 +373,8 @@ let AuthService = class AuthService {
|
|
|
372
373
|
sessionId: session_id || '',
|
|
373
374
|
createdAt: Date.now().toString()
|
|
374
375
|
};
|
|
375
|
-
|
|
376
|
+
const expiresSession = Date.now() + (session_expires_in ? session_expires_in * 1000 : 0);
|
|
377
|
+
await this.storage.set(`x-session:${sessionId}`, updatedSession, expiresSession);
|
|
376
378
|
return updatedSession;
|
|
377
379
|
}
|
|
378
380
|
};
|
|
@@ -448,10 +450,6 @@ let AuthSDKController = class AuthSDKController {
|
|
|
448
450
|
}
|
|
449
451
|
async me(req, res) {
|
|
450
452
|
const sessionId = req.cookies[this.COOKIE_NAME];
|
|
451
|
-
console.log(`🔍 [App Cookie Name]: ${this.COOKIE_NAME}`);
|
|
452
|
-
console.log('🔍 [App Port]:', req.headers.origin || 'unknown');
|
|
453
|
-
console.log('🔍 [SessionId]:', sessionId);
|
|
454
|
-
console.log('🔍 [All Cookies]:', req.cookies);
|
|
455
453
|
if (!sessionId) {
|
|
456
454
|
return res.status(401).json({
|
|
457
455
|
success: false,
|
package/dist/hemia-auth-sdk.js
CHANGED
|
@@ -184,7 +184,7 @@ exports.AuthService = class AuthService {
|
|
|
184
184
|
if (!response.data.data?.access_token) {
|
|
185
185
|
throw new common.InternalServerError('No access token received from SSO', 'invalid_token_response');
|
|
186
186
|
}
|
|
187
|
-
const { access_token, refresh_token, id_token, expires_in, session_id } = response.data.data;
|
|
187
|
+
const { access_token, refresh_token, id_token, expires_in, session_id, session_expires_in } = response.data.data;
|
|
188
188
|
const sessionId = crypto.randomBytes(16).toString('hex');
|
|
189
189
|
const sessionData = {
|
|
190
190
|
accessToken: access_token,
|
|
@@ -194,7 +194,8 @@ exports.AuthService = class AuthService {
|
|
|
194
194
|
createdAt: new Date().toISOString(),
|
|
195
195
|
sessionId: session_id
|
|
196
196
|
};
|
|
197
|
-
|
|
197
|
+
const expiresSession = Date.now() + (session_expires_in ? session_expires_in * 1000 : 0);
|
|
198
|
+
await this.storage.set(`x-session:${sessionId}`, sessionData, expiresSession);
|
|
198
199
|
return {
|
|
199
200
|
sessionId,
|
|
200
201
|
expiresIn: expires_in,
|
|
@@ -278,23 +279,23 @@ exports.AuthService = class AuthService {
|
|
|
278
279
|
}
|
|
279
280
|
const claimsId = this.jwtManager.decode(session.idToken, true);
|
|
280
281
|
return {
|
|
281
|
-
aud: claimsAccess.aud,
|
|
282
|
-
iss: claimsAccess.iss || '',
|
|
283
|
-
exp: claimsAccess.exp || 0,
|
|
284
|
-
iat: claimsAccess.iat || 0,
|
|
285
|
-
sub: claimsAccess.sub || '',
|
|
282
|
+
aud: claimsAccess.payload.aud,
|
|
283
|
+
iss: claimsAccess.payload.iss || '',
|
|
284
|
+
exp: claimsAccess.payload.exp || 0,
|
|
285
|
+
iat: claimsAccess.payload.iat || 0,
|
|
286
|
+
sub: claimsAccess.payload.sub || '',
|
|
286
287
|
user: {
|
|
287
|
-
id: claimsId
|
|
288
|
-
name: claimsId
|
|
289
|
-
email: claimsId
|
|
290
|
-
given_name: claimsId
|
|
291
|
-
family_name: claimsId
|
|
292
|
-
picture: claimsId?.picture
|
|
288
|
+
id: claimsId.payload.sub || '',
|
|
289
|
+
name: claimsId.payload.name || '',
|
|
290
|
+
email: claimsId.payload.email || '',
|
|
291
|
+
given_name: claimsId.payload.given_name,
|
|
292
|
+
family_name: claimsId.payload.family_name,
|
|
293
|
+
picture: claimsId.payload?.picture
|
|
293
294
|
},
|
|
294
|
-
permissions: claimsAccess.permissions,
|
|
295
|
+
permissions: claimsAccess.payload.permissions,
|
|
295
296
|
context: {
|
|
296
|
-
...claimsAccess['https://hemia.mx/context'],
|
|
297
|
-
...claimsId
|
|
297
|
+
...claimsAccess.payload['https://hemia.mx/context'],
|
|
298
|
+
...claimsId.payload['https://hemia.mx/context']
|
|
298
299
|
}
|
|
299
300
|
};
|
|
300
301
|
}
|
|
@@ -365,7 +366,7 @@ exports.AuthService = class AuthService {
|
|
|
365
366
|
if (!response.data.data) {
|
|
366
367
|
throw new common.InternalServerError('No token data received from SSO during refresh', 'invalid_token_response');
|
|
367
368
|
}
|
|
368
|
-
const { access_token, refresh_token, id_token, expires_in, session_id } = response.data.data;
|
|
369
|
+
const { access_token, refresh_token, id_token, expires_in, session_id, session_expires_in } = response.data.data;
|
|
369
370
|
const updatedSession = {
|
|
370
371
|
accessToken: access_token,
|
|
371
372
|
refreshToken: refresh_token || session.refreshToken,
|
|
@@ -374,7 +375,8 @@ exports.AuthService = class AuthService {
|
|
|
374
375
|
sessionId: session_id || '',
|
|
375
376
|
createdAt: Date.now().toString()
|
|
376
377
|
};
|
|
377
|
-
|
|
378
|
+
const expiresSession = Date.now() + (session_expires_in ? session_expires_in * 1000 : 0);
|
|
379
|
+
await this.storage.set(`x-session:${sessionId}`, updatedSession, expiresSession);
|
|
378
380
|
return updatedSession;
|
|
379
381
|
}
|
|
380
382
|
};
|
|
@@ -450,10 +452,6 @@ exports.AuthSDKController = class AuthSDKController {
|
|
|
450
452
|
}
|
|
451
453
|
async me(req, res) {
|
|
452
454
|
const sessionId = req.cookies[this.COOKIE_NAME];
|
|
453
|
-
console.log(`🔍 [App Cookie Name]: ${this.COOKIE_NAME}`);
|
|
454
|
-
console.log('🔍 [App Port]:', req.headers.origin || 'unknown');
|
|
455
|
-
console.log('🔍 [SessionId]:', sessionId);
|
|
456
|
-
console.log('🔍 [All Cookies]:', req.cookies);
|
|
457
455
|
if (!sessionId) {
|
|
458
456
|
return res.status(401).json({
|
|
459
457
|
success: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hemia/auth-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "Hemia SDK for authentication",
|
|
5
5
|
"main": "dist/hemia-auth-sdk.js",
|
|
6
6
|
"module": "dist/hemia-auth-sdk.esm.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@hemia/cache-manager": "^0.0.5",
|
|
19
|
-
"@hemia/common": "^0.0.
|
|
19
|
+
"@hemia/common": "^0.0.15",
|
|
20
20
|
"@hemia/jwt-manager": "^0.0.6",
|
|
21
21
|
"@hemia/network-services": "^0.0.3",
|
|
22
22
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
],
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@hemia/cache-manager": "^0.0.5",
|
|
47
|
-
"@hemia/common": "^0.0.
|
|
47
|
+
"@hemia/common": "^0.0.15",
|
|
48
48
|
"@hemia/jwt-manager": "^0.0.6",
|
|
49
49
|
"@hemia/network-services": "^0.0.3",
|
|
50
50
|
"inversify": "^7.11.0",
|