auth-backend: migrate github sign-in resolver
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -14,8 +14,5 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {
|
||||
createGithubProvider,
|
||||
githubUsernameEntityNameSignInResolver,
|
||||
} from './provider';
|
||||
export { createGithubProvider } from './provider';
|
||||
export type { GithubOAuthResult, GithubProviderOptions } from './provider';
|
||||
|
||||
@@ -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),
|
||||
}),
|
||||
|
||||
@@ -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<GithubOAuthResult> => {
|
||||
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 } });
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user