diff --git a/plugins/auth-backend/src/providers/github/index.ts b/plugins/auth-backend/src/providers/github/index.ts index 3b0c605f0e..a855b13b83 100644 --- a/plugins/auth-backend/src/providers/github/index.ts +++ b/plugins/auth-backend/src/providers/github/index.ts @@ -14,8 +14,5 @@ * limitations under the License. */ -export { - createGithubProvider, - githubUsernameEntityNameSignInResolver, -} from './provider'; +export { createGithubProvider } from './provider'; export type { GithubOAuthResult, GithubProviderOptions } from './provider'; diff --git a/plugins/auth-backend/src/providers/github/provider.test.ts b/plugins/auth-backend/src/providers/github/provider.test.ts index e425cef0ff..5cd605dcfe 100644 --- a/plugins/auth-backend/src/providers/github/provider.test.ts +++ b/plugins/auth-backend/src/providers/github/provider.test.ts @@ -15,11 +15,7 @@ */ import { Profile as PassportProfile } from 'passport'; -import { - GithubAuthProvider, - GithubOAuthResult, - githubUsernameEntityNameSignInResolver, -} from './provider'; +import { GithubAuthProvider, GithubOAuthResult, github } from './provider'; import * as helpers from '../../lib/passport/PassportStrategyHelper'; import { makeProfileInfo } from '../../lib/passport/PassportStrategyHelper'; import { OAuthStartRequest, encodeState } from '../../lib/oauth'; @@ -42,7 +38,7 @@ describe('GithubAuthProvider', () => { token: `token-for-user:${entityRef.name}`, })), } as unknown as AuthResolverContext, - signInResolver: githubUsernameEntityNameSignInResolver, + signInResolver: github.resolvers.byUsername(), authHandler: async ({ fullProfile }) => ({ profile: makeProfileInfo(fullProfile), }), diff --git a/plugins/auth-backend/src/providers/github/provider.ts b/plugins/auth-backend/src/providers/github/provider.ts index d84c89261f..5f095ea414 100644 --- a/plugins/auth-backend/src/providers/github/provider.ts +++ b/plugins/auth-backend/src/providers/github/provider.ts @@ -227,19 +227,6 @@ export class GithubAuthProvider implements OAuthHandlers { } } -export const githubUsernameEntityNameSignInResolver: SignInResolver< - GithubOAuthResult -> = async (info, ctx) => { - const { fullProfile } = info.result; - - const userId = fullProfile.username; - if (!userId) { - throw new Error(`GitHub user profile does not contain a username`); - } - - return ctx.signInWithCatalogUser({ entityRef: { name: userId } }); -}; - /** * @deprecated This type has been inlined into the create method and will be removed. */ @@ -375,6 +362,23 @@ export const github = createAuthProviderIntegration({ }); }); }, + resolvers: { + /** + * Looks up the user by matching their GitHub username to the entity name. + */ + byUsername: (): SignInResolver => { + return async (info, ctx) => { + const { fullProfile } = info.result; + + const userId = fullProfile.username; + if (!userId) { + throw new Error(`GitHub user profile does not contain a username`); + } + + return ctx.signInWithCatalogUser({ entityRef: { name: userId } }); + }; + }, + }, }); /**