From d712d2050535b1c197f831443ea33f3f085b587c Mon Sep 17 00:00:00 2001 From: Kinga Sieminiak Date: Tue, 8 Sep 2020 11:43:48 +0200 Subject: [PATCH 1/2] Enable usage of oauth2 frontend provider --- packages/core-api/src/apis/definitions/auth.ts | 6 +++++- .../src/apis/implementations/auth/oauth2/OAuth2.ts | 12 +++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/core-api/src/apis/definitions/auth.ts b/packages/core-api/src/apis/definitions/auth.ts index 469414d3dc..1ff8c46dad 100644 --- a/packages/core-api/src/apis/definitions/auth.ts +++ b/packages/core-api/src/apis/definitions/auth.ts @@ -299,7 +299,11 @@ export const microsoftAuthApiRef = createApiRef< * Provides authentication for custom identity providers. */ export const oauth2ApiRef = createApiRef< - OAuthApi & OpenIdConnectApi & ProfileInfoApi & SessionStateApi + OAuthApi & + OpenIdConnectApi & + ProfileInfoApi & + SessionStateApi & + BackstageIdentityApi >({ id: 'core.auth.oauth2', description: 'Example of how to use oauth2 custom provider', diff --git a/packages/core-api/src/apis/implementations/auth/oauth2/OAuth2.ts b/packages/core-api/src/apis/implementations/auth/oauth2/OAuth2.ts index cf582b3a13..80a24cf9e1 100644 --- a/packages/core-api/src/apis/implementations/auth/oauth2/OAuth2.ts +++ b/packages/core-api/src/apis/implementations/auth/oauth2/OAuth2.ts @@ -42,6 +42,7 @@ type CreateOptions = { environment?: string; provider?: AuthProvider & { id: string }; + defaultScopes?: string[]; }; export type OAuth2Response = { @@ -70,6 +71,11 @@ class OAuth2 environment = 'development', provider = DEFAULT_PROVIDER, oauthRequestApi, + defaultScopes = [ + 'openid', + `${SCOPE_PREFIX}userinfo.email`, + `${SCOPE_PREFIX}userinfo.profile`, + ], }: CreateOptions) { const connector = new DefaultAuthConnector({ discoveryApi, @@ -93,11 +99,7 @@ class OAuth2 const sessionManager = new RefreshingAuthSessionManager({ connector, - defaultScopes: new Set([ - 'openid', - `${SCOPE_PREFIX}userinfo.email`, - `${SCOPE_PREFIX}userinfo.profile`, - ]), + defaultScopes: new Set(defaultScopes), sessionScopes: (session: OAuth2Session) => session.providerInfo.scopes, sessionShouldRefresh: (session: OAuth2Session) => { const expiresInSec = From 61d1f0267e64256ee30392291c203b0c7e26af4a Mon Sep 17 00:00:00 2001 From: Kinga Sieminiak Date: Tue, 8 Sep 2020 12:16:31 +0200 Subject: [PATCH 2/2] Keep 'defaultScopes' value as an empty array by default --- .../src/apis/implementations/auth/oauth2/OAuth2.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/core-api/src/apis/implementations/auth/oauth2/OAuth2.ts b/packages/core-api/src/apis/implementations/auth/oauth2/OAuth2.ts index 80a24cf9e1..3f8ebce5ba 100644 --- a/packages/core-api/src/apis/implementations/auth/oauth2/OAuth2.ts +++ b/packages/core-api/src/apis/implementations/auth/oauth2/OAuth2.ts @@ -62,8 +62,6 @@ const DEFAULT_PROVIDER = { icon: OAuth2Icon, }; -const SCOPE_PREFIX = ''; - class OAuth2 implements OAuthApi, OpenIdConnectApi, ProfileInfoApi, SessionStateApi { static create({ @@ -71,11 +69,7 @@ class OAuth2 environment = 'development', provider = DEFAULT_PROVIDER, oauthRequestApi, - defaultScopes = [ - 'openid', - `${SCOPE_PREFIX}userinfo.email`, - `${SCOPE_PREFIX}userinfo.profile`, - ], + defaultScopes = [], }: CreateOptions) { const connector = new DefaultAuthConnector({ discoveryApi,