backend: mock custom google auth provider

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-02-15 12:43:41 +01:00
committed by Fredrik Adelöw
parent 1111c0753c
commit 11e3e0fc24
+29 -2
View File
@@ -14,7 +14,11 @@
* limitations under the License.
*/
import { createRouter } from '@backstage/plugin-auth-backend';
import {
createGoogleProvider,
createRouter,
defaultAuthProviderFactories,
} from '@backstage/plugin-auth-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
@@ -24,5 +28,28 @@ export default async function createPlugin({
config,
discovery,
}: PluginEnvironment): Promise<Router> {
return await createRouter({ logger, config, database, discovery });
return await createRouter({
logger,
config,
database,
discovery,
providerFactories: {
...defaultAuthProviderFactories,
google: createGoogleProvider({
signIn: {
// resolver: 'email',
resolver: async ({ profile: { email } }, ctx) => {
if (!email) {
throw new Error('No email associated with user account');
}
const id = email.split('@')[0];
const token = await ctx.tokenIssuer.issueToken({
claims: { sub: id, ent: [id] },
});
return { id, token };
},
},
}),
},
});
}