@backstage/plugin-auth-node 0.5.5 → 0.5.6-next.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @backstage/plugin-auth-node
|
|
2
2
|
|
|
3
|
+
## 0.5.6-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/types@1.2.1-next.0
|
|
9
|
+
- @backstage/backend-plugin-api@1.1.1-next.1
|
|
10
|
+
- @backstage/catalog-model@1.7.3-next.0
|
|
11
|
+
- @backstage/config@1.3.2-next.0
|
|
12
|
+
- @backstage/errors@1.2.7-next.0
|
|
13
|
+
- @backstage/catalog-client@1.9.1-next.0
|
|
14
|
+
|
|
15
|
+
## 0.5.6-next.0
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- d9d62ef: Remove some internal usages of the backend-common package
|
|
20
|
+
- 8379bf4: Remove usages of `PluginDatabaseManager` and `PluginEndpointDiscovery` and replace with their equivalent service types
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
- @backstage/backend-plugin-api@1.1.1-next.0
|
|
23
|
+
- @backstage/catalog-client@1.9.0
|
|
24
|
+
- @backstage/catalog-model@1.7.2
|
|
25
|
+
- @backstage/config@1.3.1
|
|
26
|
+
- @backstage/errors@1.2.6
|
|
27
|
+
- @backstage/types@1.2.0
|
|
28
|
+
|
|
3
29
|
## 0.5.5
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultIdentityClient.cjs.js","sources":["../../src/identity/DefaultIdentityClient.ts"],"sourcesContent":["/*\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 {
|
|
1
|
+
{"version":3,"file":"DefaultIdentityClient.cjs.js","sources":["../../src/identity/DefaultIdentityClient.ts"],"sourcesContent":["/*\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 { AuthenticationError } from '@backstage/errors';\nimport {\n createRemoteJWKSet,\n decodeJwt,\n decodeProtectedHeader,\n FlattenedJWSInput,\n JWSHeaderParameters,\n jwtVerify,\n} from 'jose';\nimport { GetKeyFunction } from 'jose';\nimport { getBearerTokenFromAuthorizationHeader } from './getBearerTokenFromAuthorizationHeader';\nimport { IdentityApi, IdentityApiGetIdentityRequest } from './IdentityApi';\nimport { BackstageIdentityResponse } from '../types';\nimport { DiscoveryService } from '@backstage/backend-plugin-api';\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: DiscoveryService;\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: DiscoveryService;\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(options: IdentityApiGetIdentityRequest) {\n const {\n request: { headers },\n } = options;\n if (!headers.authorization) {\n return undefined;\n }\n try {\n return await this.authenticate(\n getBearerTokenFromAuthorizationHeader(headers.authorization),\n );\n } catch (e) {\n throw new AuthenticationError(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"],"names":["getBearerTokenFromAuthorizationHeader","AuthenticationError","jwtVerify","decodeJwt","decodeProtectedHeader","createRemoteJWKSet"],"mappings":";;;;;;AA+BA,MAAM,cAAiB,GAAA,EAAA;AAwBhB,MAAM,qBAA6C,CAAA;AAAA,EACvC,SAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACT,QAAA;AAAA,EACA,eAA0B,GAAA,CAAA;AAAA;AAAA;AAAA;AAAA,EAKlC,OAAO,OAAO,OAAuD,EAAA;AACnE,IAAO,OAAA,IAAI,sBAAsB,OAAO,CAAA;AAAA;AAC1C,EAEQ,YAAY,OAAgC,EAAA;AAClD,IAAA,IAAA,CAAK,YAAY,OAAQ,CAAA,SAAA;AACzB,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA;AACtB,IAAK,IAAA,CAAA,UAAA,GAAa,QAAQ,cAAe,CAAA,YAAY,IACjD,OAAQ,CAAA,UAAA,GACR,CAAC,OAAO,CAAA;AAAA;AACd,EAEA,MAAM,YAAY,OAAwC,EAAA;AACxD,IAAM,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from '@backstage/backend-plugin-api';
|
|
2
|
+
import { LoggerService, DiscoveryService } from '@backstage/backend-plugin-api';
|
|
3
3
|
import { EntityFilterQuery } from '@backstage/catalog-client';
|
|
4
4
|
import { Entity } from '@backstage/catalog-model';
|
|
5
5
|
import { Config } from '@backstage/config';
|
|
6
6
|
import { JsonValue, JsonObject } from '@backstage/types';
|
|
7
7
|
import express, { Request, Response } from 'express';
|
|
8
8
|
import { BackstageSignInResult as BackstageSignInResult$1, BackstageIdentityResponse as BackstageIdentityResponse$1 } from '@backstage/plugin-auth-node';
|
|
9
|
-
import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
|
10
9
|
import { Profile, Strategy } from 'passport';
|
|
11
10
|
import { ZodSchema, ZodTypeDef } from 'zod';
|
|
12
11
|
|
|
@@ -444,7 +443,7 @@ interface IdentityApi {
|
|
|
444
443
|
* @public
|
|
445
444
|
*/
|
|
446
445
|
type IdentityClientOptions = {
|
|
447
|
-
discovery:
|
|
446
|
+
discovery: DiscoveryService;
|
|
448
447
|
issuer?: string;
|
|
449
448
|
/** JWS "alg" (Algorithm) Header Parameter values. Defaults to an array containing just ES256.
|
|
450
449
|
* More info on supported algorithms: https://github.com/panva/jose */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-auth-node",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6-next.1",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "node-library",
|
|
6
6
|
"pluginId": "auth",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@backstage/backend-common": "^0.25.0",
|
|
41
|
-
"@backstage/backend-plugin-api": "
|
|
42
|
-
"@backstage/catalog-client": "
|
|
43
|
-
"@backstage/catalog-model": "
|
|
44
|
-
"@backstage/config": "
|
|
45
|
-
"@backstage/errors": "
|
|
46
|
-
"@backstage/types": "
|
|
41
|
+
"@backstage/backend-plugin-api": "1.1.1-next.1",
|
|
42
|
+
"@backstage/catalog-client": "1.9.1-next.0",
|
|
43
|
+
"@backstage/catalog-model": "1.7.3-next.0",
|
|
44
|
+
"@backstage/config": "1.3.2-next.0",
|
|
45
|
+
"@backstage/errors": "1.2.7-next.0",
|
|
46
|
+
"@backstage/types": "1.2.1-next.0",
|
|
47
47
|
"@types/express": "^4.17.6",
|
|
48
48
|
"@types/passport": "^1.0.3",
|
|
49
49
|
"express": "^4.17.1",
|
|
@@ -56,8 +56,9 @@
|
|
|
56
56
|
"zod-validation-error": "^3.4.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@backstage/backend-
|
|
60
|
-
"@backstage/
|
|
59
|
+
"@backstage/backend-defaults": "0.7.0-next.1",
|
|
60
|
+
"@backstage/backend-test-utils": "1.2.1-next.1",
|
|
61
|
+
"@backstage/cli": "0.29.5-next.1",
|
|
61
62
|
"cookie-parser": "^1.4.6",
|
|
62
63
|
"express-promise-router": "^4.1.1",
|
|
63
64
|
"lodash": "^4.17.21",
|