@tekcify/auth-backend 2.2.0 → 2.2.1
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/dist/jwks-verifier.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare class JwksVerifier {
|
|
|
11
11
|
private readonly client;
|
|
12
12
|
private readonly issuer;
|
|
13
13
|
private readonly audience;
|
|
14
|
-
constructor(options
|
|
14
|
+
constructor(options?: JwksVerifierOptions);
|
|
15
15
|
verify(token: string): Promise<VerifiedToken>;
|
|
16
16
|
getPublicKey(kid: string): Promise<string>;
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwks-verifier.d.ts","sourceRoot":"","sources":["../src/jwks-verifier.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"jwks-verifier.d.ts","sourceRoot":"","sources":["../src/jwks-verifier.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,SAAS,CAAC;AAS3D,MAAM,WAAW,mBAAmB;IAClC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAWD,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwB;IAC/C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,OAAO,GAAE,mBAAwB;IAevC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IA6C7C,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAIjD;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAE7E"}
|
package/dist/jwks-verifier.js
CHANGED
|
@@ -9,15 +9,18 @@ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
|
9
9
|
const jwks_rsa_1 = __importDefault(require("jwks-rsa"));
|
|
10
10
|
const DEFAULT_AUTH_SERVER_URL = 'https://auth-api.tekcify.com';
|
|
11
11
|
const JWKS_PATH = '/api/.well-known/jwks.json';
|
|
12
|
+
function getAuthServerUrl(optionUrl) {
|
|
13
|
+
return optionUrl ?? process.env.AUTH_SERVER_URL ?? DEFAULT_AUTH_SERVER_URL;
|
|
14
|
+
}
|
|
12
15
|
function resolveJwksUri(options) {
|
|
13
16
|
if (options.jwksUri) {
|
|
14
17
|
return options.jwksUri;
|
|
15
18
|
}
|
|
16
|
-
const baseUrl = (options.authServerUrl
|
|
19
|
+
const baseUrl = getAuthServerUrl(options.authServerUrl).replace(/\/$/, '');
|
|
17
20
|
return `${baseUrl}${JWKS_PATH}`;
|
|
18
21
|
}
|
|
19
22
|
class JwksVerifier {
|
|
20
|
-
constructor(options) {
|
|
23
|
+
constructor(options = {}) {
|
|
21
24
|
const jwksUri = resolveJwksUri(options);
|
|
22
25
|
this.client = (0, jwks_rsa_1.default)({
|
|
23
26
|
jwksUri,
|
|
@@ -39,7 +42,14 @@ class JwksVerifier {
|
|
|
39
42
|
if (!kid) {
|
|
40
43
|
return { payload: {}, valid: false };
|
|
41
44
|
}
|
|
42
|
-
|
|
45
|
+
let key;
|
|
46
|
+
try {
|
|
47
|
+
key = await this.client.getSigningKey(kid);
|
|
48
|
+
}
|
|
49
|
+
catch (keyError) {
|
|
50
|
+
console.error(`[JwksVerifier] Failed to get signing key for kid=${kid}:`, keyError instanceof Error ? keyError.message : keyError);
|
|
51
|
+
return { payload: {}, valid: false };
|
|
52
|
+
}
|
|
43
53
|
const publicKey = key.getPublicKey();
|
|
44
54
|
const decoded = jsonwebtoken_1.default.verify(token, publicKey, {
|
|
45
55
|
algorithms: ['RS256'],
|
|
@@ -6,9 +6,9 @@ export interface JwksAuthGuardOptions extends JwksVerifierOptions {
|
|
|
6
6
|
} | null>;
|
|
7
7
|
}
|
|
8
8
|
export declare class JwksAuthGuard implements CanActivate {
|
|
9
|
-
private readonly options;
|
|
10
9
|
private readonly verifier;
|
|
11
|
-
|
|
10
|
+
private readonly options;
|
|
11
|
+
constructor(options?: JwksAuthGuardOptions);
|
|
12
12
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=jwks-guard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwks-guard.d.ts","sourceRoot":"","sources":["../../src/nestjs/jwks-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,gBAAgB,EAEjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAG1E,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC/D,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;CACrE;AAED,qBACa,aAAc,YAAW,WAAW;
|
|
1
|
+
{"version":3,"file":"jwks-guard.d.ts","sourceRoot":"","sources":["../../src/nestjs/jwks-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,gBAAgB,EAEjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAG1E,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC/D,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;CACrE;AAED,qBACa,aAAc,YAAW,WAAW;IAC/C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;gBAEnC,OAAO,GAAE,oBAAyB;IAKxC,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAkD/D"}
|
|
@@ -13,7 +13,7 @@ exports.JwksAuthGuard = void 0;
|
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const jwks_verifier_1 = require("../jwks-verifier");
|
|
15
15
|
let JwksAuthGuard = class JwksAuthGuard {
|
|
16
|
-
constructor(options) {
|
|
16
|
+
constructor(options = {}) {
|
|
17
17
|
this.options = options;
|
|
18
18
|
this.verifier = new jwks_verifier_1.JwksVerifier(options);
|
|
19
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tekcify/auth-backend",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Backend authentication helpers for Tekcify Auth. Provides middleware, guards, and utilities for validating JWT tokens and protecting API routes in NestJS and Express applications.",
|
|
5
5
|
"author": "Tekcify",
|
|
6
6
|
"main": "./dist/index.js",
|