From 74b1dc9e1596a851cc2adf90ae54c43b8749a2d6 Mon Sep 17 00:00:00 2001 From: Dmitry Gusev Date: Mon, 26 Feb 2024 20:48:50 +0300 Subject: [PATCH 1/2] auth-backend-module-oidc-provider: increase http request timeout Signed-off-by: Dmitry Gusev --- .changeset/light-chicken-search.md | 5 +++++ .../auth-backend-module-oidc-provider/src/authenticator.ts | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 .changeset/light-chicken-search.md diff --git a/.changeset/light-chicken-search.md b/.changeset/light-chicken-search.md new file mode 100644 index 0000000000..aebb53d753 --- /dev/null +++ b/.changeset/light-chicken-search.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-auth-backend-module-oidc-provider': patch +--- + +Increased HTTP request timeout used by OIDC authenticator. diff --git a/plugins/auth-backend-module-oidc-provider/src/authenticator.ts b/plugins/auth-backend-module-oidc-provider/src/authenticator.ts index eddf57a55b..29e8d54ada 100644 --- a/plugins/auth-backend-module-oidc-provider/src/authenticator.ts +++ b/plugins/auth-backend-module-oidc-provider/src/authenticator.ts @@ -15,6 +15,7 @@ */ import { + custom, Issuer, ClientAuthMethod, TokenSet, @@ -30,6 +31,10 @@ import { PassportOAuthPrivateInfo, } from '@backstage/plugin-auth-node'; +custom.setHttpOptionsDefaults({ + timeout: 10000, +}); + /** * authentication result for the OIDC which includes the token set and user * profile response From 94cb1d1c23823a31f9dab111ebd7125f6e2ac8c5 Mon Sep 17 00:00:00 2001 From: Dmitry Gusev Date: Tue, 27 Feb 2024 10:52:28 +0300 Subject: [PATCH 2/2] auth-backend-module-oidc-provider: set http request timeout on a per-request basis Signed-off-by: Dmitry Gusev --- .../src/authenticator.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/auth-backend-module-oidc-provider/src/authenticator.ts b/plugins/auth-backend-module-oidc-provider/src/authenticator.ts index 29e8d54ada..c3754b6f19 100644 --- a/plugins/auth-backend-module-oidc-provider/src/authenticator.ts +++ b/plugins/auth-backend-module-oidc-provider/src/authenticator.ts @@ -16,6 +16,7 @@ import { custom, + CustomHttpOptionsProvider, Issuer, ClientAuthMethod, TokenSet, @@ -31,9 +32,13 @@ import { PassportOAuthPrivateInfo, } from '@backstage/plugin-auth-node'; -custom.setHttpOptionsDefaults({ - timeout: 10000, -}); +const HTTP_OPTION_TIMEOUT = 10000; +const httpOptionsProvider: CustomHttpOptionsProvider = (_url, options) => { + return { + ...options, + timeout: HTTP_OPTION_TIMEOUT, + }; +}; /** * authentication result for the OIDC which includes the token set and user @@ -71,7 +76,11 @@ export const oidcAuthenticator = createOAuthAuthenticator({ const initializedScope = config.getOptionalString('scope'); const initializedPrompt = config.getOptionalString('prompt'); + Issuer[custom.http_options] = httpOptionsProvider; const promise = Issuer.discover(metadataUrl).then(issuer => { + issuer[custom.http_options] = httpOptionsProvider; + issuer.Client[custom.http_options] = httpOptionsProvider; + const client = new issuer.Client({ access_type: 'offline', // this option must be passed to provider to receive a refresh token client_id: clientId, @@ -83,6 +92,7 @@ export const oidcAuthenticator = createOAuthAuthenticator({ id_token_signed_response_alg: tokenSignedResponseAlg || 'RS256', scope: initializedScope || '', }); + client[custom.http_options] = httpOptionsProvider; const strategy = new OidcStrategy( {