@tstdl/base 0.93.162 → 0.93.163
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/api/server/gateway.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** biome-ignore-all lint/nursery/noExcessiveClassesPerFile: <explanation> */
|
|
1
2
|
import 'urlpattern-polyfill';
|
|
2
3
|
import type { HttpServerRequestContext } from '../../http/server/http-server.js';
|
|
3
4
|
import { HttpServerResponse, type HttpServerRequest } from '../../http/server/index.js';
|
package/api/server/gateway.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** biome-ignore-all lint/nursery/noExcessiveClassesPerFile: <explanation> */
|
|
1
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -14,9 +15,7 @@ import 'urlpattern-polyfill';
|
|
|
14
15
|
import { Auditor } from '../../audit/auditor.js';
|
|
15
16
|
import { ActorType } from '../../audit/types.js';
|
|
16
17
|
import { NIL_UUID } from '../../constants.js';
|
|
17
|
-
import { BadRequestError } from '../../errors/
|
|
18
|
-
import { NotFoundError } from '../../errors/not-found.error.js';
|
|
19
|
-
import { NotImplementedError } from '../../errors/not-implemented.error.js';
|
|
18
|
+
import { BadRequestError, InvalidTokenError, NotFoundError, NotImplementedError } from '../../errors/index.js';
|
|
20
19
|
import { HttpServerResponse } from '../../http/server/index.js';
|
|
21
20
|
import { inject, injectArgument, resolveArgumentType, Singleton } from '../../injector/index.js';
|
|
22
21
|
import { Logger } from '../../logger/index.js';
|
|
@@ -213,7 +212,15 @@ let ApiGateway = ApiGateway_1 = class ApiGateway {
|
|
|
213
212
|
return await requestTokenProvider.getToken(requestContext);
|
|
214
213
|
},
|
|
215
214
|
getAuditor: async () => {
|
|
216
|
-
|
|
215
|
+
let token = null;
|
|
216
|
+
try {
|
|
217
|
+
token = await requestContext.tryGetToken();
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
if (!(error instanceof InvalidTokenError)) {
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
217
224
|
return auditor.fork(context.api.resource)
|
|
218
225
|
.withCorrelation()
|
|
219
226
|
.with({
|
|
@@ -55,6 +55,30 @@ describe('AuthenticationApiController Integration', () => {
|
|
|
55
55
|
expect(service.subjectId()).toBe(user.id);
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
|
+
test('login should work even if an expired token is present in the Authorization header', async () => {
|
|
59
|
+
await runInInjectionContext(injector, async () => {
|
|
60
|
+
const user = await subjectService.createUser({ tenantId, email: 'expired-token-login@example.com', firstName: 'E', lastName: 'L' });
|
|
61
|
+
await serverService.setCredentials(user, 'Strong-Password-2026!');
|
|
62
|
+
// Create an expired token
|
|
63
|
+
const now = Math.floor(Date.now() / 1000);
|
|
64
|
+
const expiredTokenResult = await serverService.createToken({
|
|
65
|
+
subject: user,
|
|
66
|
+
sessionId: crypto.randomUUID(),
|
|
67
|
+
impersonator: undefined,
|
|
68
|
+
additionalTokenPayload: {},
|
|
69
|
+
refreshTokenExpiration: now - 3600,
|
|
70
|
+
expiration: now - 3600, // Expired 1 hour ago
|
|
71
|
+
issuedAt: now - 7200,
|
|
72
|
+
timestamp: (now - 7200) * 1000,
|
|
73
|
+
});
|
|
74
|
+
// Inject the expired token into the client service
|
|
75
|
+
service.updateRawTokens(expiredTokenResult.token);
|
|
76
|
+
// Now try to login
|
|
77
|
+
await service.login({ tenantId, subject: user.id }, 'Strong-Password-2026!');
|
|
78
|
+
expect(service.isLoggedIn()).toBe(true);
|
|
79
|
+
expect(service.subjectId()).toBe(user.id);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
58
82
|
test('checkSecret should work via API client', async () => {
|
|
59
83
|
const result = await service.checkSecret('abc');
|
|
60
84
|
expect(result.strength).toBeLessThan(2);
|