From b5bd9f2bcee0a7bb0c20b3588cfef540e1bd19ff Mon Sep 17 00:00:00 2001 From: Renjie Xu Date: Tue, 3 May 2022 14:51:23 -0700 Subject: [PATCH 1/4] Update getting-started docs to provide sign in resolver Signed-off-by: Renjie Xu --- docs/getting-started/configuration.md | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/docs/getting-started/configuration.md b/docs/getting-started/configuration.md index fc78217fbc..cf845c8d4c 100644 --- a/docs/getting-started/configuration.md +++ b/docs/getting-started/configuration.md @@ -187,6 +187,56 @@ components: { }, ``` +Since [v1.1.0](https://github.com/backstage/backstage/releases/tag/v1.1.0-next.3), you must provide an explicit sign-in resolver. + +Open `packages/backend/src/plugins/auth.ts` and replace with following code snippet: + +```typescript +import { + createRouter, + providers, + defaultAuthProviderFactories, +} from '@backstage/plugin-auth-backend'; +import { Router } from 'express'; +import { PluginEnvironment } from '../types'; +import { stringifyEntityRef } from '@backstage/catalog-model'; + +export default async function createPlugin( + env: PluginEnvironment, +): Promise { + return await createRouter({ + ...env, + providerFactories: { + ...defaultAuthProviderFactories, + github: providers.github.create({ + signIn: { + resolver: async ({ profile }, ctx) => { + if (!profile.email) { + throw new Error( + 'Login failed, user profile does not contain an email', + ); + } + const [localPart] = profile.email.split('@'); + + const userEntityRef = stringifyEntityRef({ + kind: 'User', + name: localPart, + namespace: 'DEFAULT_NAMESPACE', + }); + return ctx.issueToken({ + claims: { + sub: userEntityRef, + ent: [userEntityRef], + }, + }); + }, + }, + }), + }, + }); +} +``` + That should be it. You can stop your Backstage App. When you start it again and go to your Backstage portal in your browser, you should have your login prompt! From fe3ac2f6bbfcc3da8781ce9562efd44cabde7a78 Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 30 May 2022 11:50:34 +0200 Subject: [PATCH 2/4] chore: reworking the initial work to link out to the sign in reolver Signed-off-by: blam --- docs/getting-started/configuration.md | 50 +-------------------------- 1 file changed, 1 insertion(+), 49 deletions(-) diff --git a/docs/getting-started/configuration.md b/docs/getting-started/configuration.md index cf845c8d4c..0660497276 100644 --- a/docs/getting-started/configuration.md +++ b/docs/getting-started/configuration.md @@ -187,55 +187,7 @@ components: { }, ``` -Since [v1.1.0](https://github.com/backstage/backstage/releases/tag/v1.1.0-next.3), you must provide an explicit sign-in resolver. - -Open `packages/backend/src/plugins/auth.ts` and replace with following code snippet: - -```typescript -import { - createRouter, - providers, - defaultAuthProviderFactories, -} from '@backstage/plugin-auth-backend'; -import { Router } from 'express'; -import { PluginEnvironment } from '../types'; -import { stringifyEntityRef } from '@backstage/catalog-model'; - -export default async function createPlugin( - env: PluginEnvironment, -): Promise { - return await createRouter({ - ...env, - providerFactories: { - ...defaultAuthProviderFactories, - github: providers.github.create({ - signIn: { - resolver: async ({ profile }, ctx) => { - if (!profile.email) { - throw new Error( - 'Login failed, user profile does not contain an email', - ); - } - const [localPart] = profile.email.split('@'); - - const userEntityRef = stringifyEntityRef({ - kind: 'User', - name: localPart, - namespace: 'DEFAULT_NAMESPACE', - }); - return ctx.issueToken({ - claims: { - sub: userEntityRef, - ent: [userEntityRef], - }, - }); - }, - }, - }), - }, - }); -} -``` +> Since [v1.1.0](https://github.com/backstage/backstage/releases/tag/v1.1.0-next.3), you must provide an [explicit sign-in resolver](https://backstage.io/docs/auth/identity-resolver). That should be it. You can stop your Backstage App. When you start it again and go to your Backstage portal in your browser, you should have your login prompt! From 9e2fb90151d1ef2dee06f4292facfdabec442e33 Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 30 May 2022 11:51:16 +0200 Subject: [PATCH 3/4] chore: fixing up the link Signed-off-by: blam --- docs/getting-started/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started/configuration.md b/docs/getting-started/configuration.md index 0660497276..8de584f1e9 100644 --- a/docs/getting-started/configuration.md +++ b/docs/getting-started/configuration.md @@ -187,7 +187,7 @@ components: { }, ``` -> Since [v1.1.0](https://github.com/backstage/backstage/releases/tag/v1.1.0-next.3), you must provide an [explicit sign-in resolver](https://backstage.io/docs/auth/identity-resolver). +> Since [v1.1.0](https://github.com/backstage/backstage/releases/tag/v1.1.0-next.3), you must provide an [explicit sign-in resolver](../auth/identity-resolver). That should be it. You can stop your Backstage App. When you start it again and go to your Backstage portal in your browser, you should have your login prompt! From b10bf25802240a2d6a823d173573620293a7ba0e Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 30 May 2022 12:01:00 +0200 Subject: [PATCH 4/4] chore: woops Signed-off-by: blam --- docs/getting-started/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started/configuration.md b/docs/getting-started/configuration.md index 8de584f1e9..1dc1ffc1b1 100644 --- a/docs/getting-started/configuration.md +++ b/docs/getting-started/configuration.md @@ -187,7 +187,7 @@ components: { }, ``` -> Since [v1.1.0](https://github.com/backstage/backstage/releases/tag/v1.1.0-next.3), you must provide an [explicit sign-in resolver](../auth/identity-resolver). +> Since [v1.1.0](https://github.com/backstage/backstage/releases/tag/v1.1.0-next.3), you must provide an [explicit sign-in resolver](../auth/identity-resolver.md). That should be it. You can stop your Backstage App. When you start it again and go to your Backstage portal in your browser, you should have your login prompt!