From 8d9f6731069f95fff6433f12b3c184f349a5ab34 Mon Sep 17 00:00:00 2001 From: Patrick Jungermann Date: Tue, 19 Apr 2022 19:14:50 +0200 Subject: [PATCH] feat: add annotation `microsoft.com/email` when using the `defaultUserTransformer`. This will allow users of the Microsoft auth provider to utilize the predefined SignIn resolver instead of maintaining their own. Signed-off-by: Patrick Jungermann --- .changeset/giant-cheetahs-thank.md | 30 +++++++++++++++++++ .../api-report.md | 3 ++ .../src/microsoftGraph/constants.ts | 7 +++++ .../src/microsoftGraph/index.ts | 1 + .../src/microsoftGraph/read.test.ts | 4 +++ .../src/microsoftGraph/read.ts | 2 ++ 6 files changed, 47 insertions(+) create mode 100644 .changeset/giant-cheetahs-thank.md diff --git a/.changeset/giant-cheetahs-thank.md b/.changeset/giant-cheetahs-thank.md new file mode 100644 index 0000000000..a135fbc4a3 --- /dev/null +++ b/.changeset/giant-cheetahs-thank.md @@ -0,0 +1,30 @@ +--- +'@backstage/plugin-catalog-backend-module-msgraph': patch +--- + +Add annotation `microsoft.com/email` when using the `defaultUserTransformer`. + +This will allow users of the Microsoft auth provider to utilize the predefined +SignIn resolver instead of maintaining their own. + +```typescript +// backend/plugins/auth.ts + +// [...] + +export default async function createPlugin( + env: PluginEnvironment, +): Promise { + return await createRouter({ + // [...] + providerFactories: { + microsoft: providers.microsoft.create({ + signIn: { + resolver: + providers.microsoft.resolvers.emailMatchingUserEntityAnnotation(), + }, + }), + }, + }); +} +``` diff --git a/plugins/catalog-backend-module-msgraph/api-report.md b/plugins/catalog-backend-module-msgraph/api-report.md index 2239ec1332..31a22b0bc4 100644 --- a/plugins/catalog-backend-module-msgraph/api-report.md +++ b/plugins/catalog-backend-module-msgraph/api-report.md @@ -49,6 +49,9 @@ export type GroupTransformer = ( groupPhoto?: string, ) => Promise; +// @public +export const MICROSOFT_EMAIL_ANNOTATION = 'microsoft.com/email'; + // @public export const MICROSOFT_GRAPH_GROUP_ID_ANNOTATION = 'graph.microsoft.com/group-id'; diff --git a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/constants.ts b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/constants.ts index bbfbd61efe..dc8ac6ef62 100644 --- a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/constants.ts +++ b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/constants.ts @@ -14,6 +14,13 @@ * limitations under the License. */ +/** + * The (primary) user email. Also used by the Microsoft auth provider to resolve the User entity. + * + * @public + */ +export const MICROSOFT_EMAIL_ANNOTATION = 'microsoft.com/email'; + /** * The tenant id used by the Microsoft Graph API * diff --git a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/index.ts b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/index.ts index 61e62f5803..e9ab49f7d1 100644 --- a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/index.ts +++ b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/index.ts @@ -19,6 +19,7 @@ export type { GroupMember, ODataQuery } from './client'; export { readMicrosoftGraphConfig } from './config'; export type { MicrosoftGraphProviderConfig } from './config'; export { + MICROSOFT_EMAIL_ANNOTATION, MICROSOFT_GRAPH_GROUP_ID_ANNOTATION, MICROSOFT_GRAPH_TENANT_ID_ANNOTATION, MICROSOFT_GRAPH_USER_ID_ANNOTATION, diff --git a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.test.ts b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.test.ts index 1fc4904b74..caef1701f6 100644 --- a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.test.ts +++ b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.test.ts @@ -96,6 +96,7 @@ describe('read microsoft graph', () => { metadata: { annotations: { 'graph.microsoft.com/user-id': 'userid', + 'microsoft.com/email': 'user.name@example.com', }, name: 'user.name_example.com', }, @@ -146,6 +147,7 @@ describe('read microsoft graph', () => { metadata: { annotations: { 'graph.microsoft.com/user-id': 'userid', + 'microsoft.com/email': 'user.name@example.com', }, name: 'user.name_example.com', }, @@ -263,6 +265,7 @@ describe('read microsoft graph', () => { metadata: { annotations: { 'graph.microsoft.com/user-id': 'userid', + 'microsoft.com/email': 'user.name@example.com', }, name: 'user.name_example.com', }, @@ -339,6 +342,7 @@ describe('read microsoft graph', () => { metadata: { annotations: { 'graph.microsoft.com/user-id': 'userid', + 'microsoft.com/email': 'user.name@example.com', }, name: 'user.name_example.com', }, diff --git a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.ts b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.ts index de7f3e49e0..ecf74b34d9 100644 --- a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.ts +++ b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.ts @@ -24,6 +24,7 @@ import limiterFactory from 'p-limit'; import { Logger } from 'winston'; import { MicrosoftGraphClient } from './client'; import { + MICROSOFT_EMAIL_ANNOTATION, MICROSOFT_GRAPH_GROUP_ID_ANNOTATION, MICROSOFT_GRAPH_TENANT_ID_ANNOTATION, MICROSOFT_GRAPH_USER_ID_ANNOTATION, @@ -57,6 +58,7 @@ export async function defaultUserTransformer( metadata: { name, annotations: { + [MICROSOFT_EMAIL_ANNOTATION]: user.mail!, [MICROSOFT_GRAPH_USER_ID_ANNOTATION]: user.id!, }, },