@backstage/plugin-auth-node 0.6.8 → 0.6.9-next.0
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,18 @@
|
|
|
1
1
|
# @backstage/plugin-auth-node
|
|
2
2
|
|
|
3
|
+
## 0.6.9-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 05f60e1: Refactored constructor parameter properties to explicit property declarations for compatibility with TypeScript's `erasableSyntaxOnly` setting. This internal refactoring maintains all existing functionality while ensuring TypeScript compilation compatibility.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/config@1.3.6-next.0
|
|
10
|
+
- @backstage/catalog-model@1.7.6-next.0
|
|
11
|
+
- @backstage/backend-plugin-api@1.4.5-next.0
|
|
12
|
+
- @backstage/catalog-client@1.12.1-next.0
|
|
13
|
+
- @backstage/errors@1.2.7
|
|
14
|
+
- @backstage/types@1.2.2
|
|
15
|
+
|
|
3
16
|
## 0.6.8
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -19,10 +19,6 @@ function splitScope(scope) {
|
|
|
19
19
|
return scope.split(/[\s|,]/).filter(Boolean);
|
|
20
20
|
}
|
|
21
21
|
class CookieScopeManager {
|
|
22
|
-
constructor(scopeTransform, cookieManager) {
|
|
23
|
-
this.scopeTransform = scopeTransform;
|
|
24
|
-
this.cookieManager = cookieManager;
|
|
25
|
-
}
|
|
26
22
|
static create(options) {
|
|
27
23
|
const { authenticator, config } = options;
|
|
28
24
|
const shouldPersistScopes = authenticator.scopes?.persist ?? authenticator.shouldPersistScopes ?? false;
|
|
@@ -37,6 +33,12 @@ class CookieScopeManager {
|
|
|
37
33
|
shouldPersistScopes ? options.cookieManager : void 0
|
|
38
34
|
);
|
|
39
35
|
}
|
|
36
|
+
scopeTransform;
|
|
37
|
+
cookieManager;
|
|
38
|
+
constructor(scopeTransform, cookieManager) {
|
|
39
|
+
this.scopeTransform = scopeTransform;
|
|
40
|
+
this.cookieManager = cookieManager;
|
|
41
|
+
}
|
|
40
42
|
async start(req) {
|
|
41
43
|
const requestScope = splitScope(req.query.scope?.toString());
|
|
42
44
|
const grantedScope = splitScope(this.cookieManager?.getGrantedScopes(req));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CookieScopeManager.cjs.js","sources":["../../src/oauth/CookieScopeManager.ts"],"sourcesContent":["/*\n * Copyright 2024 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 express from 'express';\nimport {\n OAuthAuthenticator,\n OAuthAuthenticatorResult,\n OAuthAuthenticatorScopeOptions,\n} from './types';\nimport { OAuthCookieManager } from './OAuthCookieManager';\nimport { OAuthState } from './state';\nimport { AuthenticationError } from '@backstage/errors';\nimport { Config } from '@backstage/config';\n\nfunction reqRes(req: express.Request): express.Response {\n const res = req.res;\n if (!res) {\n throw new Error('No response object found in request');\n }\n return res;\n}\n\nconst defaultTransform: Required<OAuthAuthenticatorScopeOptions>['transform'] =\n ({ requested, granted, required, additional }) => {\n return [...requested, ...granted, ...required, ...additional];\n };\n\nfunction splitScope(scope?: string): Iterable<string> {\n if (!scope) {\n return [];\n }\n\n return scope.split(/[\\s|,]/).filter(Boolean);\n}\n\nexport class CookieScopeManager {\n static create(options: {\n config?: Config;\n additionalScopes?: string[];\n authenticator: OAuthAuthenticator<any, any>;\n cookieManager: OAuthCookieManager;\n }) {\n const { authenticator, config } = options;\n\n const shouldPersistScopes =\n authenticator.scopes?.persist ??\n authenticator.shouldPersistScopes ??\n false;\n\n const configScopes =\n typeof config?.getOptional('additionalScopes') === 'string'\n ? splitScope(config.getString('additionalScopes'))\n : config?.getOptionalStringArray('additionalScopes') ?? [];\n\n const transform = authenticator?.scopes?.transform ?? defaultTransform;\n const additional = [...configScopes, ...(options.additionalScopes ?? [])];\n const required = authenticator?.scopes?.required ?? [];\n\n return new CookieScopeManager(\n (requested, granted) =>\n Array.from(\n new Set(transform({ required, additional, requested, granted })),\n ).join(' '),\n shouldPersistScopes ? options.cookieManager : undefined,\n );\n }\n\n private
|
|
1
|
+
{"version":3,"file":"CookieScopeManager.cjs.js","sources":["../../src/oauth/CookieScopeManager.ts"],"sourcesContent":["/*\n * Copyright 2024 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 express from 'express';\nimport {\n OAuthAuthenticator,\n OAuthAuthenticatorResult,\n OAuthAuthenticatorScopeOptions,\n} from './types';\nimport { OAuthCookieManager } from './OAuthCookieManager';\nimport { OAuthState } from './state';\nimport { AuthenticationError } from '@backstage/errors';\nimport { Config } from '@backstage/config';\n\nfunction reqRes(req: express.Request): express.Response {\n const res = req.res;\n if (!res) {\n throw new Error('No response object found in request');\n }\n return res;\n}\n\nconst defaultTransform: Required<OAuthAuthenticatorScopeOptions>['transform'] =\n ({ requested, granted, required, additional }) => {\n return [...requested, ...granted, ...required, ...additional];\n };\n\nfunction splitScope(scope?: string): Iterable<string> {\n if (!scope) {\n return [];\n }\n\n return scope.split(/[\\s|,]/).filter(Boolean);\n}\n\nexport class CookieScopeManager {\n static create(options: {\n config?: Config;\n additionalScopes?: string[];\n authenticator: OAuthAuthenticator<any, any>;\n cookieManager: OAuthCookieManager;\n }) {\n const { authenticator, config } = options;\n\n const shouldPersistScopes =\n authenticator.scopes?.persist ??\n authenticator.shouldPersistScopes ??\n false;\n\n const configScopes =\n typeof config?.getOptional('additionalScopes') === 'string'\n ? splitScope(config.getString('additionalScopes'))\n : config?.getOptionalStringArray('additionalScopes') ?? [];\n\n const transform = authenticator?.scopes?.transform ?? defaultTransform;\n const additional = [...configScopes, ...(options.additionalScopes ?? [])];\n const required = authenticator?.scopes?.required ?? [];\n\n return new CookieScopeManager(\n (requested, granted) =>\n Array.from(\n new Set(transform({ required, additional, requested, granted })),\n ).join(' '),\n shouldPersistScopes ? options.cookieManager : undefined,\n );\n }\n\n private readonly scopeTransform: (\n requested: Iterable<string>,\n granted: Iterable<string>,\n ) => string;\n private readonly cookieManager?: OAuthCookieManager;\n\n private constructor(\n scopeTransform: (\n requested: Iterable<string>,\n granted: Iterable<string>,\n ) => string,\n cookieManager?: OAuthCookieManager,\n ) {\n this.scopeTransform = scopeTransform;\n this.cookieManager = cookieManager;\n }\n\n async start(\n req: express.Request,\n ): Promise<{ scopeState?: Partial<OAuthState>; scope: string }> {\n const requestScope = splitScope(req.query.scope?.toString());\n const grantedScope = splitScope(this.cookieManager?.getGrantedScopes(req));\n\n const scope = this.scopeTransform(requestScope, grantedScope);\n\n if (this.cookieManager) {\n // If scopes are persisted then we pass them through the state so that we\n // can set the cookie on successful auth\n return {\n scope,\n scopeState: { scope },\n };\n }\n return { scope };\n }\n\n async handleCallback(\n req: express.Request,\n ctx: {\n result: OAuthAuthenticatorResult<any>;\n state: OAuthState;\n origin?: string;\n },\n ): Promise<string> {\n // If we are not persisting scopes we can forward the scope from the result\n if (!this.cookieManager) {\n return Array.from(splitScope(ctx.result.session.scope)).join(' ');\n }\n\n const scope = ctx.state.scope;\n if (scope === undefined) {\n throw new AuthenticationError('No scope found in OAuth state');\n }\n\n // Store the scope that we have been granted for this session. This is useful if\n // the provider does not return granted scopes on refresh or if they are normalized.\n this.cookieManager.setGrantedScopes(reqRes(req), scope, ctx.origin);\n\n return scope;\n }\n\n async clear(req: express.Request): Promise<void> {\n if (this.cookieManager) {\n this.cookieManager.removeGrantedScopes(reqRes(req), req.get('origin'));\n }\n }\n\n async refresh(req: express.Request): Promise<{\n scope: string;\n scopeAlreadyGranted?: boolean;\n commit(result: OAuthAuthenticatorResult<any>): Promise<string>;\n }> {\n const requestScope = splitScope(req.query.scope?.toString());\n const grantedScope = splitScope(this.cookieManager?.getGrantedScopes(req));\n\n const scope = this.scopeTransform(requestScope, grantedScope);\n\n return {\n scope,\n scopeAlreadyGranted: this.cookieManager\n ? hasScopeBeenGranted(grantedScope, scope)\n : undefined,\n commit: async result => {\n if (this.cookieManager) {\n this.cookieManager.setGrantedScopes(\n reqRes(req),\n scope,\n req.get('origin'),\n );\n return scope;\n }\n\n return Array.from(splitScope(result.session.scope)).join(' ');\n },\n };\n }\n}\n\nfunction hasScopeBeenGranted(\n grantedScope: Iterable<string>,\n requestedScope: string,\n): boolean {\n const granted = new Set(grantedScope);\n for (const requested of splitScope(requestedScope)) {\n if (!granted.has(requested)) {\n return false;\n }\n }\n return true;\n}\n"],"names":["AuthenticationError"],"mappings":";;;;AA2BA,SAAS,OAAO,GAAA,EAAwC;AACtD,EAAA,MAAM,MAAM,GAAA,CAAI,GAAA;AAChB,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,MAAM,qCAAqC,CAAA;AAAA,EACvD;AACA,EAAA,OAAO,GAAA;AACT;AAEA,MAAM,mBACJ,CAAC,EAAE,WAAW,OAAA,EAAS,QAAA,EAAU,YAAW,KAAM;AAChD,EAAA,OAAO,CAAC,GAAG,SAAA,EAAW,GAAG,SAAS,GAAG,QAAA,EAAU,GAAG,UAAU,CAAA;AAC9D,CAAA;AAEF,SAAS,WAAW,KAAA,EAAkC;AACpD,EAAA,IAAI,CAAC,KAAA,EAAO;AACV,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,OAAO,KAAA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
"backstage": {
|
|
5
5
|
"role": "node-library",
|
|
6
6
|
"pluginId": "auth",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"test": "backstage-cli package test"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
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.4.5-next.0",
|
|
42
|
+
"@backstage/catalog-client": "1.12.1-next.0",
|
|
43
|
+
"@backstage/catalog-model": "1.7.6-next.0",
|
|
44
|
+
"@backstage/config": "1.3.6-next.0",
|
|
45
|
+
"@backstage/errors": "1.2.7",
|
|
46
|
+
"@backstage/types": "1.2.2",
|
|
47
47
|
"@types/express": "^4.17.6",
|
|
48
48
|
"@types/passport": "^1.0.3",
|
|
49
49
|
"express": "^4.17.1",
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"zod-validation-error": "^3.4.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@backstage/backend-defaults": "
|
|
59
|
-
"@backstage/backend-test-utils": "
|
|
60
|
-
"@backstage/cli": "
|
|
58
|
+
"@backstage/backend-defaults": "0.13.1-next.0",
|
|
59
|
+
"@backstage/backend-test-utils": "1.10.0-next.0",
|
|
60
|
+
"@backstage/cli": "0.34.5-next.0",
|
|
61
61
|
"cookie-parser": "^1.4.6",
|
|
62
62
|
"express-promise-router": "^4.1.1",
|
|
63
63
|
"lodash": "^4.17.21",
|