diff --git a/.changeset/purple-waves-smile.md b/.changeset/purple-waves-smile.md new file mode 100644 index 0000000000..b861089321 --- /dev/null +++ b/.changeset/purple-waves-smile.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-auth-backend-module-guest-provider': patch +--- + +Error if used outside of a development environment diff --git a/plugins/auth-backend-module-guest-provider/src/authenticator.ts b/plugins/auth-backend-module-guest-provider/src/authenticator.ts index 436b72617d..f12e551f39 100644 --- a/plugins/auth-backend-module-guest-provider/src/authenticator.ts +++ b/plugins/auth-backend-module-guest-provider/src/authenticator.ts @@ -15,12 +15,22 @@ */ import { createProxyAuthenticator } from '@backstage/plugin-auth-node'; +import { NotImplementedError } from '@backstage/errors'; export const guestAuthenticator = createProxyAuthenticator({ defaultProfileTransform: async () => { return { profile: {} }; }, - initialize() {}, + initialize({ config }) { + const allowOutsideDev = config.getOptionalBoolean( + 'dangerouslyAllowOutsideDevelopment', + ); + if (process.env.NODE_ENV !== 'development' && allowOutsideDev !== true) { + throw new NotImplementedError( + 'The guest provider cannot be used outside of a development environment', + ); + } + }, async authenticate() { return { result: {} }; }, diff --git a/plugins/auth-backend-module-guest-provider/src/module.ts b/plugins/auth-backend-module-guest-provider/src/module.ts index 7eac99b0a3..7f912ac436 100644 --- a/plugins/auth-backend-module-guest-provider/src/module.ts +++ b/plugins/auth-backend-module-guest-provider/src/module.ts @@ -31,16 +31,10 @@ export const authModuleGuestProvider = createBackendModule({ register(reg) { reg.registerInit({ deps: { - logger: coreServices.logger, providers: authProvidersExtensionPoint, config: coreServices.rootConfig, }, - async init({ providers, logger, config }) { - if (process.env.NODE_ENV !== 'development') { - logger.warn( - 'You should NOT be using the guest provider outside of a development environment.', - ); - } + async init({ providers, config }) { providers.registerProvider({ providerId: 'guest', factory: createProxyAuthProviderFactory({