@pristine-ts/gcp-identity-platform 2.0.16
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/LICENSE +201 -0
- package/dist/lib/cjs/authenticators/authenticators.js +18 -0
- package/dist/lib/cjs/authenticators/authenticators.js.map +1 -0
- package/dist/lib/cjs/authenticators/identity-platform.authenticator.js +186 -0
- package/dist/lib/cjs/authenticators/identity-platform.authenticator.js.map +1 -0
- package/dist/lib/cjs/gcp-identity-platform.configuration-keys.js +7 -0
- package/dist/lib/cjs/gcp-identity-platform.configuration-keys.js.map +1 -0
- package/dist/lib/cjs/gcp-identity-platform.module.js +46 -0
- package/dist/lib/cjs/gcp-identity-platform.module.js.map +1 -0
- package/dist/lib/cjs/gcp-identity-platform.module.keyname.js +5 -0
- package/dist/lib/cjs/gcp-identity-platform.module.keyname.js.map +1 -0
- package/dist/lib/cjs/guards/guards.js +18 -0
- package/dist/lib/cjs/guards/guards.js.map +1 -0
- package/dist/lib/cjs/guards/identity-platform-claim.guard.js +77 -0
- package/dist/lib/cjs/guards/identity-platform-claim.guard.js.map +1 -0
- package/dist/lib/cjs/interfaces/claim.interface.js +3 -0
- package/dist/lib/cjs/interfaces/claim.interface.js.map +1 -0
- package/dist/lib/cjs/interfaces/interfaces.js +19 -0
- package/dist/lib/cjs/interfaces/interfaces.js.map +1 -0
- package/dist/lib/cjs/interfaces/token-header.interface.js +3 -0
- package/dist/lib/cjs/interfaces/token-header.interface.js.map +1 -0
- package/dist/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/lib/esm/authenticators/authenticators.js +2 -0
- package/dist/lib/esm/authenticators/authenticators.js.map +1 -0
- package/dist/lib/esm/authenticators/identity-platform.authenticator.js +150 -0
- package/dist/lib/esm/authenticators/identity-platform.authenticator.js.map +1 -0
- package/dist/lib/esm/gcp-identity-platform.configuration-keys.js +4 -0
- package/dist/lib/esm/gcp-identity-platform.configuration-keys.js.map +1 -0
- package/dist/lib/esm/gcp-identity-platform.module.js +29 -0
- package/dist/lib/esm/gcp-identity-platform.module.js.map +1 -0
- package/dist/lib/esm/gcp-identity-platform.module.keyname.js +2 -0
- package/dist/lib/esm/gcp-identity-platform.module.keyname.js.map +1 -0
- package/dist/lib/esm/guards/guards.js +2 -0
- package/dist/lib/esm/guards/guards.js.map +1 -0
- package/dist/lib/esm/guards/identity-platform-claim.guard.js +74 -0
- package/dist/lib/esm/guards/identity-platform-claim.guard.js.map +1 -0
- package/dist/lib/esm/interfaces/claim.interface.js +2 -0
- package/dist/lib/esm/interfaces/claim.interface.js.map +1 -0
- package/dist/lib/esm/interfaces/interfaces.js +3 -0
- package/dist/lib/esm/interfaces/interfaces.js.map +1 -0
- package/dist/lib/esm/interfaces/token-header.interface.js +2 -0
- package/dist/lib/esm/interfaces/token-header.interface.js.map +1 -0
- package/dist/lib/esm/tsconfig.tsbuildinfo +1 -0
- package/dist/types/authenticators/authenticators.d.ts +1 -0
- package/dist/types/authenticators/identity-platform.authenticator.d.ts +39 -0
- package/dist/types/gcp-identity-platform.configuration-keys.d.ts +10 -0
- package/dist/types/gcp-identity-platform.module.d.ts +7 -0
- package/dist/types/gcp-identity-platform.module.keyname.d.ts +1 -0
- package/dist/types/guards/guards.d.ts +1 -0
- package/dist/types/guards/identity-platform-claim.guard.d.ts +19 -0
- package/dist/types/interfaces/claim.interface.d.ts +30 -0
- package/dist/types/interfaces/interfaces.d.ts +2 -0
- package/dist/types/interfaces/token-header.interface.d.ts +9 -0
- package/package.json +72 -0
- package/readme.md +5 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var IdentityPlatformAuthenticator_1;
|
|
23
|
+
import { inject, injectable, singleton } from "tsyringe";
|
|
24
|
+
import * as jwt from "jsonwebtoken";
|
|
25
|
+
import { HttpMethod, Request, traced } from "@pristine-ts/common";
|
|
26
|
+
import { ResponseTypeEnum } from "@pristine-ts/http";
|
|
27
|
+
import { GcpIdentityPlatformModuleKeyname } from "../gcp-identity-platform.module.keyname";
|
|
28
|
+
/**
|
|
29
|
+
* The IdentityPlatformAuthenticator verifies Firebase ID tokens (issued by Identity
|
|
30
|
+
* Platform / Firebase Auth). To use, apply via `@authenticator(IdentityPlatformAuthenticator)`
|
|
31
|
+
* on a controller class or method.
|
|
32
|
+
*
|
|
33
|
+
* Verification flow (mirrors `AwsCognitoAuthenticator`):
|
|
34
|
+
* 1. Fetch the X.509 cert set from the Google securetoken endpoint and cache it.
|
|
35
|
+
* 2. Extract the Bearer token from the Authorization header.
|
|
36
|
+
* 3. Pick the cert that matches the token's `kid`.
|
|
37
|
+
* 4. Verify the RS256 signature.
|
|
38
|
+
* 5. Validate standard claims: `iss === https://securetoken.google.com/{projectId}`,
|
|
39
|
+
* `aud === projectId`, `exp` in the future, `auth_time` in the past.
|
|
40
|
+
*
|
|
41
|
+
* Singleton so the cert cache is reused across requests.
|
|
42
|
+
*/
|
|
43
|
+
let IdentityPlatformAuthenticator = IdentityPlatformAuthenticator_1 = class IdentityPlatformAuthenticator {
|
|
44
|
+
constructor(projectId, httpClient, logHandler) {
|
|
45
|
+
this.projectId = projectId;
|
|
46
|
+
this.httpClient = httpClient;
|
|
47
|
+
this.logHandler = logHandler;
|
|
48
|
+
}
|
|
49
|
+
setContext(context) {
|
|
50
|
+
this.context = context;
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
}
|
|
53
|
+
authenticate(request) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
this.cachedCerts = (_a = this.cachedCerts) !== null && _a !== void 0 ? _a : yield this.getCerts();
|
|
57
|
+
const token = this.validateRequestAndReturnToken(request);
|
|
58
|
+
const cert = this.getCertForToken(token, this.cachedCerts);
|
|
59
|
+
const claim = this.getAndVerifyClaims(token, cert);
|
|
60
|
+
this.logHandler.debug("IdentityPlatformAuthenticator: Claim verified.", { extra: { claim } });
|
|
61
|
+
return {
|
|
62
|
+
id: (_b = claim.user_id) !== null && _b !== void 0 ? _b : claim.sub,
|
|
63
|
+
claims: claim,
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
getCerts() {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const response = yield this.httpClient.request({
|
|
70
|
+
httpMethod: HttpMethod.Get,
|
|
71
|
+
url: IdentityPlatformAuthenticator_1.CERTS_URL,
|
|
72
|
+
}, {
|
|
73
|
+
responseType: ResponseTypeEnum.Json,
|
|
74
|
+
});
|
|
75
|
+
return response.body;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
validateRequestAndReturnToken(request) {
|
|
79
|
+
var _a;
|
|
80
|
+
if (request.headers === undefined || (request.hasHeader("Authorization") === false && request.hasHeader("authorization") === false)) {
|
|
81
|
+
throw new Error("The Authorization header wasn't found in the Request.");
|
|
82
|
+
}
|
|
83
|
+
const authorizationHeader = (_a = request.headers.Authorization) !== null && _a !== void 0 ? _a : request.headers.authorization;
|
|
84
|
+
if (authorizationHeader === undefined) {
|
|
85
|
+
throw new Error("The Authorization header wasn't found in the Request.");
|
|
86
|
+
}
|
|
87
|
+
if (authorizationHeader.startsWith("Bearer ") === false) {
|
|
88
|
+
throw new Error("The value in Authorization header doesn't start with 'Bearer '");
|
|
89
|
+
}
|
|
90
|
+
return authorizationHeader.substr(7, authorizationHeader.length);
|
|
91
|
+
}
|
|
92
|
+
getCertForToken(token, certs) {
|
|
93
|
+
const header = this.getTokenHeader(token);
|
|
94
|
+
const cert = certs[header.kid];
|
|
95
|
+
if (cert === undefined) {
|
|
96
|
+
throw new Error("Claim made for unknown kid");
|
|
97
|
+
}
|
|
98
|
+
return cert;
|
|
99
|
+
}
|
|
100
|
+
getTokenHeader(token) {
|
|
101
|
+
const tokenSections = (token || "").split(".");
|
|
102
|
+
if (tokenSections.length < 2) {
|
|
103
|
+
throw new Error("Token is invalid");
|
|
104
|
+
}
|
|
105
|
+
const headerJSON = Buffer.from(tokenSections[0], "base64").toString("utf8");
|
|
106
|
+
return JSON.parse(headerJSON);
|
|
107
|
+
}
|
|
108
|
+
getAndVerifyClaims(token, cert) {
|
|
109
|
+
let claim;
|
|
110
|
+
try {
|
|
111
|
+
claim = jwt.verify(token, cert, { algorithms: ["RS256"] });
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
throw new Error("Invalid jwt: " + err.message);
|
|
115
|
+
}
|
|
116
|
+
const currentSeconds = Math.floor(Date.now() / 1000);
|
|
117
|
+
if (currentSeconds > claim.exp || currentSeconds < claim.auth_time) {
|
|
118
|
+
throw new Error("Claim is expired or invalid");
|
|
119
|
+
}
|
|
120
|
+
const expectedIssuer = `https://securetoken.google.com/${this.projectId}`;
|
|
121
|
+
if (claim.iss !== expectedIssuer) {
|
|
122
|
+
throw new Error("Claim issuer is invalid");
|
|
123
|
+
}
|
|
124
|
+
if (claim.aud !== this.projectId) {
|
|
125
|
+
throw new Error("Claim audience is invalid");
|
|
126
|
+
}
|
|
127
|
+
return claim;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Google's X.509 cert endpoint for Firebase ID tokens. Each entry maps `kid` →
|
|
132
|
+
* PEM-encoded public cert.
|
|
133
|
+
*/
|
|
134
|
+
IdentityPlatformAuthenticator.CERTS_URL = "https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com";
|
|
135
|
+
__decorate([
|
|
136
|
+
traced(),
|
|
137
|
+
__metadata("design:type", Function),
|
|
138
|
+
__metadata("design:paramtypes", [Request]),
|
|
139
|
+
__metadata("design:returntype", Promise)
|
|
140
|
+
], IdentityPlatformAuthenticator.prototype, "authenticate", null);
|
|
141
|
+
IdentityPlatformAuthenticator = IdentityPlatformAuthenticator_1 = __decorate([
|
|
142
|
+
singleton(),
|
|
143
|
+
injectable(),
|
|
144
|
+
__param(0, inject(`%${GcpIdentityPlatformModuleKeyname}.projectId%`)),
|
|
145
|
+
__param(1, inject("HttpClientInterface")),
|
|
146
|
+
__param(2, inject("LogHandlerInterface")),
|
|
147
|
+
__metadata("design:paramtypes", [String, Object, Object])
|
|
148
|
+
], IdentityPlatformAuthenticator);
|
|
149
|
+
export { IdentityPlatformAuthenticator };
|
|
150
|
+
//# sourceMappingURL=identity-platform.authenticator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-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c,GAAG,kCAAkC,IAAI,CAAC,SAAS,EAAE,CAAC;QAC1E,IAAI,KAAK,CAAC,GAAG,KAAK,cAAc,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;QACD,IAAI,KAAK,CAAC,GAAG,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;;AAlGD;;;GAGG;AACqB,uCAAS,GAAG,0FAA0F,AAA7F,CAA8F;AAkBzH;IADL,MAAM,EAAE;;qCACmB,OAAO;;iEAYlC;AAnCU,6BAA6B;IAFzC,SAAS,EAAE;IACX,UAAU,EAAE;IAYR,WAAA,MAAM,CAAC,IAAI,gCAAgC,aAAa,CAAC,CAAA;IACzD,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;IAC7B,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;;GAbrB,6BAA6B,CAoGzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gcp-identity-platform.configuration-keys.js","sourceRoot":"","sources":["../../../src/gcp-identity-platform.configuration-keys.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oCAAoC,GAAG;IAClD,SAAS,EAAE,0CAA0C;CAC7C,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { HttpModule } from "@pristine-ts/http";
|
|
2
|
+
import { EnvironmentVariableResolver } from "@pristine-ts/configuration";
|
|
3
|
+
import { GcpIdentityPlatformModuleKeyname } from "./gcp-identity-platform.module.keyname";
|
|
4
|
+
export * from "./authenticators/authenticators";
|
|
5
|
+
export * from "./guards/guards";
|
|
6
|
+
export * from "./interfaces/interfaces";
|
|
7
|
+
export * from "./gcp-identity-platform.module.keyname";
|
|
8
|
+
export * from "./gcp-identity-platform.configuration-keys";
|
|
9
|
+
export const GcpIdentityPlatformModule = {
|
|
10
|
+
keyname: GcpIdentityPlatformModuleKeyname,
|
|
11
|
+
configurationDefinitions: [
|
|
12
|
+
/**
|
|
13
|
+
* The Firebase / Identity Platform project id. Verified against the JWT `aud`
|
|
14
|
+
* claim. The issuer is derived as `https://securetoken.google.com/{projectId}`.
|
|
15
|
+
*/
|
|
16
|
+
{
|
|
17
|
+
parameterName: GcpIdentityPlatformModuleKeyname + ".projectId",
|
|
18
|
+
isRequired: true,
|
|
19
|
+
defaultResolvers: [
|
|
20
|
+
new EnvironmentVariableResolver("PRISTINE_GCP_IDENTITY_PLATFORM_PROJECT_ID"),
|
|
21
|
+
new EnvironmentVariableResolver("GOOGLE_CLOUD_PROJECT"),
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
importModules: [
|
|
26
|
+
HttpModule,
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=gcp-identity-platform.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gcp-identity-platform.module.js","sourceRoot":"","sources":["../../../src/gcp-identity-platform.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAC,2BAA2B,EAAC,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAC,gCAAgC,EAAC,MAAM,wCAAwC,CAAC;AAExF,cAAc,iCAAiC,CAAC;AAChD,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AAExC,cAAc,wCAAwC,CAAC;AACvD,cAAc,4CAA4C,CAAC;AAE3D,MAAM,CAAC,MAAM,yBAAyB,GAAoB;IACxD,OAAO,EAAE,gCAAgC;IACzC,wBAAwB,EAAE;QACxB;;;WAGG;QACH;YACE,aAAa,EAAE,gCAAgC,GAAG,YAAY;YAC9D,UAAU,EAAE,IAAI;YAChB,gBAAgB,EAAE;gBAChB,IAAI,2BAA2B,CAAC,2CAA2C,CAAC;gBAC5E,IAAI,2BAA2B,CAAC,sBAAsB,CAAC;aACxD;SACF;KACF;IACD,aAAa,EAAE;QACb,UAAU;KACX;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gcp-identity-platform.module.keyname.js","sourceRoot":"","sources":["../../../src/gcp-identity-platform.module.keyname.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gCAAgC,GAAW,gCAAgC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../../src/guards/guards.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
11
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
12
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
14
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
15
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
16
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
import { injectable } from "tsyringe";
|
|
20
|
+
import { Request, traced } from "@pristine-ts/common";
|
|
21
|
+
/**
|
|
22
|
+
* A guard that checks the authenticated identity has every named custom claim set
|
|
23
|
+
* to a truthy value. Use with the `@guard` decorator:
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* @guard(IdentityPlatformClaimGuard, "admin-routes", { claims: ["admin", "billing"] })
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* Mirror of `AwsCognitoGroupGuard` — that one checks `cognito:groups`; this one
|
|
30
|
+
* checks arbitrary top-level claim keys set via `admin.auth().setCustomUserClaims(...)`.
|
|
31
|
+
*/
|
|
32
|
+
let IdentityPlatformClaimGuard = class IdentityPlatformClaimGuard {
|
|
33
|
+
constructor() {
|
|
34
|
+
this.keyname = "gcp.identity-platform.claim";
|
|
35
|
+
}
|
|
36
|
+
setContext(context) {
|
|
37
|
+
this.guardContext = context;
|
|
38
|
+
return Promise.resolve();
|
|
39
|
+
}
|
|
40
|
+
isAuthorized(request, identity) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
if (this.guardContext === undefined) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const neededClaims = [];
|
|
46
|
+
if (this.guardContext.options && Array.isArray(this.guardContext.options.claims)) {
|
|
47
|
+
neededClaims.push(...this.guardContext.options.claims);
|
|
48
|
+
}
|
|
49
|
+
if (neededClaims.length === 0) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if ((identity === null || identity === void 0 ? void 0 : identity.claims) === undefined) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
for (const claim of neededClaims) {
|
|
56
|
+
if (!identity.claims[claim]) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
__decorate([
|
|
65
|
+
traced(),
|
|
66
|
+
__metadata("design:type", Function),
|
|
67
|
+
__metadata("design:paramtypes", [Request, Object]),
|
|
68
|
+
__metadata("design:returntype", Promise)
|
|
69
|
+
], IdentityPlatformClaimGuard.prototype, "isAuthorized", null);
|
|
70
|
+
IdentityPlatformClaimGuard = __decorate([
|
|
71
|
+
injectable()
|
|
72
|
+
], IdentityPlatformClaimGuard);
|
|
73
|
+
export { IdentityPlatformClaimGuard };
|
|
74
|
+
//# sourceMappingURL=identity-platform-claim.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-platform-claim.guard.js","sourceRoot":"","sources":["../../../../src/guards/identity-platform-claim.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AACpC,OAAO,EAAoB,OAAO,EAAE,MAAM,EAAC,MAAM,qBAAqB,CAAC;AAGvE;;;;;;;;;;GAUG;AAEI,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAAhC;QACE,YAAO,GAAG,6BAA6B,CAAC;IA+BjD,CAAC;IA5BC,UAAU,CAAC,OAAY;QACrB,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC;QAC5B,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAGK,YAAY,CAAC,OAAgB,EAAE,QAA4B;;YAC/D,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;gBACpC,OAAO,KAAK,CAAC;YACf,CAAC;YAED,MAAM,YAAY,GAAa,EAAE,CAAC;YAClC,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBACjF,YAAY,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACzD,CAAC;YACD,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC9B,OAAO,IAAI,CAAC;YACd,CAAC;YACD,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,MAAK,SAAS,EAAE,CAAC;gBACnC,OAAO,KAAK,CAAC;YACf,CAAC;YACD,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE,CAAC;gBACjC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;oBAC5B,OAAO,KAAK,CAAC;gBACf,CAAC;YACH,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;CACF,CAAA;AAtBO;IADL,MAAM,EAAE;;qCACmB,OAAO;;8DAqBlC;AA/BU,0BAA0B;IADtC,UAAU,EAAE;GACA,0BAA0B,CAgCtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claim.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/claim.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-header.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/token-header.interface.ts"],"names":[],"mappings":""}
|