From ad7bfe6810e09857c376ca071df41627f5a5a071 Mon Sep 17 00:00:00 2001 From: Filip Swiatczak Date: Fri, 1 Oct 2021 17:05:48 +0100 Subject: [PATCH] dropped display name Resolver, uuid -> user-id Signed-off-by: Filip Swiatczak --- plugins/auth-backend/api-report.md | 21 +++++-------- .../src/providers/bitbucket/index.ts | 3 +- .../src/providers/bitbucket/provider.ts | 30 ++++--------------- 3 files changed, 14 insertions(+), 40 deletions(-) diff --git a/plugins/auth-backend/api-report.md b/plugins/auth-backend/api-report.md index 8a0d0a8823..3834388db9 100644 --- a/plugins/auth-backend/api-report.md +++ b/plugins/auth-backend/api-report.md @@ -84,12 +84,6 @@ export type BackstageIdentity = { entity?: Entity; }; -// Warning: (ae-forgotten-export) The symbol "SignInResolver" needs to be exported by the entry point index.d.ts -// Warning: (ae-missing-release-tag) "bitbucketDisplayNameSignInResolver" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export const bitbucketDisplayNameSignInResolver: SignInResolver; - // Warning: (ae-missing-release-tag) "BitbucketOAuthResult" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -108,11 +102,11 @@ export type BitbucketOAuthResult = { // // @public (undocumented) export type BitbucketPassportProfile = Profile & { + id?: string; displayName?: string; username?: string; avatarUrl?: string; _json?: { - uuid?: string; links?: { avatar?: { href?: string; @@ -131,16 +125,16 @@ export type BitbucketProviderOptions = { }; }; +// Warning: (ae-missing-release-tag) "bitbucketUserIdSignInResolver" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export const bitbucketUserIdSignInResolver: SignInResolver; + // Warning: (ae-missing-release-tag) "bitbucketUsernameSignInResolver" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) export const bitbucketUsernameSignInResolver: SignInResolver; -// Warning: (ae-missing-release-tag) "bitbucketUuidSignInResolver" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export const bitbucketUuidSignInResolver: SignInResolver; - // Warning: (ae-missing-release-tag) "createBitbucketProvider" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -532,7 +526,8 @@ export type WebMessageResponse = // // src/identity/types.d.ts:25:5 - (ae-forgotten-export) The symbol "TokenParams" needs to be exported by the entry point index.d.ts // src/identity/types.d.ts:31:9 - (ae-forgotten-export) The symbol "AnyJWK" needs to be exported by the entry point index.d.ts -// src/providers/bitbucket/provider.d.ts:62:5 - (ae-forgotten-export) The symbol "AuthHandler" needs to be exported by the entry point index.d.ts +// src/providers/bitbucket/provider.d.ts:61:5 - (ae-forgotten-export) The symbol "AuthHandler" needs to be exported by the entry point index.d.ts +// src/providers/bitbucket/provider.d.ts:69:9 - (ae-forgotten-export) The symbol "SignInResolver" needs to be exported by the entry point index.d.ts // src/providers/types.d.ts:109:5 - (ae-forgotten-export) The symbol "AuthProviderConfig" needs to be exported by the entry point index.d.ts // src/providers/types.d.ts:115:5 - (ae-forgotten-export) The symbol "ExperimentalIdentityResolver" needs to be exported by the entry point index.d.ts // src/providers/types.d.ts:132:8 - (tsdoc-missing-deprecation-message) The @deprecated block must include a deprecation message, e.g. describing the recommended alternative diff --git a/plugins/auth-backend/src/providers/bitbucket/index.ts b/plugins/auth-backend/src/providers/bitbucket/index.ts index 288c2e0ab1..55a5735655 100644 --- a/plugins/auth-backend/src/providers/bitbucket/index.ts +++ b/plugins/auth-backend/src/providers/bitbucket/index.ts @@ -17,8 +17,7 @@ export { createBitbucketProvider, bitbucketUsernameSignInResolver, - bitbucketUuidSignInResolver, - bitbucketDisplayNameSignInResolver, + bitbucketUserIdSignInResolver, } from './provider'; export type { BitbucketProviderOptions, diff --git a/plugins/auth-backend/src/providers/bitbucket/provider.ts b/plugins/auth-backend/src/providers/bitbucket/provider.ts index e5b63ad3e3..352e0fc116 100644 --- a/plugins/auth-backend/src/providers/bitbucket/provider.ts +++ b/plugins/auth-backend/src/providers/bitbucket/provider.ts @@ -70,11 +70,11 @@ export type BitbucketOAuthResult = { }; export type BitbucketPassportProfile = PassportProfile & { + id?: string; displayName?: string; username?: string; avatarUrl?: string; _json?: { - uuid?: string; links?: { avatar?: { href?: string; @@ -223,37 +223,17 @@ export const bitbucketUsernameSignInResolver: SignInResolver = +export const bitbucketUserIdSignInResolver: SignInResolver = async (info, ctx) => { const { result } = info; - if (!result.fullProfile.displayName) { - throw new Error('Bitbucket profile contained no display name'); + if (!result.fullProfile.id) { + throw new Error('Bitbucket profile contained no User ID'); } const entity = await ctx.catalogIdentityClient.findUser({ annotations: { - 'bitbucket.org/displayName': result.fullProfile.displayName, - }, - }); - - const claims = getEntityClaims(entity); - const token = await ctx.tokenIssuer.issueToken({ claims }); - - return { id: entity.metadata.name, entity, token }; - }; - -export const bitbucketUuidSignInResolver: SignInResolver = - async (info, ctx) => { - const { result } = info; - - if (!result.fullProfile?._json?.uuid) { - throw new Error('Bitbucket profile contained no UUID'); - } - - const entity = await ctx.catalogIdentityClient.findUser({ - annotations: { - 'bitbucket.org/uuid': result.fullProfile._json?.uuid, + 'bitbucket.org/user-id': result.fullProfile.id, }, });