processed review comments. Ran prettier, api-report, minor to patch

Signed-off-by: Pepijn Schildkamp <pepijn.schildkamp@gmail.com>
This commit is contained in:
Pepijn Schildkamp
2021-08-31 16:41:29 +02:00
parent 159e107ab3
commit 723df8e8ce
5 changed files with 25 additions and 29 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
---
'@backstage/plugin-auth-backend': minor
'@backstage/plugin-auth-backend': patch
---
Added signIn and authHandler resolver for oAuth2 provider
+17
View File
@@ -105,6 +105,13 @@ export const createMicrosoftProvider: (
options?: MicrosoftProviderOptions | undefined,
) => AuthProviderFactory;
// Warning: (ae-missing-release-tag) "createOAuth2Provider" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const createOAuth2Provider: (
options?: OAuth2ProviderOptions | undefined,
) => AuthProviderFactory;
// Warning: (ae-missing-release-tag) "createOktaProvider" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
@@ -199,6 +206,16 @@ export type MicrosoftProviderOptions = {
};
};
// Warning: (ae-missing-release-tag) "OAuth2ProviderOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export type OAuth2ProviderOptions = {
authHandler?: AuthHandler<OAuthResult>;
signIn?: {
resolver?: SignInResolver<OAuthResult>;
};
};
// Warning: (ae-missing-release-tag) "OAuthAdapter" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
@@ -14,5 +14,5 @@
* limitations under the License.
*/
export { createOAuth2Provider, oAuth2EmailSignInResolver } from './provider';
export { createOAuth2Provider } from './provider';
export type { OAuth2ProviderOptions } from './provider';
@@ -21,10 +21,10 @@ import { getVoidLogger } from '@backstage/backend-common';
import { TokenIssuer } from '../../identity/types';
import { CatalogIdentityClient } from '../../lib/catalog';
const mockFrameHandler = (jest.spyOn(
const mockFrameHandler = jest.spyOn(
helpers,
'executeFrameHandlerStrategy',
) as unknown) as jest.MockedFunction<
) as unknown as jest.MockedFunction<
() => Promise<{ result: OAuthResult; privateInfo: any }>
>;
@@ -40,8 +40,9 @@ describe('createOAuth2Provider', () => {
const provider = new OAuth2AuthProvider({
logger: getVoidLogger(),
catalogIdentityClient: (catalogIdentityClient as unknown) as CatalogIdentityClient,
tokenIssuer: (tokenIssuer as unknown) as TokenIssuer,
catalogIdentityClient:
catalogIdentityClient as unknown as CatalogIdentityClient,
tokenIssuer: tokenIssuer as unknown as TokenIssuer,
authHandler: async ({ fullProfile }) => ({
profile: {
email: fullProfile.emails![0]!.value,
@@ -42,7 +42,7 @@ import {
RedirectInfo,
SignInResolver,
} from '../types';
import { CatalogIdentityClient, getEntityClaims } from '../../lib/catalog';
import { CatalogIdentityClient } from '../../lib/catalog';
import { TokenIssuer } from '../../identity';
import { Logger } from 'winston';
@@ -188,28 +188,6 @@ export class OAuth2AuthProvider implements OAuthHandlers {
}
}
export const oAuth2EmailSignInResolver: SignInResolver<OAuthResult> = async (
info,
ctx,
) => {
const { profile } = info;
if (!profile.email) {
throw new Error('OAuth2 profile contained no email');
}
const entity = await ctx.catalogIdentityClient.findUser({
annotations: {
'backstage.io/email': profile.email,
},
});
const claims = getEntityClaims(entity);
const token = await ctx.tokenIssuer.issueToken({ claims });
return { id: entity.metadata.name, entity, token };
};
export const oAuth2DefaultSignInResolver: SignInResolver<OAuthResult> = async (
info,
ctx,