@backstage/plugin-auth-node 0.2.5-next.1 → 0.2.5-next.2
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/CHANGELOG.md +10 -0
- package/dist/index.cjs.js +28 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +59 -7
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @backstage/plugin-auth-node
|
|
2
2
|
|
|
3
|
+
## 0.2.5-next.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2cbd533426: `IdentityClient` is now deprecated. Please migrate to `IdentityApi` and `DefaultIdentityClient` instead. The authenticate function on `DefaultIdentityClient` is also deprecated. Please use `getIdentity` instead.
|
|
8
|
+
- 667d917488: Updated dependency `msw` to `^0.47.0`.
|
|
9
|
+
- 87ec2ba4d6: Updated dependency `msw` to `^0.46.0`.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
- @backstage/backend-common@0.15.1-next.2
|
|
12
|
+
|
|
3
13
|
## 0.2.5-next.1
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/dist/index.cjs.js
CHANGED
|
@@ -14,16 +14,27 @@ function getBearerTokenFromAuthorizationHeader(authorizationHeader) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const CLOCK_MARGIN_S = 10;
|
|
17
|
-
class
|
|
17
|
+
class DefaultIdentityClient {
|
|
18
18
|
constructor(options) {
|
|
19
19
|
this.keyStoreUpdated = 0;
|
|
20
|
-
var _a;
|
|
21
20
|
this.discovery = options.discovery;
|
|
22
21
|
this.issuer = options.issuer;
|
|
23
|
-
this.algorithms =
|
|
22
|
+
this.algorithms = options.hasOwnProperty("algorithms") ? options.algorithms : ["ES256"];
|
|
24
23
|
}
|
|
25
24
|
static create(options) {
|
|
26
|
-
return new
|
|
25
|
+
return new DefaultIdentityClient(options);
|
|
26
|
+
}
|
|
27
|
+
async getIdentity({ request }) {
|
|
28
|
+
if (!request.headers.authorization) {
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
return await this.authenticate(
|
|
33
|
+
getBearerTokenFromAuthorizationHeader(request.headers.authorization)
|
|
34
|
+
);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
throw new errors.NotAllowedError(e.message);
|
|
37
|
+
}
|
|
27
38
|
}
|
|
28
39
|
async authenticate(token) {
|
|
29
40
|
if (!token) {
|
|
@@ -76,6 +87,19 @@ class IdentityClient {
|
|
|
76
87
|
}
|
|
77
88
|
}
|
|
78
89
|
|
|
90
|
+
class IdentityClient {
|
|
91
|
+
static create(options) {
|
|
92
|
+
return new IdentityClient(DefaultIdentityClient.create(options));
|
|
93
|
+
}
|
|
94
|
+
constructor(defaultIdentityClient) {
|
|
95
|
+
this.defaultIdentityClient = defaultIdentityClient;
|
|
96
|
+
}
|
|
97
|
+
async authenticate(token) {
|
|
98
|
+
return await this.defaultIdentityClient.authenticate(token);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
exports.DefaultIdentityClient = DefaultIdentityClient;
|
|
79
103
|
exports.IdentityClient = IdentityClient;
|
|
80
104
|
exports.getBearerTokenFromAuthorizationHeader = getBearerTokenFromAuthorizationHeader;
|
|
81
105
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/getBearerTokenFromAuthorizationHeader.ts","../src/IdentityClient.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Parses the given authorization header and returns the bearer token, or\n * undefined if no bearer token is given.\n *\n * @remarks\n *\n * This function is explicitly built to tolerate bad inputs safely, so you may\n * call it directly with e.g. the output of `req.header('authorization')`\n * without first checking that it exists.\n *\n * @public\n */\nexport function getBearerTokenFromAuthorizationHeader(\n authorizationHeader: unknown,\n): string | undefined {\n if (typeof authorizationHeader !== 'string') {\n return undefined;\n }\n const matches = authorizationHeader.match(/^Bearer[ ]+(\\S+)$/i);\n return matches?.[1];\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { PluginEndpointDiscovery } from '@backstage/backend-common';\nimport { AuthenticationError } from '@backstage/errors';\nimport {\n createRemoteJWKSet,\n decodeJwt,\n decodeProtectedHeader,\n FlattenedJWSInput,\n JWSHeaderParameters,\n jwtVerify,\n} from 'jose';\nimport { GetKeyFunction } from 'jose/dist/types/types';\n\nimport { BackstageIdentityResponse } from './types';\n\nconst CLOCK_MARGIN_S = 10;\n\n/**\n * An identity client options object which allows extra configurations\n *\n * @experimental This is not a stable API yet\n * @public\n */\nexport type IdentityClientOptions = {\n discovery: PluginEndpointDiscovery;\n issuer: string;\n\n /** JWS \"alg\" (Algorithm) Header Parameter values. Defaults to an array containing just ES256.\n * More info on supported algorithms: https://github.com/panva/jose */\n algorithms?: string[];\n};\n\n/**\n * An identity client to interact with auth-backend and authenticate Backstage\n * tokens\n *\n * @experimental This is not a stable API yet\n * @public\n */\nexport class IdentityClient {\n private readonly discovery: PluginEndpointDiscovery;\n private readonly issuer: string;\n private readonly algorithms: string[];\n private keyStore?: GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput>;\n private keyStoreUpdated: number = 0;\n\n /**\n * Create a new {@link IdentityClient} instance.\n */\n static create(options: IdentityClientOptions): IdentityClient {\n return new IdentityClient(options);\n }\n\n private constructor(options: IdentityClientOptions) {\n this.discovery = options.discovery;\n this.issuer = options.issuer;\n this.algorithms = options.algorithms ?? ['ES256'];\n }\n\n /**\n * Verifies the given backstage identity token\n * Returns a BackstageIdentity (user) matching the token.\n * The method throws an error if verification fails.\n */\n async authenticate(\n token: string | undefined,\n ): Promise<BackstageIdentityResponse> {\n // Extract token from header\n if (!token) {\n throw new AuthenticationError('No token specified');\n }\n\n // Verify token claims and signature\n // Note: Claims must match those set by TokenFactory when issuing tokens\n // Note: verify throws if verification fails\n // Check if the keystore needs to be updated\n await this.refreshKeyStore(token);\n if (!this.keyStore) {\n throw new AuthenticationError('No keystore exists');\n }\n const decoded = await jwtVerify(token, this.keyStore, {\n algorithms: this.algorithms,\n audience: 'backstage',\n issuer: this.issuer,\n });\n // Verified, return the matching user as BackstageIdentity\n // TODO: Settle internal user format/properties\n if (!decoded.payload.sub) {\n throw new AuthenticationError('No user sub found in token');\n }\n\n const user: BackstageIdentityResponse = {\n token,\n identity: {\n type: 'user',\n userEntityRef: decoded.payload.sub,\n ownershipEntityRefs: decoded.payload.ent\n ? (decoded.payload.ent as string[])\n : [],\n },\n };\n return user;\n }\n\n /**\n * If the last keystore refresh is stale, update the keystore URL to the latest\n */\n private async refreshKeyStore(rawJwtToken: string): Promise<void> {\n const payload = await decodeJwt(rawJwtToken);\n const header = await decodeProtectedHeader(rawJwtToken);\n\n // Refresh public keys if needed\n let keyStoreHasKey;\n try {\n if (this.keyStore) {\n // Check if the key is present in the keystore\n const [_, rawPayload, rawSignature] = rawJwtToken.split('.');\n keyStoreHasKey = await this.keyStore(header, {\n payload: rawPayload,\n signature: rawSignature,\n });\n }\n } catch (error) {\n keyStoreHasKey = false;\n }\n // Refresh public key URL if needed\n // Add a small margin in case clocks are out of sync\n const issuedAfterLastRefresh =\n payload?.iat && payload.iat > this.keyStoreUpdated - CLOCK_MARGIN_S;\n if (!this.keyStore || (!keyStoreHasKey && issuedAfterLastRefresh)) {\n const url = await this.discovery.getBaseUrl('auth');\n const endpoint = new URL(`${url}/.well-known/jwks.json`);\n this.keyStore = createRemoteJWKSet(endpoint);\n this.keyStoreUpdated = Date.now() / 1000;\n }\n }\n}\n"],"names":["AuthenticationError","jwtVerify","decodeJwt","decodeProtectedHeader","createRemoteJWKSet"],"mappings":";;;;;;;AA4BO,SAAS,sCACd,mBACoB,EAAA;AACpB,EAAI,IAAA,OAAO,wBAAwB,QAAU,EAAA;AAC3C,IAAO,OAAA,KAAA,CAAA,CAAA;AAAA,GACT;AACA,EAAM,MAAA,OAAA,GAAU,mBAAoB,CAAA,KAAA,CAAM,oBAAoB,CAAA,CAAA;AAC9D,EAAA,OAAO,OAAU,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,OAAA,CAAA,CAAA,CAAA,CAAA;AACnB;;ACPA,MAAM,cAAiB,GAAA,EAAA,CAAA;AAwBhB,MAAM,cAAe,CAAA;AAAA,EAclB,YAAY,OAAgC,EAAA;AATpD,IAAA,IAAA,CAAQ,eAA0B,GAAA,CAAA,CAAA;AA1DpC,IAAA,IAAA,EAAA,CAAA;AAoEI,IAAA,IAAA,CAAK,YAAY,OAAQ,CAAA,SAAA,CAAA;AACzB,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AACtB,IAAA,IAAA,CAAK,UAAa,GAAA,CAAA,EAAA,GAAA,OAAA,CAAQ,UAAR,KAAA,IAAA,GAAA,EAAA,GAAsB,CAAC,OAAO,CAAA,CAAA;AAAA,GAClD;AAAA,EARA,OAAO,OAAO,OAAgD,EAAA;AAC5D,IAAO,OAAA,IAAI,eAAe,OAAO,CAAA,CAAA;AAAA,GACnC;AAAA,E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AAA,UAAA,EAAY,YAAY,CAAI,GAAA,WAAA,CAAY,MAAM,GAAG,CAAA,CAAA;AAC3D,QAAiB,cAAA,GAAA,MAAM,IAAK,CAAA,QAAA,CAAS,MAAQ,EAAA;AAAA,UAC3C,OAAS,EAAA,UAAA;AAAA,UACT,SAAW,EAAA,YAAA;AAAA,SACZ,CAAA,CAAA;AAAA,OACH;AAAA,aACO,KAAP,EAAA;AACA,MAAiB,cAAA,GAAA,KAAA,CAAA;AAAA,KACnB;AAGA,IAAA,MAAM,0BACJ,OAAS,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,OAAA,CAAA,GAAA,KAAO,OAAQ,CAAA,GAAA,GAAM,KAAK,eAAkB,GAAA,cAAA,CAAA;AACvD,IAAA,IAAI,CAAC,IAAA,CAAK,QAAa,IAAA,CAAC,kBAAkB,sBAAyB,EAAA;AACjE,MAAA,MAAM,GAAM,GAAA,MAAM,IAAK,CAAA,SAAA,CAAU,WAAW,MAAM,CAAA,CAAA;AAClD,MAAA,MAAM,QAAW,GAAA,IAAI,GAAI,CAAA,CAAA,EAAG,GAA2B,CAAA,sBAAA,CAAA,CAAA,CAAA;AACvD,MAAK,IAAA,CAAA,QAAA,GAAWC,wBAAmB,QAAQ,CAAA,CAAA;AAC3C,MAAK,IAAA,CAAA,eAAA,GAAkB,IAAK,CAAA,GAAA,EAAQ,GAAA,GAAA,CAAA;AAAA,KACtC;AAAA,GACF;AACF;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/getBearerTokenFromAuthorizationHeader.ts","../src/DefaultIdentityClient.ts","../src/IdentityClient.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Parses the given authorization header and returns the bearer token, or\n * undefined if no bearer token is given.\n *\n * @remarks\n *\n * This function is explicitly built to tolerate bad inputs safely, so you may\n * call it directly with e.g. the output of `req.header('authorization')`\n * without first checking that it exists.\n *\n * @public\n */\nexport function getBearerTokenFromAuthorizationHeader(\n authorizationHeader: unknown,\n): string | undefined {\n if (typeof authorizationHeader !== 'string') {\n return undefined;\n }\n const matches = authorizationHeader.match(/^Bearer[ ]+(\\S+)$/i);\n return matches?.[1];\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { PluginEndpointDiscovery } from '@backstage/backend-common';\nimport { AuthenticationError, NotAllowedError } from '@backstage/errors';\nimport {\n createRemoteJWKSet,\n decodeJwt,\n decodeProtectedHeader,\n FlattenedJWSInput,\n JWSHeaderParameters,\n jwtVerify,\n} from 'jose';\nimport { GetKeyFunction } from 'jose/dist/types/types';\n\nimport {\n BackstageIdentityResponse,\n IdentityApiGetIdentityRequest,\n} from './types';\nimport { getBearerTokenFromAuthorizationHeader, IdentityApi } from '.';\n\nconst CLOCK_MARGIN_S = 10;\n\n/**\n * An identity client options object which allows extra configurations\n *\n * @experimental This is not a stable API yet\n * @public\n */\nexport type IdentityClientOptions = {\n discovery: PluginEndpointDiscovery;\n issuer?: string;\n\n /** JWS \"alg\" (Algorithm) Header Parameter values. Defaults to an array containing just ES256.\n * More info on supported algorithms: https://github.com/panva/jose */\n algorithms?: string[];\n};\n\n/**\n * An identity client to interact with auth-backend and authenticate Backstage\n * tokens\n *\n * @experimental This is not a stable API yet\n * @public\n */\nexport class DefaultIdentityClient implements IdentityApi {\n private readonly discovery: PluginEndpointDiscovery;\n private readonly issuer?: string;\n private readonly algorithms?: string[];\n private keyStore?: GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput>;\n private keyStoreUpdated: number = 0;\n\n /**\n * Create a new {@link DefaultIdentityClient} instance.\n */\n static create(options: IdentityClientOptions): DefaultIdentityClient {\n return new DefaultIdentityClient(options);\n }\n\n private constructor(options: IdentityClientOptions) {\n this.discovery = options.discovery;\n this.issuer = options.issuer;\n this.algorithms = options.hasOwnProperty('algorithms')\n ? options.algorithms\n : ['ES256'];\n }\n\n async getIdentity({ request }: IdentityApiGetIdentityRequest) {\n if (!request.headers.authorization) {\n return undefined;\n }\n try {\n return await this.authenticate(\n getBearerTokenFromAuthorizationHeader(request.headers.authorization),\n );\n } catch (e) {\n throw new NotAllowedError(e.message);\n }\n }\n\n /**\n * Verifies the given backstage identity token\n * Returns a BackstageIdentity (user) matching the token.\n * The method throws an error if verification fails.\n *\n * @deprecated You should start to use getIdentity instead of authenticate to retrieve the user\n * identity.\n */\n async authenticate(\n token: string | undefined,\n ): Promise<BackstageIdentityResponse> {\n // Extract token from header\n if (!token) {\n throw new AuthenticationError('No token specified');\n }\n\n // Verify token claims and signature\n // Note: Claims must match those set by TokenFactory when issuing tokens\n // Note: verify throws if verification fails\n // Check if the keystore needs to be updated\n await this.refreshKeyStore(token);\n if (!this.keyStore) {\n throw new AuthenticationError('No keystore exists');\n }\n const decoded = await jwtVerify(token, this.keyStore, {\n algorithms: this.algorithms,\n audience: 'backstage',\n issuer: this.issuer,\n });\n // Verified, return the matching user as BackstageIdentity\n // TODO: Settle internal user format/properties\n if (!decoded.payload.sub) {\n throw new AuthenticationError('No user sub found in token');\n }\n\n const user: BackstageIdentityResponse = {\n token,\n identity: {\n type: 'user',\n userEntityRef: decoded.payload.sub,\n ownershipEntityRefs: decoded.payload.ent\n ? (decoded.payload.ent as string[])\n : [],\n },\n };\n return user;\n }\n\n /**\n * If the last keystore refresh is stale, update the keystore URL to the latest\n */\n private async refreshKeyStore(rawJwtToken: string): Promise<void> {\n const payload = await decodeJwt(rawJwtToken);\n const header = await decodeProtectedHeader(rawJwtToken);\n\n // Refresh public keys if needed\n let keyStoreHasKey;\n try {\n if (this.keyStore) {\n // Check if the key is present in the keystore\n const [_, rawPayload, rawSignature] = rawJwtToken.split('.');\n keyStoreHasKey = await this.keyStore(header, {\n payload: rawPayload,\n signature: rawSignature,\n });\n }\n } catch (error) {\n keyStoreHasKey = false;\n }\n // Refresh public key URL if needed\n // Add a small margin in case clocks are out of sync\n const issuedAfterLastRefresh =\n payload?.iat && payload.iat > this.keyStoreUpdated - CLOCK_MARGIN_S;\n if (!this.keyStore || (!keyStoreHasKey && issuedAfterLastRefresh)) {\n const url = await this.discovery.getBaseUrl('auth');\n const endpoint = new URL(`${url}/.well-known/jwks.json`);\n this.keyStore = createRemoteJWKSet(endpoint);\n this.keyStoreUpdated = Date.now() / 1000;\n }\n }\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n DefaultIdentityClient,\n IdentityClientOptions,\n} from './DefaultIdentityClient';\nimport { BackstageIdentityResponse } from './types';\n\n/**\n * An identity client to interact with auth-backend and authenticate Backstage\n * tokens\n *\n * @public\n * @experimental This is not a stable API yet\n * @deprecated Please migrate to the DefaultIdentityClient.\n */\nexport class IdentityClient {\n private readonly defaultIdentityClient: DefaultIdentityClient;\n static create(options: IdentityClientOptions): IdentityClient {\n return new IdentityClient(DefaultIdentityClient.create(options));\n }\n\n private constructor(defaultIdentityClient: DefaultIdentityClient) {\n this.defaultIdentityClient = defaultIdentityClient;\n }\n\n /**\n * Verifies the given backstage identity token\n * Returns a BackstageIdentity (user) matching the token.\n * The method throws an error if verification fails.\n *\n * @deprecated You should start to use IdentityApi#getIdentity instead of authenticate\n * to retrieve the user identity.\n */\n async authenticate(\n token: string | undefined,\n ): Promise<BackstageIdentityResponse> {\n return await this.defaultIdentityClient.authenticate(token);\n }\n}\n"],"names":["NotAllowedError","AuthenticationError","jwtVerify","decodeJwt","decodeProtectedHeader","createRemoteJWKSet"],"mappings":";;;;;;;AA4BO,SAAS,sCACd,mBACoB,EAAA;AACpB,EAAI,IAAA,OAAO,wBAAwB,QAAU,EAAA;AAC3C,IAAO,OAAA,KAAA,CAAA,CAAA;AAAA,GACT;AACA,EAAM,MAAA,OAAA,GAAU,mBAAoB,CAAA,KAAA,CAAM,oBAAoB,CAAA,CAAA;AAC9D,EAAA,OAAO,OAAU,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,OAAA,CAAA,CAAA,CAAA,CAAA;AACnB;;ACHA,MAAM,cAAiB,GAAA,EAAA,CAAA;AAwBhB,MAAM,qBAA6C,CAAA;AAAA,EAchD,YAAY,OAAgC,EAAA;AATpD,IAAA,IAAA,CAAQ,eAA0B,GAAA,CAAA,CAAA;AAUhC,IAAA,IAAA,CAAK,YAAY,OAAQ,CAAA,SAAA,CAAA;AACzB,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AACtB,IAAK,IAAA,CAAA,UAAA,GAAa,QAAQ,cAAe,CAAA,YAAY,IACjD,OAAQ,CAAA,UAAA,GACR,CAAC,OAAO,CAAA,CAAA;AAAA,GACd;AAAA,EAVA,OAAO,OAAO,OAAuD,EAAA;AACnE,IAAO,OAAA,IAAI,sBAAsB,OAAO,CAAA,CAAA;AAAA,GAC1C;AAAA,EAUA,MAAM,WAAA,CAAY,EAAE,OAAA,EAA0C,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A,CAAA;AAAA,KACtC;AAAA,GACF;AACF;;AC9IO,MAAM,cAAe,CAAA;AAAA,EAE1B,OAAO,OAAO,OAAgD,EAAA;AAC5D,IAAA,OAAO,IAAI,cAAA,CAAe,qBAAsB,CAAA,MAAA,CAAO,OAAO,CAAC,CAAA,CAAA;AAAA,GACjE;AAAA,EAEQ,YAAY,qBAA8C,EAAA;AAChE,IAAA,IAAA,CAAK,qBAAwB,GAAA,qBAAA,CAAA;AAAA,GAC/B;AAAA,EAUA,MAAM,aACJ,KACoC,EAAA;AACpC,IAAA,OAAO,MAAM,IAAA,CAAK,qBAAsB,CAAA,YAAA,CAAa,KAAK,CAAA,CAAA;AAAA,GAC5D;AACF;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
|
2
|
+
import { Request } from 'express';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Parses the given authorization header and returns the bearer token, or
|
|
@@ -28,6 +29,14 @@ interface BackstageSignInResult {
|
|
|
28
29
|
*/
|
|
29
30
|
token: string;
|
|
30
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Options to request the identity from a Backstage backend request
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
declare type IdentityApiGetIdentityRequest = {
|
|
38
|
+
request: Request<unknown>;
|
|
39
|
+
};
|
|
31
40
|
/**
|
|
32
41
|
* Response object containing the {@link BackstageUserIdentity} and the token
|
|
33
42
|
* from the authentication provider.
|
|
@@ -70,7 +79,7 @@ declare type BackstageUserIdentity = {
|
|
|
70
79
|
*/
|
|
71
80
|
declare type IdentityClientOptions = {
|
|
72
81
|
discovery: PluginEndpointDiscovery;
|
|
73
|
-
issuer
|
|
82
|
+
issuer?: string;
|
|
74
83
|
/** JWS "alg" (Algorithm) Header Parameter values. Defaults to an array containing just ES256.
|
|
75
84
|
* More info on supported algorithms: https://github.com/panva/jose */
|
|
76
85
|
algorithms?: string[];
|
|
@@ -82,21 +91,25 @@ declare type IdentityClientOptions = {
|
|
|
82
91
|
* @experimental This is not a stable API yet
|
|
83
92
|
* @public
|
|
84
93
|
*/
|
|
85
|
-
declare class
|
|
94
|
+
declare class DefaultIdentityClient implements IdentityApi {
|
|
86
95
|
private readonly discovery;
|
|
87
|
-
private readonly issuer
|
|
88
|
-
private readonly algorithms
|
|
96
|
+
private readonly issuer?;
|
|
97
|
+
private readonly algorithms?;
|
|
89
98
|
private keyStore?;
|
|
90
99
|
private keyStoreUpdated;
|
|
91
100
|
/**
|
|
92
|
-
* Create a new {@link
|
|
101
|
+
* Create a new {@link DefaultIdentityClient} instance.
|
|
93
102
|
*/
|
|
94
|
-
static create(options: IdentityClientOptions):
|
|
103
|
+
static create(options: IdentityClientOptions): DefaultIdentityClient;
|
|
95
104
|
private constructor();
|
|
105
|
+
getIdentity({ request }: IdentityApiGetIdentityRequest): Promise<BackstageIdentityResponse | undefined>;
|
|
96
106
|
/**
|
|
97
107
|
* Verifies the given backstage identity token
|
|
98
108
|
* Returns a BackstageIdentity (user) matching the token.
|
|
99
109
|
* The method throws an error if verification fails.
|
|
110
|
+
*
|
|
111
|
+
* @deprecated You should start to use getIdentity instead of authenticate to retrieve the user
|
|
112
|
+
* identity.
|
|
100
113
|
*/
|
|
101
114
|
authenticate(token: string | undefined): Promise<BackstageIdentityResponse>;
|
|
102
115
|
/**
|
|
@@ -105,4 +118,43 @@ declare class IdentityClient {
|
|
|
105
118
|
private refreshKeyStore;
|
|
106
119
|
}
|
|
107
120
|
|
|
108
|
-
|
|
121
|
+
/**
|
|
122
|
+
* An identity client to interact with auth-backend and authenticate Backstage
|
|
123
|
+
* tokens
|
|
124
|
+
*
|
|
125
|
+
* @public
|
|
126
|
+
* @experimental This is not a stable API yet
|
|
127
|
+
* @deprecated Please migrate to the DefaultIdentityClient.
|
|
128
|
+
*/
|
|
129
|
+
declare class IdentityClient {
|
|
130
|
+
private readonly defaultIdentityClient;
|
|
131
|
+
static create(options: IdentityClientOptions): IdentityClient;
|
|
132
|
+
private constructor();
|
|
133
|
+
/**
|
|
134
|
+
* Verifies the given backstage identity token
|
|
135
|
+
* Returns a BackstageIdentity (user) matching the token.
|
|
136
|
+
* The method throws an error if verification fails.
|
|
137
|
+
*
|
|
138
|
+
* @deprecated You should start to use IdentityApi#getIdentity instead of authenticate
|
|
139
|
+
* to retrieve the user identity.
|
|
140
|
+
*/
|
|
141
|
+
authenticate(token: string | undefined): Promise<BackstageIdentityResponse>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* An identity client api to authenticate Backstage
|
|
146
|
+
* tokens
|
|
147
|
+
*
|
|
148
|
+
* @experimental This is not a stable API yet
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
interface IdentityApi {
|
|
152
|
+
/**
|
|
153
|
+
* Verifies the given backstage identity token
|
|
154
|
+
* Returns a BackstageIdentity (user) matching the token.
|
|
155
|
+
* The method throws an error if verification fails.
|
|
156
|
+
*/
|
|
157
|
+
getIdentity(options: IdentityApiGetIdentityRequest): Promise<BackstageIdentityResponse | undefined>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export { BackstageIdentityResponse, BackstageSignInResult, BackstageUserIdentity, DefaultIdentityClient, IdentityApi, IdentityApiGetIdentityRequest, IdentityClient, IdentityClientOptions, getBearerTokenFromAuthorizationHeader };
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-auth-node",
|
|
3
|
-
"version": "0.2.5-next.
|
|
3
|
+
"version": "0.2.5-next.2",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
|
-
"private": false,
|
|
8
7
|
"publishConfig": {
|
|
9
8
|
"access": "public",
|
|
10
9
|
"main": "dist/index.cjs.js",
|
|
@@ -23,22 +22,24 @@
|
|
|
23
22
|
"start": "backstage-cli package start"
|
|
24
23
|
},
|
|
25
24
|
"dependencies": {
|
|
26
|
-
"@backstage/backend-common": "^0.15.1-next.
|
|
25
|
+
"@backstage/backend-common": "^0.15.1-next.2",
|
|
27
26
|
"@backstage/config": "^1.0.1",
|
|
28
27
|
"@backstage/errors": "^1.1.0",
|
|
28
|
+
"@types/express": "*",
|
|
29
|
+
"express": "^4.17.1",
|
|
29
30
|
"jose": "^4.6.0",
|
|
30
31
|
"node-fetch": "^2.6.7",
|
|
31
32
|
"winston": "^3.2.1"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@backstage/backend-test-utils": "^0.1.28-next.
|
|
35
|
-
"@backstage/cli": "^0.19.0-next.
|
|
35
|
+
"@backstage/backend-test-utils": "^0.1.28-next.2",
|
|
36
|
+
"@backstage/cli": "^0.19.0-next.2",
|
|
36
37
|
"lodash": "^4.17.21",
|
|
37
|
-
"msw": "^0.
|
|
38
|
+
"msw": "^0.47.0",
|
|
38
39
|
"uuid": "^8.0.0"
|
|
39
40
|
},
|
|
40
41
|
"files": [
|
|
41
42
|
"dist"
|
|
42
43
|
],
|
|
43
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "24f889f173370f060725fcf9404081e40769beb4"
|
|
44
45
|
}
|