Skip to content

Instantly share code, notes, and snippets.

@larkintuckerllc
Created February 19, 2022 11:25
Show Gist options
  • Save larkintuckerllc/eedbd5b1f1b572f71e34440b3e3a4a1c to your computer and use it in GitHub Desktop.
Save larkintuckerllc/eedbd5b1f1b572f71e34440b3e3a4a1c to your computer and use it in GitHub Desktop.
import { createRouter, createGithubProvider } from '@backstage/plugin-auth-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
export default async function createPlugin({
logger,
database,
config,
discovery,
tokenManager,
}: PluginEnvironment): Promise<Router> {
return await createRouter({
logger,
config,
database,
discovery,
tokenManager,
providerFactories: {
github: createGithubProvider({
authHandler: async ({
fullProfile: {
displayName,
photos,
username,
},
}, ctx) => {
if (username === undefined) {
throw new Error();
}
await ctx.catalogIdentityClient.findUser({
annotations: {
'github.com/user-login': username,
},
});
let picture:string|undefined;
if (photos !== undefined && photos[0] !== undefined) {
picture = photos[0].value;
}
return {
profile: {
picture,
displayName,
}
};
},
}),
},
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment