refactor: apply review suggestions
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
@@ -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<PassportProfile>,
|
||||
unknown
|
||||
>;
|
||||
}
|
||||
|
||||
@@ -23,4 +23,3 @@
|
||||
export { bitbucketServerAuthenticator } from './authenticator';
|
||||
export { authModuleBitbucketServerProvider as default } from './module';
|
||||
export { bitbucketServerSignInResolvers } from './resolvers';
|
||||
export { type BitbucketServerOAuthResult } from './types';
|
||||
|
||||
@@ -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<BitbucketServerOAuthResult>, ctx) => {
|
||||
return async (
|
||||
info: SignInInfo<OAuthAuthenticatorResult<PassportProfile>>,
|
||||
ctx,
|
||||
) => {
|
||||
const { profile } = info;
|
||||
|
||||
if (!profile.email) {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
@@ -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<bitbucketServerSignInResolvers>;
|
||||
resolvers: Readonly<{
|
||||
emailMatchingUserEntityProfileEmail: () => SignInResolver_2<BitbucketServerOAuthResult>;
|
||||
}>;
|
||||
}>;
|
||||
cfAccess: Readonly<{
|
||||
create: (options: {
|
||||
|
||||
@@ -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<BitbucketServerOAuthResult> => {
|
||||
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,
|
||||
);
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user