Add custom authorization header for OAuth2.0 strategy

Signed-off-by: Sonali Mishra <sonali.priyam@gmail.com>
Signed-off-by: Sonali Mishra <sonali.mishra@grabtaxi.com>
This commit is contained in:
Sonali Mishra
2021-12-01 11:49:34 +08:00
parent 32eb6303c5
commit 1b69ed44f2
2 changed files with 19 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
---
'@backstage/plugin-auth-backend': patch
---
---
## '@backstage/plugin-auth-backend': patch
Added custom OAuth2.0 authorization header for generic oauth2 provider.
@@ -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<OAuthResult> = async (