From 7ee6d388414b1f1351fec885dcfc2540d9ff7a62 Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Mon, 9 Sep 2024 15:14:45 +0200 Subject: [PATCH] refactor: apply review suggestions Signed-off-by: Camila Belo --- .../api-report.md | 16 +------- .../src/index.ts | 1 - .../src/resolvers.ts | 8 +++- .../src/types.ts | 32 --------------- plugins/auth-backend/api-report.md | 5 ++- .../src/providers/bitbucketServer/provider.ts | 29 +++++++++++++- yarn.lock | 40 +++++++++++++++++++ 7 files changed, 79 insertions(+), 52 deletions(-) delete mode 100644 plugins/auth-backend-module-bitbucket-server-provider/src/types.ts diff --git a/plugins/auth-backend-module-bitbucket-server-provider/api-report.md b/plugins/auth-backend-module-bitbucket-server-provider/api-report.md index 83fbf54064..d5c484f6e3 100644 --- a/plugins/auth-backend-module-bitbucket-server-provider/api-report.md +++ b/plugins/auth-backend-module-bitbucket-server-provider/api-report.md @@ -5,6 +5,7 @@ ```ts import { BackendFeature } from '@backstage/backend-plugin-api'; import { OAuthAuthenticator } from '@backstage/plugin-auth-node'; +import { OAuthAuthenticatorResult } from '@backstage/plugin-auth-node'; import { PassportOAuthAuthenticatorHelper } from '@backstage/plugin-auth-node'; import { PassportProfile } from '@backstage/plugin-auth-node'; import { SignInResolverFactory } from '@backstage/plugin-auth-node'; @@ -22,23 +23,10 @@ export const bitbucketServerAuthenticator: OAuthAuthenticator< PassportProfile >; -// @public (undocumented) -export type BitbucketServerOAuthResult = { - fullProfile: PassportProfile; - params: { - scope: string; - access_token?: string; - token_type?: string; - expires_in?: number; - }; - accessToken: string; - refreshToken?: string; -}; - // @public export namespace bitbucketServerSignInResolvers { const emailMatchingUserEntityProfileEmail: SignInResolverFactory< - BitbucketServerOAuthResult, + OAuthAuthenticatorResult, unknown >; } diff --git a/plugins/auth-backend-module-bitbucket-server-provider/src/index.ts b/plugins/auth-backend-module-bitbucket-server-provider/src/index.ts index 06d6e778ba..0d32abfe22 100644 --- a/plugins/auth-backend-module-bitbucket-server-provider/src/index.ts +++ b/plugins/auth-backend-module-bitbucket-server-provider/src/index.ts @@ -23,4 +23,3 @@ export { bitbucketServerAuthenticator } from './authenticator'; export { authModuleBitbucketServerProvider as default } from './module'; export { bitbucketServerSignInResolvers } from './resolvers'; -export { type BitbucketServerOAuthResult } from './types'; diff --git a/plugins/auth-backend-module-bitbucket-server-provider/src/resolvers.ts b/plugins/auth-backend-module-bitbucket-server-provider/src/resolvers.ts index 04595531ea..dc2ceef7e9 100644 --- a/plugins/auth-backend-module-bitbucket-server-provider/src/resolvers.ts +++ b/plugins/auth-backend-module-bitbucket-server-provider/src/resolvers.ts @@ -15,9 +15,10 @@ */ import { createSignInResolverFactory, + OAuthAuthenticatorResult, + PassportProfile, SignInInfo, } from '@backstage/plugin-auth-node'; -import { BitbucketServerOAuthResult } from './types'; /** * Available sign-in resolvers for the Bitbucket Server auth provider. @@ -31,7 +32,10 @@ export namespace bitbucketServerSignInResolvers { export const emailMatchingUserEntityProfileEmail = createSignInResolverFactory({ create() { - return async (info: SignInInfo, ctx) => { + return async ( + info: SignInInfo>, + ctx, + ) => { const { profile } = info; if (!profile.email) { diff --git a/plugins/auth-backend-module-bitbucket-server-provider/src/types.ts b/plugins/auth-backend-module-bitbucket-server-provider/src/types.ts deleted file mode 100644 index e88dfdbf5b..0000000000 --- a/plugins/auth-backend-module-bitbucket-server-provider/src/types.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2024 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 { PassportProfile } from '@backstage/plugin-auth-node'; - -/** - * @public - */ -export type BitbucketServerOAuthResult = { - fullProfile: PassportProfile; - params: { - scope: string; - access_token?: string; - token_type?: string; - expires_in?: number; - }; - accessToken: string; - refreshToken?: string; -}; diff --git a/plugins/auth-backend/api-report.md b/plugins/auth-backend/api-report.md index 9c0d37bdba..20690528d1 100644 --- a/plugins/auth-backend/api-report.md +++ b/plugins/auth-backend/api-report.md @@ -14,7 +14,6 @@ import { AwsAlbResult as AwsAlbResult_2 } from '@backstage/plugin-auth-backend-m import { AzureEasyAuthResult } from '@backstage/plugin-auth-backend-module-azure-easyauth-provider'; import { BackendFeature } from '@backstage/backend-plugin-api'; import { BackstageSignInResult } from '@backstage/plugin-auth-node'; -import { bitbucketServerSignInResolvers } from '@backstage/plugin-auth-backend-module-bitbucket-server-provider'; import { CacheService } from '@backstage/backend-plugin-api'; import { CatalogApi } from '@backstage/catalog-client'; import { ClientAuthResponse } from '@backstage/plugin-auth-node'; @@ -443,7 +442,9 @@ export const providers: Readonly<{ } | undefined, ) => AuthProviderFactory_2; - resolvers: Readonly; + resolvers: Readonly<{ + emailMatchingUserEntityProfileEmail: () => SignInResolver_2; + }>; }>; cfAccess: Readonly<{ create: (options: { diff --git a/plugins/auth-backend/src/providers/bitbucketServer/provider.ts b/plugins/auth-backend/src/providers/bitbucketServer/provider.ts index b42b752e43..c49cf5b7b1 100644 --- a/plugins/auth-backend/src/providers/bitbucketServer/provider.ts +++ b/plugins/auth-backend/src/providers/bitbucketServer/provider.ts @@ -85,5 +85,32 @@ export const bitbucketServer = createAuthProviderIntegration({ signInResolver: adaptLegacyOAuthSignInResolver(options?.signIn?.resolver), }); }, - resolvers: bitbucketServerSignInResolvers, + resolvers: { + /** + * Looks up the user by matching their email to the entity email. + */ + emailMatchingUserEntityProfileEmail: + (): SignInResolver => { + const resolver = + bitbucketServerSignInResolvers.emailMatchingUserEntityProfileEmail(); + return async (info, ctx) => { + return resolver( + { + profile: info.profile, + result: { + fullProfile: info.result.fullProfile, + session: { + accessToken: info.result.accessToken, + tokenType: info.result.params.token_type ?? 'bearer', + scope: info.result.params.scope, + expiresInSeconds: info.result.params.expires_in, + refreshToken: info.result.refreshToken, + }, + }, + }, + ctx, + ); + }; + }, + }, }); diff --git a/yarn.lock b/yarn.lock index c6902501cd..aa5db912b9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -27240,6 +27240,18 @@ __metadata: languageName: node linkType: hard +"formidable@npm:^2.1.2": + version: 2.1.2 + resolution: "formidable@npm:2.1.2" + dependencies: + dezalgo: ^1.0.4 + hexoid: ^1.0.0 + once: ^1.4.0 + qs: ^6.11.0 + checksum: 81c8e5d89f5eb873e992893468f0de22c01678ca3d315db62be0560f9de1c77d4faefc9b1f4575098eb2263b3c81ba1024833a9fc3206297ddbac88a4f69b7a8 + languageName: node + linkType: hard + "formidable@npm:^3.5.1": version: 3.5.1 resolution: "formidable@npm:3.5.1" @@ -41158,6 +41170,24 @@ __metadata: languageName: node linkType: hard +"superagent@npm:^8.1.2": + version: 8.1.2 + resolution: "superagent@npm:8.1.2" + dependencies: + component-emitter: ^1.3.0 + cookiejar: ^2.1.4 + debug: ^4.3.4 + fast-safe-stringify: ^2.1.1 + form-data: ^4.0.0 + formidable: ^2.1.2 + methods: ^1.1.2 + mime: 2.6.0 + qs: ^6.11.0 + semver: ^7.3.8 + checksum: f3601c5ccae34d5ba684a03703394b5d25931f4ae2e1e31a1de809f88a9400e997ece037f9accf148a21c408f950dc829db1e4e23576a7f9fe0efa79fd5c9d2f + languageName: node + linkType: hard + "superagent@npm:^9.0.1": version: 9.0.2 resolution: "superagent@npm:9.0.2" @@ -41175,6 +41205,16 @@ __metadata: languageName: node linkType: hard +"supertest@npm:^6.3.3": + version: 6.3.4 + resolution: "supertest@npm:6.3.4" + dependencies: + methods: ^1.1.2 + superagent: ^8.1.2 + checksum: 875c6fa7940f21e5be9bb646579cdb030d4057bf2da643e125e1f0480add1200395d2b17e10b8e54e1009efc63e047422501e9eb30e12828668498c0910f295f + languageName: node + linkType: hard + "supertest@npm:^7.0.0": version: 7.0.0 resolution: "supertest@npm:7.0.0"