Merge pull request #8292 from sonali-mishra-94/add-oauth2-header

Add custom authorization header for OAuth2.0 strategy
This commit is contained in:
Patrik Oldsberg
2021-12-02 13:29:42 +01:00
committed by GitHub
2 changed files with 15 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@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 (