From 0afc4f21d89ef7c8fc1bee8758773d2caba657c8 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 18 Feb 2025 15:09:27 +0100 Subject: [PATCH] chore: cleanup changeset and refactor Signed-off-by: blam --- .changeset/new-dryers-cough-2.md | 5 +++++ .changeset/new-dryers-cough.md | 3 +-- .../src/authenticator.ts | 13 +++---------- 3 files changed, 9 insertions(+), 12 deletions(-) create mode 100644 .changeset/new-dryers-cough-2.md diff --git a/.changeset/new-dryers-cough-2.md b/.changeset/new-dryers-cough-2.md new file mode 100644 index 0000000000..436bb3629c --- /dev/null +++ b/.changeset/new-dryers-cough-2.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-auth-backend-module-oidc-provider': patch +--- + +Simplify the `start` method in the `authenticator` to just return the helper promise diff --git a/.changeset/new-dryers-cough.md b/.changeset/new-dryers-cough.md index 39a972e71f..5be2dd761a 100644 --- a/.changeset/new-dryers-cough.md +++ b/.changeset/new-dryers-cough.md @@ -1,6 +1,5 @@ --- -'@backstage/plugin-auth-backend-module-oidc-provider': patch '@backstage/plugin-auth-node': patch --- -Fixed a potential issue when using the Backstage's `PassportOAuthAuthenticatorHelper` to implement a custom OAuth Authenticator. The issue occurs during the start stage of the authorization process when the custom `passport.Strategy` calls the `error()` to propagate an error message. Because the `error` function wasn't being set Backstage would throw a `this.error is not a function` error thus hiding the original cause. +Add an `error` handler to the `strategy` to reject the `executeRedirectStrategy` diff --git a/plugins/auth-backend-module-oidc-provider/src/authenticator.ts b/plugins/auth-backend-module-oidc-provider/src/authenticator.ts index cb01639685..c396ea7034 100644 --- a/plugins/auth-backend-module-oidc-provider/src/authenticator.ts +++ b/plugins/auth-backend-module-oidc-provider/src/authenticator.ts @@ -135,7 +135,7 @@ export const oidcAuthenticator = createOAuthAuthenticator({ async start(input, ctx) { const { initializedPrompt, promise } = ctx; - const { helper, strategy } = await promise; + const { helper } = await promise; const options: Record = { scope: input.scope, state: input.state, @@ -146,15 +146,8 @@ export const oidcAuthenticator = createOAuthAuthenticator({ options.prompt = prompt; } - return new Promise((resolve, reject) => { - strategy.error = reject; - - return helper - .start(input, { - ...options, - }) - .then(resolve) - .catch(reject); + return helper.start(input, { + ...options, }); },