@backstage/plugin-auth-backend-module-github-provider 0.5.6 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @backstage/plugin-auth-backend-module-github-provider
2
2
 
3
+ ## 0.5.7
4
+
5
+ ### Patch Changes
6
+
7
+ - 211a61a: Deprecated the GitHub username sign-in resolver in favor of the stable user ID resolver. GitHub user ID catalog lookups now require an exact match and handle candidates that differ only by letter casing.
8
+ - Updated dependencies
9
+ - @backstage/catalog-model@1.10.1
10
+ - @backstage/plugin-auth-node@0.7.6
11
+ - @backstage/backend-plugin-api@1.10.1
12
+ - @backstage/plugin-catalog-node@2.2.5
13
+
14
+ ## 0.5.7-next.0
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies
19
+ - @backstage/plugin-auth-node@0.7.5-next.0
20
+ - @backstage/backend-plugin-api@1.10.1-next.0
21
+
3
22
  ## 0.5.6
4
23
 
5
24
  ### Patch Changes
@@ -51,7 +51,8 @@
51
51
  "properties": {
52
52
  "resolver": {
53
53
  "type": "string",
54
- "const": "usernameMatchingUserEntityName"
54
+ "const": "usernameMatchingUserEntityName",
55
+ "deprecated": "Use `userIdMatchingUserEntityAnnotation` instead."
55
56
  },
56
57
  "dangerouslyAllowSignInWithoutUserInCatalog": {
57
58
  "type": "boolean"
package/dist/index.d.ts CHANGED
@@ -20,6 +20,9 @@ declare const authModuleGithubProvider: _backstage_backend_plugin_api.BackendFea
20
20
  declare namespace githubSignInResolvers {
21
21
  /**
22
22
  * Looks up the user by matching their GitHub username to the entity name.
23
+ *
24
+ * @deprecated Use {@link githubSignInResolvers.userIdMatchingUserEntityAnnotation}
25
+ * instead, because GitHub usernames can change and be reassigned.
23
26
  */
24
27
  const usernameMatchingUserEntityName: _backstage_plugin_auth_node.SignInResolverFactory<OAuthAuthenticatorResult<GithubProfile>, {
25
28
  dangerouslyAllowSignInWithoutUserInCatalog?: boolean | undefined;
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var backendPluginApi = require('@backstage/backend-plugin-api');
4
+ var pluginCatalogNode = require('@backstage/plugin-catalog-node');
4
5
  var pluginAuthNode = require('@backstage/plugin-auth-node');
5
6
  var authenticator = require('./authenticator.cjs.js');
6
7
  var resolvers = require('./resolvers.cjs.js');
@@ -11,15 +12,17 @@ const authModuleGithubProvider = backendPluginApi.createBackendModule({
11
12
  register(reg) {
12
13
  reg.registerInit({
13
14
  deps: {
14
- providers: pluginAuthNode.authProvidersExtensionPoint
15
+ providers: pluginAuthNode.authProvidersExtensionPoint,
16
+ auth: backendPluginApi.coreServices.auth,
17
+ catalog: pluginCatalogNode.catalogServiceRef
15
18
  },
16
- async init({ providers }) {
19
+ async init({ providers, auth, catalog }) {
17
20
  providers.registerProvider({
18
21
  providerId: "github",
19
22
  factory: pluginAuthNode.createOAuthProviderFactory({
20
23
  authenticator: authenticator.githubAuthenticator,
21
24
  signInResolverFactories: {
22
- ...resolvers.githubSignInResolvers,
25
+ ...resolvers.createGithubProviderSignInResolvers({ auth, catalog }),
23
26
  ...pluginAuthNode.commonSignInResolvers
24
27
  }
25
28
  })
@@ -1 +1 @@
1
- {"version":3,"file":"module.cjs.js","sources":["../src/module.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createBackendModule } from '@backstage/backend-plugin-api';\nimport {\n authProvidersExtensionPoint,\n commonSignInResolvers,\n createOAuthProviderFactory,\n} from '@backstage/plugin-auth-node';\nimport { githubAuthenticator } from './authenticator';\nimport { githubSignInResolvers } from './resolvers';\n\n/** @public */\nexport const authModuleGithubProvider = createBackendModule({\n pluginId: 'auth',\n moduleId: 'github-provider',\n register(reg) {\n reg.registerInit({\n deps: {\n providers: authProvidersExtensionPoint,\n },\n async init({ providers }) {\n providers.registerProvider({\n providerId: 'github',\n factory: createOAuthProviderFactory({\n authenticator: githubAuthenticator,\n signInResolverFactories: {\n ...githubSignInResolvers,\n ...commonSignInResolvers,\n },\n }),\n });\n },\n });\n },\n});\n"],"names":["createBackendModule","authProvidersExtensionPoint","createOAuthProviderFactory","githubAuthenticator","githubSignInResolvers","commonSignInResolvers"],"mappings":";;;;;;;AAyBO,MAAM,2BAA2BA,oCAAA,CAAoB;AAAA,EAC1D,QAAA,EAAU,MAAA;AAAA,EACV,QAAA,EAAU,iBAAA;AAAA,EACV,SAAS,GAAA,EAAK;AACZ,IAAA,GAAA,CAAI,YAAA,CAAa;AAAA,MACf,IAAA,EAAM;AAAA,QACJ,SAAA,EAAWC;AAAA,OACb;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,SAAA,EAAU,EAAG;AACxB,QAAA,SAAA,CAAU,gBAAA,CAAiB;AAAA,UACzB,UAAA,EAAY,QAAA;AAAA,UACZ,SAASC,yCAAA,CAA2B;AAAA,YAClC,aAAA,EAAeC,iCAAA;AAAA,YACf,uBAAA,EAAyB;AAAA,cACvB,GAAGC,+BAAA;AAAA,cACH,GAAGC;AAAA;AACL,WACD;AAAA,SACF,CAAA;AAAA,MACH;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
1
+ {"version":3,"file":"module.cjs.js","sources":["../src/module.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { catalogServiceRef } from '@backstage/plugin-catalog-node';\nimport {\n authProvidersExtensionPoint,\n commonSignInResolvers,\n createOAuthProviderFactory,\n} from '@backstage/plugin-auth-node';\nimport { githubAuthenticator } from './authenticator';\nimport { createGithubProviderSignInResolvers } from './resolvers';\n\n/** @public */\nexport const authModuleGithubProvider = createBackendModule({\n pluginId: 'auth',\n moduleId: 'github-provider',\n register(reg) {\n reg.registerInit({\n deps: {\n providers: authProvidersExtensionPoint,\n auth: coreServices.auth,\n catalog: catalogServiceRef,\n },\n async init({ providers, auth, catalog }) {\n providers.registerProvider({\n providerId: 'github',\n factory: createOAuthProviderFactory({\n authenticator: githubAuthenticator,\n signInResolverFactories: {\n ...createGithubProviderSignInResolvers({ auth, catalog }),\n ...commonSignInResolvers,\n },\n }),\n });\n },\n });\n },\n});\n"],"names":["createBackendModule","authProvidersExtensionPoint","coreServices","catalogServiceRef","createOAuthProviderFactory","githubAuthenticator","createGithubProviderSignInResolvers","commonSignInResolvers"],"mappings":";;;;;;;;AA6BO,MAAM,2BAA2BA,oCAAA,CAAoB;AAAA,EAC1D,QAAA,EAAU,MAAA;AAAA,EACV,QAAA,EAAU,iBAAA;AAAA,EACV,SAAS,GAAA,EAAK;AACZ,IAAA,GAAA,CAAI,YAAA,CAAa;AAAA,MACf,IAAA,EAAM;AAAA,QACJ,SAAA,EAAWC,0CAAA;AAAA,QACX,MAAMC,6BAAA,CAAa,IAAA;AAAA,QACnB,OAAA,EAASC;AAAA,OACX;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,SAAA,EAAW,IAAA,EAAM,SAAQ,EAAG;AACvC,QAAA,SAAA,CAAU,gBAAA,CAAiB;AAAA,UACzB,UAAA,EAAY,QAAA;AAAA,UACZ,SAASC,yCAAA,CAA2B;AAAA,YAClC,aAAA,EAAeC,iCAAA;AAAA,YACf,uBAAA,EAAyB;AAAA,cACvB,GAAGC,6CAAA,CAAoC,EAAE,IAAA,EAAM,SAAS,CAAA;AAAA,cACxD,GAAGC;AAAA;AACL,WACD;AAAA,SACF,CAAA;AAAA,MACH;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
@@ -1,8 +1,38 @@
1
1
  'use strict';
2
2
 
3
+ var catalogModel = require('@backstage/catalog-model');
4
+ var errors = require('@backstage/errors');
3
5
  var pluginAuthNode = require('@backstage/plugin-auth-node');
4
6
  var v3 = require('zod/v3');
5
7
 
8
+ const GITHUB_USER_ID_ANNOTATION = "github.com/user-id";
9
+ function requireMatchingGithubUserId(entity, userId) {
10
+ if (entity.metadata.annotations?.[GITHUB_USER_ID_ANNOTATION] !== userId) {
11
+ throw new Error(`GitHub user ID does not match the catalog user`);
12
+ }
13
+ }
14
+ async function signInWithCatalogEntity(entity, ctx) {
15
+ const { ownershipEntityRefs } = await ctx.resolveOwnershipEntityRefs(entity);
16
+ return ctx.issueToken({
17
+ claims: {
18
+ sub: catalogModel.stringifyEntityRef(entity),
19
+ ent: ownershipEntityRefs
20
+ }
21
+ });
22
+ }
23
+ async function signInWithoutCatalogUser(name, ctx) {
24
+ const userEntityRef = catalogModel.stringifyEntityRef({
25
+ kind: "User",
26
+ namespace: catalogModel.DEFAULT_NAMESPACE,
27
+ name
28
+ });
29
+ return ctx.issueToken({
30
+ claims: {
31
+ sub: userEntityRef,
32
+ ent: [userEntityRef]
33
+ }
34
+ });
35
+ }
6
36
  exports.githubSignInResolvers = void 0;
7
37
  ((githubSignInResolvers2) => {
8
38
  githubSignInResolvers2.usernameMatchingUserEntityName = pluginAuthNode.createSignInResolverFactory({
@@ -39,19 +69,73 @@ exports.githubSignInResolvers = void 0;
39
69
  if (!userId) {
40
70
  throw new Error(`GitHub user profile does not contain a user ID`);
41
71
  }
42
- return ctx.signInWithCatalogUser(
43
- {
44
- annotations: {
45
- "github.com/user-id": userId
46
- }
47
- },
48
- {
49
- dangerousEntityRefFallback: options?.dangerouslyAllowSignInWithoutUserInCatalog ? { entityRef: { name: userId } } : void 0
72
+ const query = {
73
+ annotations: {
74
+ [GITHUB_USER_ID_ANNOTATION]: userId
50
75
  }
51
- );
76
+ };
77
+ let entity;
78
+ try {
79
+ ({ entity } = await ctx.findCatalogUser(query));
80
+ } catch (error) {
81
+ if (!errors.isError(error) || error.name !== "NotFoundError" || !options.dangerouslyAllowSignInWithoutUserInCatalog) {
82
+ throw error;
83
+ }
84
+ return signInWithoutCatalogUser(userId, ctx);
85
+ }
86
+ requireMatchingGithubUserId(entity, userId);
87
+ return signInWithCatalogEntity(entity, ctx);
52
88
  };
53
89
  }
54
90
  }
55
91
  );
56
92
  })(exports.githubSignInResolvers || (exports.githubSignInResolvers = {}));
93
+ function createGithubProviderSignInResolvers(options) {
94
+ return {
95
+ ...exports.githubSignInResolvers,
96
+ userIdMatchingUserEntityAnnotation: pluginAuthNode.createSignInResolverFactory({
97
+ optionsSchema: v3.z.object({
98
+ dangerouslyAllowSignInWithoutUserInCatalog: v3.z.boolean().optional()
99
+ }).optional(),
100
+ create(resolverOptions = {}) {
101
+ return async (info, ctx) => {
102
+ const userId = info.result.fullProfile.nodeId;
103
+ if (!userId) {
104
+ throw new Error(`GitHub user profile does not contain a user ID`);
105
+ }
106
+ const credentials = await options.auth.getOwnServiceCredentials();
107
+ const { items } = await options.catalog.getEntities(
108
+ {
109
+ filter: {
110
+ kind: "user",
111
+ [`metadata.annotations.${GITHUB_USER_ID_ANNOTATION}`]: userId
112
+ }
113
+ },
114
+ { credentials }
115
+ );
116
+ const exactMatches = items.filter(
117
+ (item) => item.metadata.annotations?.[GITHUB_USER_ID_ANNOTATION] === userId
118
+ );
119
+ if (exactMatches.length > 1) {
120
+ throw new errors.ConflictError(
121
+ "User lookup resulted in multiple exact matches"
122
+ );
123
+ }
124
+ if (exactMatches.length === 1) {
125
+ return signInWithCatalogEntity(exactMatches[0], ctx);
126
+ }
127
+ if (items.length > 0) {
128
+ throw new Error(`GitHub user ID does not match the catalog user`);
129
+ }
130
+ if (resolverOptions.dangerouslyAllowSignInWithoutUserInCatalog) {
131
+ return signInWithoutCatalogUser(userId, ctx);
132
+ }
133
+ throw new errors.NotFoundError("User not found");
134
+ };
135
+ }
136
+ })
137
+ };
138
+ }
139
+
140
+ exports.createGithubProviderSignInResolvers = createGithubProviderSignInResolvers;
57
141
  //# sourceMappingURL=resolvers.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolvers.cjs.js","sources":["../src/resolvers.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createSignInResolverFactory,\n OAuthAuthenticatorResult,\n SignInInfo,\n} from '@backstage/plugin-auth-node';\nimport { z } from 'zod/v3';\n\nimport { GithubProfile } from './authenticator';\n\n/**\n * Available sign-in resolvers for the GitHub auth provider.\n *\n * @public\n */\nexport namespace githubSignInResolvers {\n /**\n * Looks up the user by matching their GitHub username to the entity name.\n */\n export const usernameMatchingUserEntityName = createSignInResolverFactory({\n optionsSchema: z\n .object({\n dangerouslyAllowSignInWithoutUserInCatalog: z.boolean().optional(),\n })\n .optional(),\n create(options = {}) {\n return async (\n info: SignInInfo<OAuthAuthenticatorResult<GithubProfile>>,\n ctx,\n ) => {\n const { fullProfile } = info.result;\n\n const userId = fullProfile.username;\n if (!userId) {\n throw new Error(`GitHub user profile does not contain a username`);\n }\n\n return ctx.signInWithCatalogUser(\n {\n entityRef: { name: userId },\n },\n {\n dangerousEntityRefFallback:\n options?.dangerouslyAllowSignInWithoutUserInCatalog\n ? { entityRef: { name: userId } }\n : undefined,\n },\n );\n };\n },\n });\n\n /**\n * Looks up the user by matching their GitHub user ID to the github.com/user-id annotation.\n */\n export const userIdMatchingUserEntityAnnotation = createSignInResolverFactory(\n {\n optionsSchema: z\n .object({\n dangerouslyAllowSignInWithoutUserInCatalog: z.boolean().optional(),\n })\n .optional(),\n create(options = {}) {\n return async (\n info: SignInInfo<OAuthAuthenticatorResult<GithubProfile>>,\n ctx,\n ) => {\n const { fullProfile } = info.result;\n\n const userId = fullProfile.nodeId;\n if (!userId) {\n throw new Error(`GitHub user profile does not contain a user ID`);\n }\n\n return ctx.signInWithCatalogUser(\n {\n annotations: {\n 'github.com/user-id': userId,\n },\n },\n {\n dangerousEntityRefFallback:\n options?.dangerouslyAllowSignInWithoutUserInCatalog\n ? { entityRef: { name: userId } }\n : undefined,\n },\n );\n };\n },\n },\n );\n}\n"],"names":["githubSignInResolvers","createSignInResolverFactory","z"],"mappings":";;;;;AA8BiBA;AAAA,CAAV,CAAUA,sBAAAA,KAAV;AAIE,EAAMA,sBAAAA,CAAA,iCAAiCC,0CAAA,CAA4B;AAAA,IACxE,aAAA,EAAeC,KACZ,MAAA,CAAO;AAAA,MACN,0CAAA,EAA4CA,IAAA,CAAE,OAAA,EAAQ,CAAE,QAAA;AAAS,KAClE,EACA,QAAA,EAAS;AAAA,IACZ,MAAA,CAAO,OAAA,GAAU,EAAC,EAAG;AACnB,MAAA,OAAO,OACL,MACA,GAAA,KACG;AACH,QAAA,MAAM,EAAE,WAAA,EAAY,GAAI,IAAA,CAAK,MAAA;AAE7B,QAAA,MAAM,SAAS,WAAA,CAAY,QAAA;AAC3B,QAAA,IAAI,CAAC,MAAA,EAAQ;AACX,UAAA,MAAM,IAAI,MAAM,CAAA,+CAAA,CAAiD,CAAA;AAAA,QACnE;AAEA,QAAA,OAAO,GAAA,CAAI,qBAAA;AAAA,UACT;AAAA,YACE,SAAA,EAAW,EAAE,IAAA,EAAM,MAAA;AAAO,WAC5B;AAAA,UACA;AAAA,YACE,0BAAA,EACE,SAAS,0CAAA,GACL,EAAE,WAAW,EAAE,IAAA,EAAM,MAAA,EAAO,EAAE,GAC9B;AAAA;AACR,SACF;AAAA,MACF,CAAA;AAAA,IACF;AAAA,GACD,CAAA;AAKM,EAAMF,uBAAA,kCAAA,GAAqCC,0CAAA;AAAA,IAChD;AAAA,MACE,aAAA,EAAeC,KACZ,MAAA,CAAO;AAAA,QACN,0CAAA,EAA4CA,IAAA,CAAE,OAAA,EAAQ,CAAE,QAAA;AAAS,OAClE,EACA,QAAA,EAAS;AAAA,MACZ,MAAA,CAAO,OAAA,GAAU,EAAC,EAAG;AACnB,QAAA,OAAO,OACL,MACA,GAAA,KACG;AACH,UAAA,MAAM,EAAE,WAAA,EAAY,GAAI,IAAA,CAAK,MAAA;AAE7B,UAAA,MAAM,SAAS,WAAA,CAAY,MAAA;AAC3B,UAAA,IAAI,CAAC,MAAA,EAAQ;AACX,YAAA,MAAM,IAAI,MAAM,CAAA,8CAAA,CAAgD,CAAA;AAAA,UAClE;AAEA,UAAA,OAAO,GAAA,CAAI,qBAAA;AAAA,YACT;AAAA,cACE,WAAA,EAAa;AAAA,gBACX,oBAAA,EAAsB;AAAA;AACxB,aACF;AAAA,YACA;AAAA,cACE,0BAAA,EACE,SAAS,0CAAA,GACL,EAAE,WAAW,EAAE,IAAA,EAAM,MAAA,EAAO,EAAE,GAC9B;AAAA;AACR,WACF;AAAA,QACF,CAAA;AAAA,MACF;AAAA;AACF,GACF;AAAA,CAAA,EA3EeF,6BAAA,KAAAA,6BAAA,GAAA,EAAA,CAAA,CAAA;;"}
1
+ {"version":3,"file":"resolvers.cjs.js","sources":["../src/resolvers.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n DEFAULT_NAMESPACE,\n stringifyEntityRef,\n type Entity,\n} from '@backstage/catalog-model';\nimport type { AuthService } from '@backstage/backend-plugin-api';\nimport { ConflictError, isError, NotFoundError } from '@backstage/errors';\nimport {\n type AuthResolverContext,\n createSignInResolverFactory,\n OAuthAuthenticatorResult,\n SignInInfo,\n} from '@backstage/plugin-auth-node';\nimport type { CatalogService } from '@backstage/plugin-catalog-node';\nimport { z } from 'zod/v3';\n\nimport { GithubProfile } from './authenticator';\n\nconst GITHUB_USER_ID_ANNOTATION = 'github.com/user-id';\n\nfunction requireMatchingGithubUserId(entity: Entity, userId: string) {\n if (entity.metadata.annotations?.[GITHUB_USER_ID_ANNOTATION] !== userId) {\n throw new Error(`GitHub user ID does not match the catalog user`);\n }\n}\n\nasync function signInWithCatalogEntity(\n entity: Entity,\n ctx: AuthResolverContext,\n) {\n const { ownershipEntityRefs } = await ctx.resolveOwnershipEntityRefs(entity);\n return ctx.issueToken({\n claims: {\n sub: stringifyEntityRef(entity),\n ent: ownershipEntityRefs,\n },\n });\n}\n\nasync function signInWithoutCatalogUser(\n name: string,\n ctx: AuthResolverContext,\n) {\n const userEntityRef = stringifyEntityRef({\n kind: 'User',\n namespace: DEFAULT_NAMESPACE,\n name,\n });\n return ctx.issueToken({\n claims: {\n sub: userEntityRef,\n ent: [userEntityRef],\n },\n });\n}\n\n/**\n * Available sign-in resolvers for the GitHub auth provider.\n *\n * @public\n */\nexport namespace githubSignInResolvers {\n /**\n * Looks up the user by matching their GitHub username to the entity name.\n *\n * @deprecated Use {@link githubSignInResolvers.userIdMatchingUserEntityAnnotation}\n * instead, because GitHub usernames can change and be reassigned.\n */\n export const usernameMatchingUserEntityName = createSignInResolverFactory({\n optionsSchema: z\n .object({\n dangerouslyAllowSignInWithoutUserInCatalog: z.boolean().optional(),\n })\n .optional(),\n create(options = {}) {\n return async (\n info: SignInInfo<OAuthAuthenticatorResult<GithubProfile>>,\n ctx,\n ) => {\n const { fullProfile } = info.result;\n\n const userId = fullProfile.username;\n if (!userId) {\n throw new Error(`GitHub user profile does not contain a username`);\n }\n\n return ctx.signInWithCatalogUser(\n {\n entityRef: { name: userId },\n },\n {\n dangerousEntityRefFallback:\n options?.dangerouslyAllowSignInWithoutUserInCatalog\n ? { entityRef: { name: userId } }\n : undefined,\n },\n );\n };\n },\n });\n\n /**\n * Looks up the user by matching their GitHub user ID to the github.com/user-id annotation.\n */\n export const userIdMatchingUserEntityAnnotation = createSignInResolverFactory(\n {\n optionsSchema: z\n .object({\n dangerouslyAllowSignInWithoutUserInCatalog: z.boolean().optional(),\n })\n .optional(),\n create(options = {}) {\n return async (\n info: SignInInfo<OAuthAuthenticatorResult<GithubProfile>>,\n ctx,\n ) => {\n const { fullProfile } = info.result;\n\n const userId = fullProfile.nodeId;\n if (!userId) {\n throw new Error(`GitHub user profile does not contain a user ID`);\n }\n\n const query = {\n annotations: {\n [GITHUB_USER_ID_ANNOTATION]: userId,\n },\n };\n\n let entity;\n try {\n ({ entity } = await ctx.findCatalogUser(query));\n } catch (error) {\n if (\n !isError(error) ||\n error.name !== 'NotFoundError' ||\n !options.dangerouslyAllowSignInWithoutUserInCatalog\n ) {\n throw error;\n }\n\n return signInWithoutCatalogUser(userId, ctx);\n }\n\n requireMatchingGithubUserId(entity, userId);\n return signInWithCatalogEntity(entity, ctx);\n };\n },\n },\n );\n}\n\n/**\n * Creates the resolver map used by the built-in GitHub provider module.\n *\n * @remarks\n *\n * The service-aware user ID resolver can inspect all case-insensitive catalog\n * matches and select the exact ID. The public resolver remains fail-closed when\n * its context reports an ambiguous lookup.\n *\n * @internal\n */\nexport function createGithubProviderSignInResolvers(options: {\n auth: AuthService;\n catalog: CatalogService;\n}) {\n return {\n ...githubSignInResolvers,\n userIdMatchingUserEntityAnnotation: createSignInResolverFactory({\n optionsSchema: z\n .object({\n dangerouslyAllowSignInWithoutUserInCatalog: z.boolean().optional(),\n })\n .optional(),\n create(resolverOptions = {}) {\n return async (\n info: SignInInfo<OAuthAuthenticatorResult<GithubProfile>>,\n ctx: AuthResolverContext,\n ) => {\n const userId = info.result.fullProfile.nodeId;\n if (!userId) {\n throw new Error(`GitHub user profile does not contain a user ID`);\n }\n\n const credentials = await options.auth.getOwnServiceCredentials();\n const { items } = await options.catalog.getEntities(\n {\n filter: {\n kind: 'user',\n [`metadata.annotations.${GITHUB_USER_ID_ANNOTATION}`]: userId,\n },\n },\n { credentials },\n );\n const exactMatches = items.filter(\n item =>\n item.metadata.annotations?.[GITHUB_USER_ID_ANNOTATION] === userId,\n );\n\n if (exactMatches.length > 1) {\n throw new ConflictError(\n 'User lookup resulted in multiple exact matches',\n );\n }\n if (exactMatches.length === 1) {\n return signInWithCatalogEntity(exactMatches[0], ctx);\n }\n if (items.length > 0) {\n throw new Error(`GitHub user ID does not match the catalog user`);\n }\n if (resolverOptions.dangerouslyAllowSignInWithoutUserInCatalog) {\n return signInWithoutCatalogUser(userId, ctx);\n }\n throw new NotFoundError('User not found');\n };\n },\n }),\n };\n}\n"],"names":["stringifyEntityRef","DEFAULT_NAMESPACE","githubSignInResolvers","createSignInResolverFactory","z","isError","ConflictError","NotFoundError"],"mappings":";;;;;;;AAkCA,MAAM,yBAAA,GAA4B,oBAAA;AAElC,SAAS,2BAAA,CAA4B,QAAgB,MAAA,EAAgB;AACnE,EAAA,IAAI,MAAA,CAAO,QAAA,CAAS,WAAA,GAAc,yBAAyB,MAAM,MAAA,EAAQ;AACvE,IAAA,MAAM,IAAI,MAAM,CAAA,8CAAA,CAAgD,CAAA;AAAA,EAClE;AACF;AAEA,eAAe,uBAAA,CACb,QACA,GAAA,EACA;AACA,EAAA,MAAM,EAAE,mBAAA,EAAoB,GAAI,MAAM,GAAA,CAAI,2BAA2B,MAAM,CAAA;AAC3E,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AAS,CAAA,EAAG;AACpB,YAAA,MAAM,IAAI,MAAM,CAAA,8CAAA,CAAgD,CAAA;AAAA,UAClE;AACA,UAAA,IAAI,gBAAgB,0CAAA,EAA4C;AAC9D,YAAA,OAAO,wBAAA,CAAyB,QAAQ,GAAG,CAAA;AAAA,UAC7C;AACA,UAAA,MAAM,IAAIC,qBAAc,gBAAgB,CAAA;AAAA,QAC1C,CAAA;AAAA,MACF;AAAA,KACD;AAAA,GACH;AACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-auth-backend-module-github-provider",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "The github-provider backend module for the auth plugin.",
5
5
  "backstage": {
6
6
  "role": "backend-plugin-module",
@@ -37,16 +37,19 @@
37
37
  "test": "backstage-cli package test"
38
38
  },
39
39
  "dependencies": {
40
- "@backstage/backend-plugin-api": "^1.10.0",
41
- "@backstage/plugin-auth-node": "^0.7.4",
40
+ "@backstage/backend-plugin-api": "^1.10.1",
41
+ "@backstage/catalog-model": "^1.10.1",
42
+ "@backstage/errors": "^1.3.1",
43
+ "@backstage/plugin-auth-node": "^0.7.6",
44
+ "@backstage/plugin-catalog-node": "^2.2.5",
42
45
  "passport-github2": "^0.1.12",
43
46
  "zod": "^3.25.76 || ^4.0.0"
44
47
  },
45
48
  "devDependencies": {
46
- "@backstage/backend-defaults": "^0.17.7",
47
- "@backstage/backend-test-utils": "^1.11.6",
48
- "@backstage/cli": "^0.36.5",
49
- "@backstage/plugin-auth-backend": "^0.30.0",
49
+ "@backstage/backend-defaults": "^0.18.0",
50
+ "@backstage/backend-test-utils": "^1.11.7",
51
+ "@backstage/cli": "^0.36.6",
52
+ "@backstage/plugin-auth-backend": "^0.30.1",
50
53
  "@backstage/types": "^1.2.2",
51
54
  "@types/passport-github2": "^1.2.4",
52
55
  "supertest": "^7.0.0"