Merge pull request #2326 from kingasieminiak/enable-oauth2-provider-usage
Enable usage of oAuth2 frontend provider
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -42,6 +42,7 @@ type CreateOptions = {
|
||||
|
||||
environment?: string;
|
||||
provider?: AuthProvider & { id: string };
|
||||
defaultScopes?: string[];
|
||||
};
|
||||
|
||||
export type OAuth2Response = {
|
||||
@@ -61,8 +62,6 @@ const DEFAULT_PROVIDER = {
|
||||
icon: OAuth2Icon,
|
||||
};
|
||||
|
||||
const SCOPE_PREFIX = '';
|
||||
|
||||
class OAuth2
|
||||
implements OAuthApi, OpenIdConnectApi, ProfileInfoApi, SessionStateApi {
|
||||
static create({
|
||||
@@ -70,6 +69,7 @@ class OAuth2
|
||||
environment = 'development',
|
||||
provider = DEFAULT_PROVIDER,
|
||||
oauthRequestApi,
|
||||
defaultScopes = [],
|
||||
}: CreateOptions) {
|
||||
const connector = new DefaultAuthConnector({
|
||||
discoveryApi,
|
||||
@@ -93,11 +93,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 =
|
||||
|
||||
Reference in New Issue
Block a user