@backstage/plugin-auth-backend-module-guest-provider 0.1.0-next.1 → 0.1.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,51 @@
1
1
  # @backstage/plugin-auth-backend-module-guest-provider
2
2
 
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1bedb23: Adds a new guest provider that maps guest users to actual tokens. This also shifts the default guest login to `user:development/guest` to reduce overlap with your production/real data. To change that (or set it back to the old default, use the new `auth.providers.guest.userEntityRef` config key) like so,
8
+
9
+ ```yaml title=app-config.yaml
10
+ auth:
11
+ providers:
12
+ guest:
13
+ userEntityRef: user:default/guest
14
+ ```
15
+
16
+ This also adds a new property to control the ownership entity refs,
17
+
18
+ ```yaml title=app-config.yaml
19
+ auth:
20
+ providers:
21
+ guest:
22
+ ownershipEntityRefs:
23
+ - guests
24
+ - development/custom
25
+ ```
26
+
27
+ ### Patch Changes
28
+
29
+ - 72dd380: Ensure that the config schema is present
30
+ - 50a331b: Fix issue for issuing a token when `guest` user does not exist in catalog
31
+ - Updated dependencies
32
+ - @backstage/backend-common@0.21.4
33
+ - @backstage/plugin-auth-node@0.4.9
34
+ - @backstage/errors@1.2.4
35
+ - @backstage/backend-plugin-api@0.6.14
36
+ - @backstage/catalog-model@1.4.5
37
+
38
+ ## 0.1.0-next.2
39
+
40
+ ### Patch Changes
41
+
42
+ - Updated dependencies
43
+ - @backstage/backend-common@0.21.4-next.2
44
+ - @backstage/plugin-auth-node@0.4.9-next.2
45
+ - @backstage/backend-plugin-api@0.6.14-next.2
46
+ - @backstage/catalog-model@1.4.5-next.0
47
+ - @backstage/errors@1.2.4-next.0
48
+
3
49
  ## 0.1.0-next.1
4
50
 
5
51
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -34,7 +34,7 @@ const signInAsGuestUser = (config) => async (_, ctx) => {
34
34
  "ownershipEntityRefs"
35
35
  )) != null ? _b : [userRef];
36
36
  try {
37
- return ctx.signInWithCatalogUser({ entityRef: userRef });
37
+ return await ctx.signInWithCatalogUser({ entityRef: userRef });
38
38
  } catch (err) {
39
39
  return ctx.issueToken({
40
40
  claims: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/authenticator.ts","../src/resolvers.ts","../src/module.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 { createProxyAuthenticator } from '@backstage/plugin-auth-node';\n\nexport const guestAuthenticator = createProxyAuthenticator({\n defaultProfileTransform: async () => {\n return { profile: {} };\n },\n initialize() {},\n async authenticate() {\n return { result: {} };\n },\n});\n","/*\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 { stringifyEntityRef } from '@backstage/catalog-model';\nimport type { Config } from '@backstage/config';\nimport { SignInResolver } from '@backstage/plugin-auth-node';\nimport { NotImplementedError } from '@backstage/errors';\n\n/**\n * Provide a default implementation of the user to resolve to. By default, this\n * is `user:development/guest`. We will attempt to get that user if they're in the\n * catalog. If that user doesn't exist in the catalog, we will still create a\n * token for them so they can keep viewing.\n */\nexport const signInAsGuestUser: (config: Config) => SignInResolver<{}> =\n (config: Config) => async (_, ctx) => {\n if (\n process.env.NODE_ENV !== 'development' &&\n config.getOptionalBoolean('dangerouslyAllowOutsideDevelopment') !== true\n ) {\n throw new NotImplementedError(\n 'The guest provider is NOT recommended for use outside of a development environment. If you want to enable this, set `auth.providers.guest.dangerouslyAllowOutsideDevelopment: true` in your app config.',\n );\n }\n const userRef =\n config.getOptionalString('userEntityRef') ??\n stringifyEntityRef({\n kind: 'user',\n namespace: 'development',\n name: 'guest',\n });\n const ownershipRefs = config.getOptionalStringArray(\n 'ownershipEntityRefs',\n ) ?? [userRef];\n try {\n return ctx.signInWithCatalogUser({ entityRef: userRef });\n } catch (err) {\n // We can't guarantee that a guest user exists in the catalog, so we issue a token directly,\n return ctx.issueToken({\n claims: {\n sub: userRef,\n ent: ownershipRefs,\n },\n });\n }\n };\n","/*\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 */\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport {\n authProvidersExtensionPoint,\n createProxyAuthProviderFactory,\n} from '@backstage/plugin-auth-node';\nimport { guestAuthenticator } from './authenticator';\nimport { signInAsGuestUser } from './resolvers';\n\n/** @public */\nexport const authModuleGuestProvider = createBackendModule({\n pluginId: 'auth',\n moduleId: 'guest-provider',\n register(reg) {\n reg.registerInit({\n deps: {\n logger: coreServices.logger,\n providers: authProvidersExtensionPoint,\n config: coreServices.rootConfig,\n },\n async init({ providers, logger, config }) {\n if (process.env.NODE_ENV !== 'development') {\n logger.warn(\n 'You should NOT be using the guest provider outside of a development environment.',\n );\n }\n providers.registerProvider({\n providerId: 'guest',\n factory: createProxyAuthProviderFactory({\n authenticator: guestAuthenticator,\n signInResolver: signInAsGuestUser(\n config.getConfig('auth.providers.guest'),\n ),\n }),\n });\n },\n });\n },\n});\n"],"names":["createProxyAuthenticator","NotImplementedError","stringifyEntityRef","createBackendModule","coreServices","authProvidersExtensionPoint","createProxyAuthProviderFactory"],"mappings":";;;;;;;;;AAkBO,MAAM,qBAAqBA,uCAAyB,CAAA;AAAA,EACzD,yBAAyB,YAAY;AACnC,IAAO,OAAA,EAAE,OAAS,EAAA,EAAG,EAAA,CAAA;AAAA,GACvB;AAAA,EACA,UAAa,GAAA;AAAA,GAAC;AAAA,EACd,MAAM,YAAe,GAAA;AACnB,IAAO,OAAA,EAAE,MAAQ,EAAA,EAAG,EAAA,CAAA;AAAA,GACtB;AACF,CAAC,CAAA;;ACCM,MAAM,iBACX,GAAA,CAAC,MAAmB,KAAA,OAAO,GAAG,GAAQ,KAAA;AA5BxC,EAAA,IAAA,EAAA,EAAA,EAAA,CAAA;AA6BI,EACE,IAAA,OAAA,CAAQ,IAAI,QAAa,KAAA,aAAA,IACzB,OAAO,kBAAmB,CAAA,oCAAoC,MAAM,IACpE,EAAA;AACA,IAAA,MAAM,IAAIC,0BAAA;AAAA,MACR,yMAAA;AAAA,KACF,CAAA;AAAA,GACF;AACA,EAAA,MAAM,WACJ,EAAO,GAAA,MAAA,CAAA,iBAAA,CAAkB,eAAe,CAAA,KAAxC,YACAC,+BAAmB,CAAA;AAAA,IACjB,IAAM,EAAA,MAAA;AAAA,IACN,SAAW,EAAA,aAAA;AAAA,IACX,IAAM,EAAA,OAAA;AAAA,GACP,CAAA,CAAA;AACH,EAAA,MAAM,iBAAgB,EAAO,GAAA,MAAA,CAAA,sBAAA;AAAA,IAC3B,qBAAA;AAAA,GACF,KAFsB,IAEjB,GAAA,EAAA,GAAA,CAAC,OAAO,CAAA,CAAA;AACb,EAAI,IAAA;AACF,IAAA,OAAO,GAAI,CAAA,qBAAA,CAAsB,EAAE,SAAA,EAAW,SAAS,CAAA,CAAA;AAAA,WAChD,GAAK,EAAA;AAEZ,IAAA,OAAO,IAAI,UAAW,CAAA;AAAA,MACpB,MAAQ,EAAA;AAAA,QACN,GAAK,EAAA,OAAA;AAAA,QACL,GAAK,EAAA,aAAA;AAAA,OACP;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAA;;AC/BK,MAAM,0BAA0BC,oCAAoB,CAAA;AAAA,EACzD,QAAU,EAAA,MAAA;AAAA,EACV,QAAU,EAAA,gBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,QAAQC,6BAAa,CAAA,MAAA;AAAA,QACrB,SAAW,EAAAC,0CAAA;AAAA,QACX,QAAQD,6BAAa,CAAA,UAAA;AAAA,OACvB;AAAA,MACA,MAAM,IAAK,CAAA,EAAE,SAAW,EAAA,MAAA,EAAQ,QAAU,EAAA;AACxC,QAAI,IAAA,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,aAAe,EAAA;AAC1C,UAAO,MAAA,CAAA,IAAA;AAAA,YACL,kFAAA;AAAA,WACF,CAAA;AAAA,SACF;AACA,QAAA,SAAA,CAAU,gBAAiB,CAAA;AAAA,UACzB,UAAY,EAAA,OAAA;AAAA,UACZ,SAASE,6CAA+B,CAAA;AAAA,YACtC,aAAe,EAAA,kBAAA;AAAA,YACf,cAAgB,EAAA,iBAAA;AAAA,cACd,MAAA,CAAO,UAAU,sBAAsB,CAAA;AAAA,aACzC;AAAA,WACD,CAAA;AAAA,SACF,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/authenticator.ts","../src/resolvers.ts","../src/module.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 { createProxyAuthenticator } from '@backstage/plugin-auth-node';\n\nexport const guestAuthenticator = createProxyAuthenticator({\n defaultProfileTransform: async () => {\n return { profile: {} };\n },\n initialize() {},\n async authenticate() {\n return { result: {} };\n },\n});\n","/*\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 { stringifyEntityRef } from '@backstage/catalog-model';\nimport type { Config } from '@backstage/config';\nimport { SignInResolver } from '@backstage/plugin-auth-node';\nimport { NotImplementedError } from '@backstage/errors';\n\n/**\n * Provide a default implementation of the user to resolve to. By default, this\n * is `user:development/guest`. We will attempt to get that user if they're in the\n * catalog. If that user doesn't exist in the catalog, we will still create a\n * token for them so they can keep viewing.\n */\nexport const signInAsGuestUser: (config: Config) => SignInResolver<{}> =\n (config: Config) => async (_, ctx) => {\n if (\n process.env.NODE_ENV !== 'development' &&\n config.getOptionalBoolean('dangerouslyAllowOutsideDevelopment') !== true\n ) {\n throw new NotImplementedError(\n 'The guest provider is NOT recommended for use outside of a development environment. If you want to enable this, set `auth.providers.guest.dangerouslyAllowOutsideDevelopment: true` in your app config.',\n );\n }\n const userRef =\n config.getOptionalString('userEntityRef') ??\n stringifyEntityRef({\n kind: 'user',\n namespace: 'development',\n name: 'guest',\n });\n const ownershipRefs = config.getOptionalStringArray(\n 'ownershipEntityRefs',\n ) ?? [userRef];\n try {\n return await ctx.signInWithCatalogUser({ entityRef: userRef });\n } catch (err) {\n // We can't guarantee that a guest user exists in the catalog, so we issue a token directly,\n return ctx.issueToken({\n claims: {\n sub: userRef,\n ent: ownershipRefs,\n },\n });\n }\n };\n","/*\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 */\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport {\n authProvidersExtensionPoint,\n createProxyAuthProviderFactory,\n} from '@backstage/plugin-auth-node';\nimport { guestAuthenticator } from './authenticator';\nimport { signInAsGuestUser } from './resolvers';\n\n/** @public */\nexport const authModuleGuestProvider = createBackendModule({\n pluginId: 'auth',\n moduleId: 'guest-provider',\n register(reg) {\n reg.registerInit({\n deps: {\n logger: coreServices.logger,\n providers: authProvidersExtensionPoint,\n config: coreServices.rootConfig,\n },\n async init({ providers, logger, config }) {\n if (process.env.NODE_ENV !== 'development') {\n logger.warn(\n 'You should NOT be using the guest provider outside of a development environment.',\n );\n }\n providers.registerProvider({\n providerId: 'guest',\n factory: createProxyAuthProviderFactory({\n authenticator: guestAuthenticator,\n signInResolver: signInAsGuestUser(\n config.getConfig('auth.providers.guest'),\n ),\n }),\n });\n },\n });\n },\n});\n"],"names":["createProxyAuthenticator","NotImplementedError","stringifyEntityRef","createBackendModule","coreServices","authProvidersExtensionPoint","createProxyAuthProviderFactory"],"mappings":";;;;;;;;;AAkBO,MAAM,qBAAqBA,uCAAyB,CAAA;AAAA,EACzD,yBAAyB,YAAY;AACnC,IAA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AAA,EACV,QAAU,EAAA,gBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,QAAQC,6BAAa,CAAA,MAAA;AAAA,QACrB,SAAW,EAAAC,0CAAA;AAAA,QACX,QAAQD,6BAAa,CAAA,UAAA;AAAA,OACvB;AAAA,MACA,MAAM,IAAK,CAAA,EAAE,SAAW,EAAA,MAAA,EAAQ,QAAU,EAAA;AACxC,QAAI,IAAA,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,aAAe,EAAA;AAC1C,UAAO,MAAA,CAAA,IAAA;AAAA,YACL,kFAAA;AAAA,WACF,CAAA;AAAA,SACF;AACA,QAAA,SAAA,CAAU,gBAAiB,CAAA;AAAA,UACzB,UAAY,EAAA,OAAA;AAAA,UACZ,SAASE,6CAA+B,CAAA;AAAA,YACtC,aAAe,EAAA,kBAAA;AAAA,YACf,cAAgB,EAAA,iBAAA;AAAA,cACd,MAAA,CAAO,UAAU,sBAAsB,CAAA;AAAA,aACzC;AAAA,WACD,CAAA;AAAA,SACF,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-auth-backend-module-guest-provider",
3
- "version": "0.1.0-next.1",
3
+ "version": "0.1.0",
4
4
  "description": "The guest-provider backend module for the auth plugin.",
5
5
  "backstage": {
6
6
  "role": "backend-plugin-module"
@@ -32,17 +32,17 @@
32
32
  "test": "backstage-cli package test"
33
33
  },
34
34
  "dependencies": {
35
- "@backstage/backend-common": "^0.21.4-next.1",
36
- "@backstage/backend-plugin-api": "^0.6.14-next.1",
37
- "@backstage/catalog-model": "^1.4.5-next.0",
38
- "@backstage/errors": "^1.2.4-next.0",
39
- "@backstage/plugin-auth-node": "^0.4.9-next.1",
35
+ "@backstage/backend-common": "^0.21.4",
36
+ "@backstage/backend-plugin-api": "^0.6.14",
37
+ "@backstage/catalog-model": "^1.4.5",
38
+ "@backstage/errors": "^1.2.4",
39
+ "@backstage/plugin-auth-node": "^0.4.9",
40
40
  "passport-oauth2": "^1.7.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@backstage/backend-test-utils": "^0.3.4-next.1",
44
- "@backstage/cli": "^0.25.3-next.1",
45
- "@backstage/config": "^1.2.0-next.1",
43
+ "@backstage/backend-test-utils": "^0.3.4",
44
+ "@backstage/cli": "^0.26.0",
45
+ "@backstage/config": "^1.2.0",
46
46
  "express": "^4.18.2"
47
47
  },
48
48
  "configSchema": "config.d.ts"