Merge pull request #9804 from backstage/jhaals/cleanup-auth

core-app-api: Remove deprecated auth ApiRefs
This commit is contained in:
Johan Haals
2022-03-01 09:39:34 +01:00
committed by GitHub
13 changed files with 10 additions and 463 deletions
+10
View File
@@ -0,0 +1,10 @@
---
'@backstage/app-defaults': minor
'@backstage/core-app-api': minor
'@backstage/core-components': minor
'@backstage/core-plugin-api': minor
'@backstage/test-utils': minor
'@backstage/plugin-user-settings': minor
---
**BREAKING**: Removed deprecated `auth0AuthApiRef`, `oauth2ApiRef`, `samlAuthApiRef` and `oidcAuthApiRef` as these APIs are too generic to be useful. Instructions for how to migrate can be found at [https://backstage.io/docs/api/deprecations#generic-auth-api-refs](https://backstage.io/docs/api/deprecations#generic-auth-api-refs).
@@ -21,16 +21,13 @@ import {
ErrorAlerter,
GoogleAuth,
GithubAuth,
OAuth2,
OktaAuth,
GitlabAuth,
Auth0Auth,
MicrosoftAuth,
BitbucketAuth,
OAuthRequestManager,
WebStorage,
UrlPatternDiscovery,
SamlAuth,
OneLoginAuth,
UnhandledErrorForwarder,
AtlassianAuth,
@@ -49,16 +46,12 @@ import {
oauthRequestApiRef,
googleAuthApiRef,
githubAuthApiRef,
oauth2ApiRef,
oktaAuthApiRef,
gitlabAuthApiRef,
auth0AuthApiRef,
microsoftAuthApiRef,
storageApiRef,
configApiRef,
samlAuthApiRef,
oneloginAuthApiRef,
oidcAuthApiRef,
bitbucketAuthApiRef,
atlassianAuthApiRef,
} from '@backstage/core-plugin-api';
@@ -197,46 +190,6 @@ export const apis = [
environment: configApi.getOptionalString('auth.environment'),
}),
}),
createApiFactory({
api: auth0AuthApiRef,
deps: {
discoveryApi: discoveryApiRef,
oauthRequestApi: oauthRequestApiRef,
configApi: configApiRef,
},
factory: ({ discoveryApi, oauthRequestApi, configApi }) =>
Auth0Auth.create({
discoveryApi,
oauthRequestApi,
environment: configApi.getOptionalString('auth.environment'),
}),
}),
createApiFactory({
api: oauth2ApiRef,
deps: {
discoveryApi: discoveryApiRef,
oauthRequestApi: oauthRequestApiRef,
configApi: configApiRef,
},
factory: ({ discoveryApi, oauthRequestApi, configApi }) =>
OAuth2.create({
discoveryApi,
oauthRequestApi,
environment: configApi.getOptionalString('auth.environment'),
}),
}),
createApiFactory({
api: samlAuthApiRef,
deps: {
discoveryApi: discoveryApiRef,
configApi: configApiRef,
},
factory: ({ discoveryApi, configApi }) =>
SamlAuth.create({
discoveryApi,
environment: configApi.getOptionalString('auth.environment'),
}),
}),
createApiFactory({
api: oneloginAuthApiRef,
deps: {
@@ -251,25 +204,6 @@ export const apis = [
environment: configApi.getOptionalString('auth.environment'),
}),
}),
createApiFactory({
api: oidcAuthApiRef,
deps: {
discoveryApi: discoveryApiRef,
oauthRequestApi: oauthRequestApiRef,
configApi: configApiRef,
},
factory: ({ discoveryApi, oauthRequestApi, configApi }) =>
OAuth2.create({
discoveryApi,
oauthRequestApi,
provider: {
id: 'oidc',
title: 'Your Identity Provider',
icon: () => null,
},
environment: configApi.getOptionalString('auth.environment'),
}),
}),
createApiFactory({
api: bitbucketAuthApiRef,
deps: {
-21
View File
@@ -19,27 +19,12 @@ import {
gitlabAuthApiRef,
oktaAuthApiRef,
githubAuthApiRef,
samlAuthApiRef,
microsoftAuthApiRef,
oneloginAuthApiRef,
oauth2ApiRef,
oidcAuthApiRef,
bitbucketAuthApiRef,
} from '@backstage/core-plugin-api';
export const providers = [
{
id: 'oidc-auth-provider',
title: 'Oidc',
message: 'Sign In using OpenId Connect',
apiRef: oidcAuthApiRef,
},
{
id: 'oauth2-auth-provider',
title: 'OAuth 2.0',
message: 'Sign In using OAuth 2.0',
apiRef: oauth2ApiRef,
},
{
id: 'google-auth-provider',
title: 'Google',
@@ -70,12 +55,6 @@ export const providers = [
message: 'Sign In using Okta',
apiRef: oktaAuthApiRef,
},
{
id: 'saml-auth-provider',
title: 'SAML',
message: 'Sign In using SAML',
apiRef: samlAuthApiRef,
},
{
id: 'onelogin-auth-provider',
title: 'OneLogin',
-7
View File
@@ -16,7 +16,6 @@ import { AppConfig } from '@backstage/config';
import { AppTheme } from '@backstage/core-plugin-api';
import { AppThemeApi } from '@backstage/core-plugin-api';
import { atlassianAuthApiRef } from '@backstage/core-plugin-api';
import { auth0AuthApiRef } from '@backstage/core-plugin-api';
import { AuthProviderInfo } from '@backstage/core-plugin-api';
import { AuthRequestOptions } from '@backstage/core-plugin-api';
import { BackstageIdentityApi } from '@backstage/core-plugin-api';
@@ -246,12 +245,6 @@ export class AtlassianAuth {
static create(options: OAuthApiCreateOptions): typeof atlassianAuthApiRef.T;
}
// @public @deprecated
export class Auth0Auth {
// (undocumented)
static create(options: OAuthApiCreateOptions): typeof auth0AuthApiRef.T;
}
// @public
export type AuthApiCreateOptions = {
discoveryApi: DiscoveryApi;
@@ -1,67 +0,0 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { auth0AuthApiRef } from '@backstage/core-plugin-api';
import { OAuth2 } from '../oauth2';
import { OAuthApiCreateOptions } from '../types';
const DEFAULT_PROVIDER = {
id: 'auth0',
title: 'Auth0',
icon: () => null,
};
/**
* Implements the OAuth flow to Auth0 products.
*
* @public
* @deprecated Use {@link OAuth2} instead
*
* @example
*
* ```ts
* OAuth2.create({
* discoveryApi,
* oauthRequestApi,
* provider: {
* id: 'auth0',
* title: 'Auth0',
* icon: () => null,
* },
* defaultScopes: ['openid', 'email', 'profile'],
* environment: configApi.getOptionalString('auth.environment'),
* })
* ```
*/
export default class Auth0Auth {
static create(options: OAuthApiCreateOptions): typeof auth0AuthApiRef.T {
const {
discoveryApi,
environment = 'development',
provider = DEFAULT_PROVIDER,
oauthRequestApi,
defaultScopes = ['openid', `email`, `profile`],
} = options;
return OAuth2.create({
discoveryApi,
oauthRequestApi,
provider,
environment,
defaultScopes,
});
}
}
@@ -1,17 +0,0 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { default as Auth0Auth } from './Auth0Auth';
@@ -20,7 +20,6 @@ export * from './google';
export * from './oauth2';
export * from './okta';
export * from './saml';
export * from './auth0';
export * from './microsoft';
export * from './onelogin';
export * from './bitbucket';
@@ -1,95 +0,0 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import Grid from '@material-ui/core/Grid';
import Typography from '@material-ui/core/Typography';
import Button from '@material-ui/core/Button';
import { InfoCard } from '../InfoCard/InfoCard';
import { ProviderComponent, ProviderLoader, SignInProvider } from './types';
import {
useApi,
auth0AuthApiRef,
errorApiRef,
} from '@backstage/core-plugin-api';
import { ForwardedError } from '@backstage/errors';
import { UserIdentity } from './UserIdentity';
const Component: ProviderComponent = ({ onSignInSuccess }) => {
const auth0AuthApi = useApi(auth0AuthApiRef);
const errorApi = useApi(errorApiRef);
const handleLogin = async () => {
try {
const identityResponse = await auth0AuthApi.getBackstageIdentity({
instantPopup: true,
});
if (!identityResponse) {
throw new Error(
'The Auth0 provider is not configured to support sign-in',
);
}
const profile = await auth0AuthApi.getProfile();
onSignInSuccess(
UserIdentity.create({
identity: identityResponse.identity,
authApi: auth0AuthApi,
profile,
}),
);
} catch (error) {
errorApi.post(new ForwardedError('Auth0 login failed', error));
}
};
return (
<Grid item>
<InfoCard
title="Auth0"
actions={
<Button color="primary" variant="outlined" onClick={handleLogin}>
Sign In
</Button>
}
>
<Typography variant="body1">Sign In using Auth0</Typography>
</InfoCard>
</Grid>
);
};
const loader: ProviderLoader = async apis => {
const auth0AuthApi = apis.get(auth0AuthApiRef)!;
const identityResponse = await auth0AuthApi.getBackstageIdentity({
optional: true,
});
if (!identityResponse) {
return undefined;
}
const profile = await auth0AuthApi.getProfile();
return UserIdentity.create({
identity: identityResponse.identity,
authApi: auth0AuthApi,
profile,
});
};
export const auth0Provider: SignInProvider = { Component, loader };
-28
View File
@@ -184,11 +184,6 @@ export function attachComponentData<P>(
data: unknown,
): void;
// @public @deprecated
export const auth0AuthApiRef: ApiRef<
OpenIdConnectApi & ProfileInfoApi & BackstageIdentityApi & SessionApi
>;
// @public
export type AuthProviderInfo = {
id: string;
@@ -531,15 +526,6 @@ export const microsoftAuthApiRef: ApiRef<
SessionApi
>;
// @public @deprecated
export const oauth2ApiRef: ApiRef<
OAuthApi &
OpenIdConnectApi &
ProfileInfoApi &
BackstageIdentityApi &
SessionApi
>;
// @public
export type OAuthApi = {
getAccessToken(
@@ -573,15 +559,6 @@ export type OAuthRequesterOptions<TOAuthResponse> = {
// @public
export type OAuthScope = string | string[];
// @public @deprecated
export const oidcAuthApiRef: ApiRef<
OAuthApi &
OpenIdConnectApi &
ProfileInfoApi &
BackstageIdentityApi &
SessionApi
>;
// @alpha
export const oktaAuthApiRef: ApiRef<
OAuthApi &
@@ -680,11 +657,6 @@ export type RouteRef<Params extends AnyParams = any> = {
params: ParamKeys<Params>;
};
// @public @deprecated
export const samlAuthApiRef: ApiRef<
ProfileInfoApi & BackstageIdentityApi & SessionApi
>;
// @public
export type SessionApi = {
signIn(): Promise<void>;
@@ -366,23 +366,6 @@ export const gitlabAuthApiRef: ApiRef<
id: 'core.auth.gitlab',
});
/**
* Provides authentication towards Auth0 APIs.
*
* @remarks
*
* See {@link https://auth0.com/docs/scopes/current/oidc-scopes}
* for a full list of supported scopes.
*
* @public
* @deprecated See https://backstage.io/docs/api/deprecations#generic-auth-api-refs
*/
export const auth0AuthApiRef: ApiRef<
OpenIdConnectApi & ProfileInfoApi & BackstageIdentityApi & SessionApi
> = createApiRef({
id: 'core.auth.auth0',
});
/**
* Provides authentication towards Microsoft APIs and identities.
*
@@ -404,50 +387,6 @@ export const microsoftAuthApiRef: ApiRef<
id: 'core.auth.microsoft',
});
/**
* Provides authentication for custom identity providers.
*
* @public
* @deprecated See https://backstage.io/docs/api/deprecations#generic-auth-api-refs
*/
export const oauth2ApiRef: ApiRef<
OAuthApi &
OpenIdConnectApi &
ProfileInfoApi &
BackstageIdentityApi &
SessionApi
> = createApiRef({
id: 'core.auth.oauth2',
});
/**
* Provides authentication for custom OpenID Connect identity providers.
*
* @public
* @deprecated See https://backstage.io/docs/api/deprecations#generic-auth-api-refs
*/
export const oidcAuthApiRef: ApiRef<
OAuthApi &
OpenIdConnectApi &
ProfileInfoApi &
BackstageIdentityApi &
SessionApi
> = createApiRef({
id: 'core.auth.oidc',
});
/**
* Provides authentication for SAML-based identity providers.
*
* @public
* @deprecated See https://backstage.io/docs/api/deprecations#generic-auth-api-refs
*/
export const samlAuthApiRef: ApiRef<
ProfileInfoApi & BackstageIdentityApi & SessionApi
> = createApiRef({
id: 'core.auth.saml',
});
/**
* Provides authentication towards OneLogin APIs.
*
@@ -21,16 +21,13 @@ import {
ErrorAlerter,
GoogleAuth,
GithubAuth,
OAuth2,
OktaAuth,
GitlabAuth,
Auth0Auth,
MicrosoftAuth,
BitbucketAuth,
OAuthRequestManager,
WebStorage,
UrlPatternDiscovery,
SamlAuth,
OneLoginAuth,
UnhandledErrorForwarder,
AtlassianAuth,
@@ -45,16 +42,12 @@ import {
oauthRequestApiRef,
googleAuthApiRef,
githubAuthApiRef,
oauth2ApiRef,
oktaAuthApiRef,
gitlabAuthApiRef,
auth0AuthApiRef,
microsoftAuthApiRef,
storageApiRef,
configApiRef,
samlAuthApiRef,
oneloginAuthApiRef,
oidcAuthApiRef,
bitbucketAuthApiRef,
atlassianAuthApiRef,
} from '@backstage/core-plugin-api';
@@ -158,46 +151,6 @@ export const defaultApis = [
environment: configApi.getOptionalString('auth.environment'),
}),
}),
createApiFactory({
api: auth0AuthApiRef,
deps: {
discoveryApi: discoveryApiRef,
oauthRequestApi: oauthRequestApiRef,
configApi: configApiRef,
},
factory: ({ discoveryApi, oauthRequestApi, configApi }) =>
Auth0Auth.create({
discoveryApi,
oauthRequestApi,
environment: configApi.getOptionalString('auth.environment'),
}),
}),
createApiFactory({
api: oauth2ApiRef,
deps: {
discoveryApi: discoveryApiRef,
oauthRequestApi: oauthRequestApiRef,
configApi: configApiRef,
},
factory: ({ discoveryApi, oauthRequestApi, configApi }) =>
OAuth2.create({
discoveryApi,
oauthRequestApi,
environment: configApi.getOptionalString('auth.environment'),
}),
}),
createApiFactory({
api: samlAuthApiRef,
deps: {
discoveryApi: discoveryApiRef,
configApi: configApiRef,
},
factory: ({ discoveryApi, configApi }) =>
SamlAuth.create({
discoveryApi,
environment: configApi.getOptionalString('auth.environment'),
}),
}),
createApiFactory({
api: oneloginAuthApiRef,
deps: {
@@ -212,25 +165,6 @@ export const defaultApis = [
environment: configApi.getOptionalString('auth.environment'),
}),
}),
createApiFactory({
api: oidcAuthApiRef,
deps: {
discoveryApi: discoveryApiRef,
oauthRequestApi: oauthRequestApiRef,
configApi: configApiRef,
},
factory: ({ discoveryApi, oauthRequestApi, configApi }) =>
OAuth2.create({
discoveryApi,
oauthRequestApi,
provider: {
id: 'oidc',
title: 'Your Identity Provider',
icon: () => null,
},
environment: configApi.getOptionalString('auth.environment'),
}),
}),
createApiFactory({
api: bitbucketAuthApiRef,
deps: {
@@ -17,11 +17,9 @@ import Star from '@material-ui/icons/Star';
import React from 'react';
import { ProviderSettingsItem } from './ProviderSettingsItem';
import {
auth0AuthApiRef,
githubAuthApiRef,
gitlabAuthApiRef,
googleAuthApiRef,
oauth2ApiRef,
oktaAuthApiRef,
microsoftAuthApiRef,
bitbucketAuthApiRef,
@@ -66,14 +64,6 @@ export const DefaultProviderSettings = ({ configuredProviders }: Props) => (
icon={Star}
/>
)}
{configuredProviders.includes('auth0') && (
<ProviderSettingsItem
title="Auth0"
description="Provides authentication towards Auth0 APIs"
apiRef={auth0AuthApiRef}
icon={Star}
/>
)}
{configuredProviders.includes('okta') && (
<ProviderSettingsItem
title="Okta"
@@ -98,13 +88,5 @@ export const DefaultProviderSettings = ({ configuredProviders }: Props) => (
icon={Star}
/>
)}
{configuredProviders.includes('oauth2') && (
<ProviderSettingsItem
title="YourOrg"
description="Example of how to use oauth2 custom provider"
apiRef={oauth2ApiRef}
icon={Star}
/>
)}
</>
);
-16
View File
@@ -5,10 +5,8 @@ import {
GithubAuth,
GitlabAuth,
GoogleAuth,
OAuth2,
OAuthRequestManager,
OktaAuth,
Auth0Auth,
ConfigReader,
LocalStorageFeatureFlags,
} from '@backstage/core-app-api';
@@ -20,10 +18,8 @@ import {
gitlabAuthApiRef,
googleAuthApiRef,
identityApiRef,
oauth2ApiRef,
oauthRequestApiRef,
oktaAuthApiRef,
auth0AuthApiRef,
configApiRef,
featureFlagsApiRef,
} from '@backstage/core-plugin-api';
@@ -59,16 +55,6 @@ const oktaAuthApi = OktaAuth.create({
basePath: '/auth/',
oauthRequestApi,
});
const auth0AuthApi = Auth0Auth.create({
apiOrigin: 'http://localhost:7007',
basePath: '/auth/',
oauthRequestApi,
});
const oauth2Api = OAuth2.create({
apiOrigin: 'http://localhost:7007',
basePath: '/auth/',
oauthRequestApi,
});
export const apis = [
[configApiRef, configApi],
@@ -81,6 +67,4 @@ export const apis = [
[githubAuthApiRef, githubAuthApi],
[gitlabAuthApiRef, gitlabAuthApi],
[oktaAuthApiRef, oktaAuthApi],
[auth0AuthApiRef, auth0AuthApi],
[oauth2ApiRef, oauth2Api],
];