From 1b69ed44f2cb890d5b13f0336e38b014397eb530 Mon Sep 17 00:00:00 2001 From: Sonali Mishra Date: Wed, 1 Dec 2021 11:49:34 +0800 Subject: [PATCH 1/3] Add custom authorization header for OAuth2.0 strategy Signed-off-by: Sonali Mishra Signed-off-by: Sonali Mishra --- .changeset/thin-poems-watch.md | 9 +++++++++ plugins/auth-backend/src/providers/oauth2/provider.ts | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 .changeset/thin-poems-watch.md diff --git a/.changeset/thin-poems-watch.md b/.changeset/thin-poems-watch.md new file mode 100644 index 0000000000..b537423e34 --- /dev/null +++ b/.changeset/thin-poems-watch.md @@ -0,0 +1,9 @@ +--- +'@backstage/plugin-auth-backend': patch +--- + +--- + +## '@backstage/plugin-auth-backend': patch + +Added custom OAuth2.0 authorization header for generic oauth2 provider. diff --git a/plugins/auth-backend/src/providers/oauth2/provider.ts b/plugins/auth-backend/src/providers/oauth2/provider.ts index cf70580664..1160ad19c9 100644 --- a/plugins/auth-backend/src/providers/oauth2/provider.ts +++ b/plugins/auth-backend/src/providers/oauth2/provider.ts @@ -85,6 +85,12 @@ export class OAuth2AuthProvider implements OAuthHandlers { tokenURL: options.tokenUrl, passReqToCallback: false as true, scope: options.scope, + customHeaders: { + Authorization: `Basic ${this.encodeClientCredentials( + options.clientId, + options.clientSecret, + )}`, + }, }, ( accessToken: any, @@ -187,6 +193,10 @@ export class OAuth2AuthProvider implements OAuthHandlers { return response; } + + encodeClientCredentials(clientID: string, clientSecret: string): string { + return Buffer.from(`${clientID}:${clientSecret}`).toString('base64'); + } } export const oAuth2DefaultSignInResolver: SignInResolver = async ( From 4df32ebf2f0a08d303854a50c97856981c7227c9 Mon Sep 17 00:00:00 2001 From: Sonali Mishra Date: Thu, 2 Dec 2021 16:24:49 +0800 Subject: [PATCH 2/3] Cleanup changeset Signed-off-by: Sonali Mishra --- .changeset/thin-poems-watch.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.changeset/thin-poems-watch.md b/.changeset/thin-poems-watch.md index b537423e34..ed0e15bcfd 100644 --- a/.changeset/thin-poems-watch.md +++ b/.changeset/thin-poems-watch.md @@ -1,9 +1,3 @@ ---- -'@backstage/plugin-auth-backend': patch ---- - ---- - ## '@backstage/plugin-auth-backend': patch Added custom OAuth2.0 authorization header for generic oauth2 provider. From 1925d1c5c666731625a3f2d1ca616543bd8dd9aa Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 2 Dec 2021 13:08:41 +0100 Subject: [PATCH 3/3] Update thin-poems-watch.md Signed-off-by: Patrik Oldsberg --- .changeset/thin-poems-watch.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.changeset/thin-poems-watch.md b/.changeset/thin-poems-watch.md index ed0e15bcfd..9ace95ef04 100644 --- a/.changeset/thin-poems-watch.md +++ b/.changeset/thin-poems-watch.md @@ -1,3 +1,5 @@ -## '@backstage/plugin-auth-backend': patch +--- +'@backstage/plugin-auth-backend': patch +--- Added custom OAuth2.0 authorization header for generic oauth2 provider.