@backstage/plugin-auth-backend 0.18.8-next.0 → 0.18.8

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/dist/index.cjs.js CHANGED
@@ -2,27 +2,26 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var backendPluginApi = require('@backstage/backend-plugin-api');
6
- var pluginAuthNode = require('@backstage/plugin-auth-node');
7
- var alpha = require('@backstage/plugin-catalog-node/alpha');
8
5
  var express = require('express');
9
6
  var Router = require('express-promise-router');
10
7
  var cookieParser = require('cookie-parser');
11
8
  var OAuth2Strategy = require('passport-oauth2');
9
+ var errors = require('@backstage/errors');
10
+ var pickBy = require('lodash/pickBy');
12
11
  var crypto = require('crypto');
13
12
  var url = require('url');
14
- var errors = require('@backstage/errors');
15
13
  var jwtDecoder = require('jwt-decode');
16
14
  var Auth0InternalStrategy = require('passport-auth0');
17
15
  var fetch = require('node-fetch');
18
16
  var NodeCache = require('node-cache');
19
17
  var jose = require('jose');
20
18
  var passportBitbucketOauth2 = require('passport-bitbucket-oauth2');
21
- var pluginAuthBackendModuleGcpIapProvider = require('@backstage/plugin-auth-backend-module-gcp-iap-provider');
22
- var pluginAuthBackendModuleGithubProvider = require('@backstage/plugin-auth-backend-module-github-provider');
19
+ var googleAuthLibrary = require('google-auth-library');
20
+ var passportGithub2 = require('passport-github2');
23
21
  var passportGitlab2 = require('passport-gitlab2');
24
- var pluginAuthBackendModuleGoogleProvider = require('@backstage/plugin-auth-backend-module-google-provider');
22
+ var passportGoogleOauth20 = require('passport-google-oauth20');
25
23
  var passportMicrosoft = require('passport-microsoft');
24
+ var pluginAuthNode = require('@backstage/plugin-auth-node');
26
25
  var openidClient = require('openid-client');
27
26
  var passportOktaOauth = require('@davidzemon/passport-okta-oauth');
28
27
  var passportOneloginOauth = require('passport-onelogin-oauth');
@@ -64,6 +63,7 @@ var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
64
63
  var Router__default = /*#__PURE__*/_interopDefaultLegacy(Router);
65
64
  var cookieParser__default = /*#__PURE__*/_interopDefaultLegacy(cookieParser);
66
65
  var OAuth2Strategy__default = /*#__PURE__*/_interopDefaultLegacy(OAuth2Strategy);
66
+ var pickBy__default = /*#__PURE__*/_interopDefaultLegacy(pickBy);
67
67
  var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
68
68
  var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
69
69
  var jwtDecoder__default = /*#__PURE__*/_interopDefaultLegacy(jwtDecoder);
@@ -74,10 +74,10 @@ var session__default = /*#__PURE__*/_interopDefaultLegacy(session);
74
74
  var connectSessionKnex__default = /*#__PURE__*/_interopDefaultLegacy(connectSessionKnex);
75
75
  var passport__default = /*#__PURE__*/_interopDefaultLegacy(passport);
76
76
 
77
- var __defProp$j = Object.defineProperty;
78
- var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
79
- var __publicField$j = (obj, key, value) => {
80
- __defNormalProp$j(obj, typeof key !== "symbol" ? key + "" : key, value);
77
+ var __defProp$m = Object.defineProperty;
78
+ var __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
79
+ var __publicField$m = (obj, key, value) => {
80
+ __defNormalProp$m(obj, typeof key !== "symbol" ? key + "" : key, value);
81
81
  return value;
82
82
  };
83
83
  const defaultScopes = ["offline_access", "read:me"];
@@ -94,7 +94,7 @@ class AtlassianStrategy extends OAuth2Strategy__default["default"] {
94
94
  scope: Array.from(/* @__PURE__ */ new Set([...defaultScopes, ...scopes]))
95
95
  };
96
96
  super(optionsWithURLs, verify);
97
- __publicField$j(this, "profileURL");
97
+ __publicField$m(this, "profileURL");
98
98
  this.profileURL = "https://api.atlassian.com/me";
99
99
  this.name = "atlassian";
100
100
  this._oauth2.useAuthorizationHeaderforGET(true);
@@ -142,10 +142,22 @@ class AtlassianStrategy extends OAuth2Strategy__default["default"] {
142
142
  }
143
143
  }
144
144
 
145
- const OAuthEnvironmentHandler = pluginAuthNode.OAuthEnvironmentHandler;
146
-
147
- const readState = pluginAuthNode.decodeOAuthState;
148
- const encodeState = pluginAuthNode.encodeOAuthState;
145
+ const readState = (stateString) => {
146
+ var _a, _b;
147
+ const state = Object.fromEntries(
148
+ new URLSearchParams(Buffer.from(stateString, "hex").toString("utf-8"))
149
+ );
150
+ if (!state.nonce || !state.env || ((_a = state.nonce) == null ? void 0 : _a.length) === 0 || ((_b = state.env) == null ? void 0 : _b.length) === 0) {
151
+ throw Error(`Invalid state passed via request`);
152
+ }
153
+ return state;
154
+ };
155
+ const encodeState = (state) => {
156
+ const stateString = new URLSearchParams(
157
+ pickBy__default["default"](state, (value) => value !== void 0)
158
+ ).toString();
159
+ return Buffer.from(stateString, "utf-8").toString("hex");
160
+ };
149
161
  const verifyNonce = (req, providerId) => {
150
162
  var _a, _b;
151
163
  const cookieNonce = req.cookies[`${providerId}-nonce`];
@@ -176,6 +188,66 @@ const defaultCookieConfigurer = ({
176
188
  return { domain, path, secure, sameSite };
177
189
  };
178
190
 
191
+ class OAuthEnvironmentHandler {
192
+ constructor(handlers) {
193
+ this.handlers = handlers;
194
+ }
195
+ static mapConfig(config, factoryFunc) {
196
+ const envs = config.keys();
197
+ const handlers = /* @__PURE__ */ new Map();
198
+ for (const env of envs) {
199
+ const envConfig = config.getConfig(env);
200
+ const handler = factoryFunc(envConfig);
201
+ handlers.set(env, handler);
202
+ }
203
+ return new OAuthEnvironmentHandler(handlers);
204
+ }
205
+ async start(req, res) {
206
+ const provider = this.getProviderForEnv(req);
207
+ await provider.start(req, res);
208
+ }
209
+ async frameHandler(req, res) {
210
+ const provider = this.getProviderForEnv(req);
211
+ await provider.frameHandler(req, res);
212
+ }
213
+ async refresh(req, res) {
214
+ var _a;
215
+ const provider = this.getProviderForEnv(req);
216
+ await ((_a = provider.refresh) == null ? void 0 : _a.call(provider, req, res));
217
+ }
218
+ async logout(req, res) {
219
+ var _a;
220
+ const provider = this.getProviderForEnv(req);
221
+ await ((_a = provider.logout) == null ? void 0 : _a.call(provider, req, res));
222
+ }
223
+ getRequestFromEnv(req) {
224
+ var _a, _b;
225
+ const reqEnv = (_a = req.query.env) == null ? void 0 : _a.toString();
226
+ if (reqEnv) {
227
+ return reqEnv;
228
+ }
229
+ const stateParams = (_b = req.query.state) == null ? void 0 : _b.toString();
230
+ if (!stateParams) {
231
+ return void 0;
232
+ }
233
+ const env = readState(stateParams).env;
234
+ return env;
235
+ }
236
+ getProviderForEnv(req) {
237
+ const env = this.getRequestFromEnv(req);
238
+ if (!env) {
239
+ throw new errors.InputError(`Must specify 'env' query to select environment`);
240
+ }
241
+ const handler = this.handlers.get(env);
242
+ if (!handler) {
243
+ throw new errors.NotFoundError(
244
+ `No configuration available for the '${env}' environment of this provider.`
245
+ );
246
+ }
247
+ return handler;
248
+ }
249
+ }
250
+
179
251
  const safelyEncodeURIComponent = (value) => {
180
252
  return encodeURIComponent(value).replace(/'/g, "%27");
181
253
  };
@@ -207,12 +279,26 @@ const ensuresXRequestedWith = (req) => {
207
279
  return true;
208
280
  };
209
281
 
210
- const prepareBackstageIdentityResponse = pluginAuthNode.prepareBackstageIdentityResponse;
282
+ function parseJwtPayload(token) {
283
+ const [_header, payload, _signature] = token.split(".");
284
+ return JSON.parse(Buffer.from(payload, "base64").toString());
285
+ }
286
+ function prepareBackstageIdentityResponse(result) {
287
+ const { sub, ent } = parseJwtPayload(result.token);
288
+ return {
289
+ ...result,
290
+ identity: {
291
+ type: "user",
292
+ userEntityRef: sub,
293
+ ownershipEntityRefs: ent != null ? ent : []
294
+ }
295
+ };
296
+ }
211
297
 
212
- var __defProp$i = Object.defineProperty;
213
- var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
214
- var __publicField$i = (obj, key, value) => {
215
- __defNormalProp$i(obj, typeof key !== "symbol" ? key + "" : key, value);
298
+ var __defProp$l = Object.defineProperty;
299
+ var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
300
+ var __publicField$l = (obj, key, value) => {
301
+ __defNormalProp$l(obj, typeof key !== "symbol" ? key + "" : key, value);
216
302
  return value;
217
303
  };
218
304
  const THOUSAND_DAYS_MS = 1e3 * 24 * 60 * 60 * 1e3;
@@ -221,8 +307,8 @@ class OAuthAdapter {
221
307
  constructor(handlers, options) {
222
308
  this.handlers = handlers;
223
309
  this.options = options;
224
- __publicField$i(this, "baseCookieOptions");
225
- __publicField$i(this, "setNonceCookie", (res, nonce, cookieConfig) => {
310
+ __publicField$l(this, "baseCookieOptions");
311
+ __publicField$l(this, "setNonceCookie", (res, nonce, cookieConfig) => {
226
312
  res.cookie(`${this.options.providerId}-nonce`, nonce, {
227
313
  maxAge: TEN_MINUTES_MS,
228
314
  ...this.baseCookieOptions,
@@ -230,34 +316,34 @@ class OAuthAdapter {
230
316
  path: `${cookieConfig.path}/handler`
231
317
  });
232
318
  });
233
- __publicField$i(this, "setGrantedScopeCookie", (res, scope, cookieConfig) => {
319
+ __publicField$l(this, "setGrantedScopeCookie", (res, scope, cookieConfig) => {
234
320
  res.cookie(`${this.options.providerId}-granted-scope`, scope, {
235
321
  maxAge: THOUSAND_DAYS_MS,
236
322
  ...this.baseCookieOptions,
237
323
  ...cookieConfig
238
324
  });
239
325
  });
240
- __publicField$i(this, "getRefreshTokenFromCookie", (req) => {
326
+ __publicField$l(this, "getRefreshTokenFromCookie", (req) => {
241
327
  return req.cookies[`${this.options.providerId}-refresh-token`];
242
328
  });
243
- __publicField$i(this, "getGrantedScopeFromCookie", (req) => {
329
+ __publicField$l(this, "getGrantedScopeFromCookie", (req) => {
244
330
  return req.cookies[`${this.options.providerId}-granted-scope`];
245
331
  });
246
- __publicField$i(this, "setRefreshTokenCookie", (res, refreshToken, cookieConfig) => {
332
+ __publicField$l(this, "setRefreshTokenCookie", (res, refreshToken, cookieConfig) => {
247
333
  res.cookie(`${this.options.providerId}-refresh-token`, refreshToken, {
248
334
  maxAge: THOUSAND_DAYS_MS,
249
335
  ...this.baseCookieOptions,
250
336
  ...cookieConfig
251
337
  });
252
338
  });
253
- __publicField$i(this, "removeRefreshTokenCookie", (res, cookieConfig) => {
339
+ __publicField$l(this, "removeRefreshTokenCookie", (res, cookieConfig) => {
254
340
  res.cookie(`${this.options.providerId}-refresh-token`, "", {
255
341
  maxAge: 0,
256
342
  ...this.baseCookieOptions,
257
343
  ...cookieConfig
258
344
  });
259
345
  });
260
- __publicField$i(this, "getCookieConfig", (origin) => {
346
+ __publicField$l(this, "getCookieConfig", (origin) => {
261
347
  return this.options.cookieConfigurer({
262
348
  providerId: this.options.providerId,
263
349
  baseUrl: this.options.baseUrl,
@@ -563,10 +649,10 @@ function createAuthProviderIntegration(config) {
563
649
  });
564
650
  }
565
651
 
566
- var __defProp$h = Object.defineProperty;
567
- var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
568
- var __publicField$h = (obj, key, value) => {
569
- __defNormalProp$h(obj, typeof key !== "symbol" ? key + "" : key, value);
652
+ var __defProp$k = Object.defineProperty;
653
+ var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
654
+ var __publicField$k = (obj, key, value) => {
655
+ __defNormalProp$k(obj, typeof key !== "symbol" ? key + "" : key, value);
570
656
  return value;
571
657
  };
572
658
  const atlassianDefaultAuthHandler = async ({
@@ -577,10 +663,10 @@ const atlassianDefaultAuthHandler = async ({
577
663
  });
578
664
  class AtlassianAuthProvider {
579
665
  constructor(options) {
580
- __publicField$h(this, "_strategy");
581
- __publicField$h(this, "signInResolver");
582
- __publicField$h(this, "authHandler");
583
- __publicField$h(this, "resolverContext");
666
+ __publicField$k(this, "_strategy");
667
+ __publicField$k(this, "signInResolver");
668
+ __publicField$k(this, "authHandler");
669
+ __publicField$k(this, "resolverContext");
584
670
  this.resolverContext = options.resolverContext;
585
671
  this.authHandler = options.authHandler;
586
672
  this.signInResolver = options.signInResolver;
@@ -698,21 +784,21 @@ class Auth0Strategy extends Auth0InternalStrategy__default["default"] {
698
784
  }
699
785
  }
700
786
 
701
- var __defProp$g = Object.defineProperty;
702
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
703
- var __publicField$g = (obj, key, value) => {
704
- __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
787
+ var __defProp$j = Object.defineProperty;
788
+ var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
789
+ var __publicField$j = (obj, key, value) => {
790
+ __defNormalProp$j(obj, typeof key !== "symbol" ? key + "" : key, value);
705
791
  return value;
706
792
  };
707
793
  class Auth0AuthProvider {
708
794
  constructor(options) {
709
- __publicField$g(this, "_strategy");
710
- __publicField$g(this, "signInResolver");
711
- __publicField$g(this, "authHandler");
712
- __publicField$g(this, "resolverContext");
713
- __publicField$g(this, "audience");
714
- __publicField$g(this, "connection");
715
- __publicField$g(this, "connectionScope");
795
+ __publicField$j(this, "_strategy");
796
+ __publicField$j(this, "signInResolver");
797
+ __publicField$j(this, "authHandler");
798
+ __publicField$j(this, "resolverContext");
799
+ __publicField$j(this, "audience");
800
+ __publicField$j(this, "connection");
801
+ __publicField$j(this, "connectionScope");
716
802
  /**
717
803
  * Due to passport-auth0 forcing options.state = true,
718
804
  * passport-oauth2 requires express-session to be installed
@@ -721,7 +807,7 @@ class Auth0AuthProvider {
721
807
  * passport-oauth2, which is the StateStore implementation used when options.state = false,
722
808
  * allowing us to avoid using express-session in order to integrate with auth0.
723
809
  */
724
- __publicField$g(this, "store", {
810
+ __publicField$j(this, "store", {
725
811
  store(_req, cb) {
726
812
  cb(null, null);
727
813
  },
@@ -862,23 +948,23 @@ const auth0 = createAuthProviderIntegration({
862
948
  }
863
949
  });
864
950
 
865
- var __defProp$f = Object.defineProperty;
866
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
867
- var __publicField$f = (obj, key, value) => {
868
- __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
951
+ var __defProp$i = Object.defineProperty;
952
+ var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
953
+ var __publicField$i = (obj, key, value) => {
954
+ __defNormalProp$i(obj, typeof key !== "symbol" ? key + "" : key, value);
869
955
  return value;
870
956
  };
871
957
  const ALB_JWT_HEADER = "x-amzn-oidc-data";
872
958
  const ALB_ACCESS_TOKEN_HEADER = "x-amzn-oidc-accesstoken";
873
959
  class AwsAlbAuthProvider {
874
960
  constructor(options) {
875
- __publicField$f(this, "region");
876
- __publicField$f(this, "issuer");
877
- __publicField$f(this, "resolverContext");
878
- __publicField$f(this, "keyCache");
879
- __publicField$f(this, "authHandler");
880
- __publicField$f(this, "signInResolver");
881
- __publicField$f(this, "getKey", async (header) => {
961
+ __publicField$i(this, "region");
962
+ __publicField$i(this, "issuer");
963
+ __publicField$i(this, "resolverContext");
964
+ __publicField$i(this, "keyCache");
965
+ __publicField$i(this, "authHandler");
966
+ __publicField$i(this, "signInResolver");
967
+ __publicField$i(this, "getKey", async (header) => {
882
968
  if (!header.kid) {
883
969
  throw new errors.AuthenticationError("No key id was specified in header");
884
970
  }
@@ -1006,18 +1092,18 @@ const awsAlb = createAuthProviderIntegration({
1006
1092
  }
1007
1093
  });
1008
1094
 
1009
- var __defProp$e = Object.defineProperty;
1010
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1011
- var __publicField$e = (obj, key, value) => {
1012
- __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
1095
+ var __defProp$h = Object.defineProperty;
1096
+ var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1097
+ var __publicField$h = (obj, key, value) => {
1098
+ __defNormalProp$h(obj, typeof key !== "symbol" ? key + "" : key, value);
1013
1099
  return value;
1014
1100
  };
1015
1101
  class BitbucketAuthProvider {
1016
1102
  constructor(options) {
1017
- __publicField$e(this, "_strategy");
1018
- __publicField$e(this, "signInResolver");
1019
- __publicField$e(this, "authHandler");
1020
- __publicField$e(this, "resolverContext");
1103
+ __publicField$h(this, "_strategy");
1104
+ __publicField$h(this, "signInResolver");
1105
+ __publicField$h(this, "authHandler");
1106
+ __publicField$h(this, "resolverContext");
1021
1107
  this.signInResolver = options.signInResolver;
1022
1108
  this.authHandler = options.authHandler;
1023
1109
  this.resolverContext = options.resolverContext;
@@ -1185,10 +1271,10 @@ const commonByEmailResolver = async (info, ctx) => {
1185
1271
  });
1186
1272
  };
1187
1273
 
1188
- var __defProp$d = Object.defineProperty;
1189
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1190
- var __publicField$d = (obj, key, value) => {
1191
- __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
1274
+ var __defProp$g = Object.defineProperty;
1275
+ var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1276
+ var __publicField$g = (obj, key, value) => {
1277
+ __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
1192
1278
  return value;
1193
1279
  };
1194
1280
  const CF_JWT_HEADER = "cf-access-jwt-assertion";
@@ -1196,12 +1282,12 @@ const COOKIE_AUTH_NAME = "CF_Authorization";
1196
1282
  const CACHE_PREFIX = "providers/cloudflare-access/profile-v1";
1197
1283
  class CloudflareAccessAuthProvider {
1198
1284
  constructor(options) {
1199
- __publicField$d(this, "teamName");
1200
- __publicField$d(this, "resolverContext");
1201
- __publicField$d(this, "authHandler");
1202
- __publicField$d(this, "signInResolver");
1203
- __publicField$d(this, "jwtKeySet");
1204
- __publicField$d(this, "cache");
1285
+ __publicField$g(this, "teamName");
1286
+ __publicField$g(this, "resolverContext");
1287
+ __publicField$g(this, "authHandler");
1288
+ __publicField$g(this, "signInResolver");
1289
+ __publicField$g(this, "jwtKeySet");
1290
+ __publicField$g(this, "cache");
1205
1291
  this.teamName = options.teamName;
1206
1292
  this.authHandler = options.authHandler;
1207
1293
  this.signInResolver = options.signInResolver;
@@ -1339,52 +1425,272 @@ const cfAccess = createAuthProviderIntegration({
1339
1425
  }
1340
1426
  });
1341
1427
 
1428
+ function createTokenValidator(audience, mockClient) {
1429
+ const client = mockClient != null ? mockClient : new googleAuthLibrary.OAuth2Client();
1430
+ return async function tokenValidator(token) {
1431
+ const response = await client.getIapPublicKeys();
1432
+ const ticket = await client.verifySignedJwtWithCertsAsync(
1433
+ token,
1434
+ response.pubkeys,
1435
+ audience,
1436
+ ["https://cloud.google.com/iap"]
1437
+ );
1438
+ const payload = ticket.getPayload();
1439
+ if (!payload) {
1440
+ throw new TypeError("Token had no payload");
1441
+ }
1442
+ return payload;
1443
+ };
1444
+ }
1445
+ async function parseRequestToken(jwtToken, tokenValidator) {
1446
+ if (typeof jwtToken !== "string" || !jwtToken) {
1447
+ throw new errors.AuthenticationError("Missing Google IAP header");
1448
+ }
1449
+ let payload;
1450
+ try {
1451
+ payload = await tokenValidator(jwtToken);
1452
+ } catch (e) {
1453
+ throw new errors.AuthenticationError(`Google IAP token verification failed, ${e}`);
1454
+ }
1455
+ if (!payload.sub || !payload.email) {
1456
+ throw new errors.AuthenticationError(
1457
+ "Google IAP token payload is missing sub and/or email claim"
1458
+ );
1459
+ }
1460
+ return {
1461
+ iapToken: {
1462
+ ...payload,
1463
+ sub: payload.sub,
1464
+ email: payload.email
1465
+ }
1466
+ };
1467
+ }
1468
+ const defaultAuthHandler$1 = async ({
1469
+ iapToken
1470
+ }) => ({ profile: { email: iapToken.email } });
1471
+
1472
+ const DEFAULT_IAP_JWT_HEADER = "x-goog-iap-jwt-assertion";
1473
+
1474
+ var __defProp$f = Object.defineProperty;
1475
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1476
+ var __publicField$f = (obj, key, value) => {
1477
+ __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
1478
+ return value;
1479
+ };
1480
+ class GcpIapProvider {
1481
+ constructor(options) {
1482
+ __publicField$f(this, "authHandler");
1483
+ __publicField$f(this, "signInResolver");
1484
+ __publicField$f(this, "tokenValidator");
1485
+ __publicField$f(this, "resolverContext");
1486
+ __publicField$f(this, "jwtHeader");
1487
+ this.authHandler = options.authHandler;
1488
+ this.signInResolver = options.signInResolver;
1489
+ this.tokenValidator = options.tokenValidator;
1490
+ this.resolverContext = options.resolverContext;
1491
+ this.jwtHeader = (options == null ? void 0 : options.jwtHeader) || DEFAULT_IAP_JWT_HEADER;
1492
+ }
1493
+ async start() {
1494
+ }
1495
+ async frameHandler() {
1496
+ }
1497
+ async refresh(req, res) {
1498
+ const result = await parseRequestToken(
1499
+ req.header(this.jwtHeader),
1500
+ this.tokenValidator
1501
+ );
1502
+ const { profile } = await this.authHandler(result, this.resolverContext);
1503
+ const backstageIdentity = await this.signInResolver(
1504
+ { profile, result },
1505
+ this.resolverContext
1506
+ );
1507
+ const response = {
1508
+ providerInfo: { iapToken: result.iapToken },
1509
+ profile,
1510
+ backstageIdentity: prepareBackstageIdentityResponse(backstageIdentity)
1511
+ };
1512
+ res.json(response);
1513
+ }
1514
+ }
1342
1515
  const gcpIap = createAuthProviderIntegration({
1343
1516
  create(options) {
1344
- var _a;
1345
- return pluginAuthNode.createProxyAuthProviderFactory({
1346
- authenticator: pluginAuthBackendModuleGcpIapProvider.gcpIapAuthenticator,
1347
- profileTransform: options == null ? void 0 : options.authHandler,
1348
- signInResolver: (_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver
1349
- });
1517
+ return ({ config, resolverContext }) => {
1518
+ var _a;
1519
+ const audience = config.getString("audience");
1520
+ const jwtHeader = config.getOptionalString("jwtHeader");
1521
+ const authHandler = (_a = options.authHandler) != null ? _a : defaultAuthHandler$1;
1522
+ const signInResolver = options.signIn.resolver;
1523
+ const tokenValidator = createTokenValidator(audience);
1524
+ return new GcpIapProvider({
1525
+ authHandler,
1526
+ signInResolver,
1527
+ tokenValidator,
1528
+ resolverContext,
1529
+ jwtHeader
1530
+ });
1531
+ };
1350
1532
  }
1351
1533
  });
1352
1534
 
1353
- const github = createAuthProviderIntegration({
1354
- create(options) {
1355
- var _a;
1356
- const authHandler = options == null ? void 0 : options.authHandler;
1357
- const signInResolver = (_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver;
1358
- return pluginAuthNode.createOAuthProviderFactory({
1359
- authenticator: pluginAuthBackendModuleGithubProvider.githubAuthenticator,
1360
- profileTransform: authHandler && (async (result, ctx) => authHandler(
1361
- {
1362
- fullProfile: result.fullProfile,
1363
- accessToken: result.session.accessToken,
1364
- params: {
1365
- scope: result.session.scope,
1366
- expires_in: result.session.expiresInSeconds ? String(result.session.expiresInSeconds) : "",
1367
- refresh_token_expires_in: result.session.refreshTokenExpiresInSeconds ? String(result.session.refreshTokenExpiresInSeconds) : ""
1368
- }
1369
- },
1370
- ctx
1371
- )),
1372
- signInResolver: signInResolver && (async ({ profile, result }, ctx) => signInResolver(
1535
+ const BACKSTAGE_SESSION_EXPIRATION = 3600;
1536
+
1537
+ var __defProp$e = Object.defineProperty;
1538
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1539
+ var __publicField$e = (obj, key, value) => {
1540
+ __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
1541
+ return value;
1542
+ };
1543
+ const ACCESS_TOKEN_PREFIX = "access-token.";
1544
+ class GithubAuthProvider {
1545
+ constructor(options) {
1546
+ __publicField$e(this, "_strategy");
1547
+ __publicField$e(this, "signInResolver");
1548
+ __publicField$e(this, "authHandler");
1549
+ __publicField$e(this, "resolverContext");
1550
+ __publicField$e(this, "stateEncoder");
1551
+ this.signInResolver = options.signInResolver;
1552
+ this.authHandler = options.authHandler;
1553
+ this.stateEncoder = options.stateEncoder;
1554
+ this.resolverContext = options.resolverContext;
1555
+ this._strategy = new passportGithub2.Strategy(
1556
+ {
1557
+ clientID: options.clientId,
1558
+ clientSecret: options.clientSecret,
1559
+ callbackURL: options.callbackUrl,
1560
+ tokenURL: options.tokenUrl,
1561
+ userProfileURL: options.userProfileUrl,
1562
+ authorizationURL: options.authorizationUrl
1563
+ },
1564
+ (accessToken, refreshToken, params, fullProfile, done) => {
1565
+ done(void 0, { fullProfile, params, accessToken }, { refreshToken });
1566
+ }
1567
+ );
1568
+ }
1569
+ async start(req) {
1570
+ return await executeRedirectStrategy(req, this._strategy, {
1571
+ scope: req.scope,
1572
+ state: (await this.stateEncoder(req)).encodedState
1573
+ });
1574
+ }
1575
+ async handler(req) {
1576
+ const { result, privateInfo } = await executeFrameHandlerStrategy(req, this._strategy);
1577
+ let refreshToken = privateInfo.refreshToken;
1578
+ if (!refreshToken && !result.params.expires_in) {
1579
+ refreshToken = ACCESS_TOKEN_PREFIX + result.accessToken;
1580
+ }
1581
+ return {
1582
+ response: await this.handleResult(result),
1583
+ refreshToken
1584
+ };
1585
+ }
1586
+ async refresh(req) {
1587
+ const { scope, refreshToken } = req;
1588
+ if (refreshToken == null ? void 0 : refreshToken.startsWith(ACCESS_TOKEN_PREFIX)) {
1589
+ const accessToken = refreshToken.slice(ACCESS_TOKEN_PREFIX.length);
1590
+ const fullProfile = await executeFetchUserProfileStrategy(
1591
+ this._strategy,
1592
+ accessToken
1593
+ ).catch((error) => {
1594
+ var _a;
1595
+ if (((_a = error.oauthError) == null ? void 0 : _a.statusCode) === 401) {
1596
+ throw new Error("Invalid access token");
1597
+ }
1598
+ throw error;
1599
+ });
1600
+ return {
1601
+ response: await this.handleResult({
1602
+ fullProfile,
1603
+ params: { scope },
1604
+ accessToken
1605
+ }),
1606
+ refreshToken
1607
+ };
1608
+ }
1609
+ const result = await executeRefreshTokenStrategy(
1610
+ this._strategy,
1611
+ refreshToken,
1612
+ scope
1613
+ );
1614
+ return {
1615
+ response: await this.handleResult({
1616
+ fullProfile: await executeFetchUserProfileStrategy(
1617
+ this._strategy,
1618
+ result.accessToken
1619
+ ),
1620
+ params: { ...result.params, scope },
1621
+ accessToken: result.accessToken
1622
+ }),
1623
+ refreshToken: result.refreshToken
1624
+ };
1625
+ }
1626
+ async handleResult(result) {
1627
+ const { profile } = await this.authHandler(result, this.resolverContext);
1628
+ const expiresInStr = result.params.expires_in;
1629
+ let expiresInSeconds = expiresInStr === void 0 ? void 0 : Number(expiresInStr);
1630
+ let backstageIdentity = void 0;
1631
+ if (this.signInResolver) {
1632
+ backstageIdentity = await this.signInResolver(
1373
1633
  {
1374
- profile,
1375
- result: {
1376
- fullProfile: result.fullProfile,
1377
- accessToken: result.session.accessToken,
1378
- refreshToken: result.session.refreshToken,
1379
- params: {
1380
- scope: result.session.scope,
1381
- expires_in: result.session.expiresInSeconds ? String(result.session.expiresInSeconds) : "",
1382
- refresh_token_expires_in: result.session.refreshTokenExpiresInSeconds ? String(result.session.refreshTokenExpiresInSeconds) : ""
1383
- }
1384
- }
1634
+ result,
1635
+ profile
1385
1636
  },
1386
- ctx
1387
- ))
1637
+ this.resolverContext
1638
+ );
1639
+ if (expiresInSeconds) {
1640
+ expiresInSeconds = Math.min(
1641
+ expiresInSeconds,
1642
+ BACKSTAGE_SESSION_EXPIRATION
1643
+ );
1644
+ } else {
1645
+ expiresInSeconds = BACKSTAGE_SESSION_EXPIRATION;
1646
+ }
1647
+ }
1648
+ return {
1649
+ backstageIdentity,
1650
+ providerInfo: {
1651
+ accessToken: result.accessToken,
1652
+ scope: result.params.scope,
1653
+ expiresInSeconds
1654
+ },
1655
+ profile
1656
+ };
1657
+ }
1658
+ }
1659
+ const github = createAuthProviderIntegration({
1660
+ create(options) {
1661
+ return ({ providerId, globalConfig, config, resolverContext }) => OAuthEnvironmentHandler.mapConfig(config, (envConfig) => {
1662
+ var _a, _b, _c;
1663
+ const clientId = envConfig.getString("clientId");
1664
+ const clientSecret = envConfig.getString("clientSecret");
1665
+ const enterpriseInstanceUrl = (_a = envConfig.getOptionalString("enterpriseInstanceUrl")) == null ? void 0 : _a.replace(/\/$/, "");
1666
+ const customCallbackUrl = envConfig.getOptionalString("callbackUrl");
1667
+ const authorizationUrl = enterpriseInstanceUrl ? `${enterpriseInstanceUrl}/login/oauth/authorize` : void 0;
1668
+ const tokenUrl = enterpriseInstanceUrl ? `${enterpriseInstanceUrl}/login/oauth/access_token` : void 0;
1669
+ const userProfileUrl = enterpriseInstanceUrl ? `${enterpriseInstanceUrl}/api/v3/user` : void 0;
1670
+ const callbackUrl = customCallbackUrl || `${globalConfig.baseUrl}/${providerId}/handler/frame`;
1671
+ const authHandler = (options == null ? void 0 : options.authHandler) ? options.authHandler : async ({ fullProfile }) => ({
1672
+ profile: makeProfileInfo(fullProfile)
1673
+ });
1674
+ const stateEncoder = (_b = options == null ? void 0 : options.stateEncoder) != null ? _b : async (req) => {
1675
+ return { encodedState: encodeState(req.state) };
1676
+ };
1677
+ const provider = new GithubAuthProvider({
1678
+ clientId,
1679
+ clientSecret,
1680
+ callbackUrl,
1681
+ tokenUrl,
1682
+ userProfileUrl,
1683
+ authorizationUrl,
1684
+ signInResolver: (_c = options == null ? void 0 : options.signIn) == null ? void 0 : _c.resolver,
1685
+ authHandler,
1686
+ stateEncoder,
1687
+ resolverContext
1688
+ });
1689
+ return OAuthAdapter.fromConfig(globalConfig, provider, {
1690
+ persistScopes: true,
1691
+ providerId,
1692
+ callbackUrl
1693
+ });
1388
1694
  });
1389
1695
  },
1390
1696
  resolvers: {
@@ -1404,10 +1710,10 @@ const github = createAuthProviderIntegration({
1404
1710
  }
1405
1711
  });
1406
1712
 
1407
- var __defProp$c = Object.defineProperty;
1408
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1409
- var __publicField$c = (obj, key, value) => {
1410
- __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
1713
+ var __defProp$d = Object.defineProperty;
1714
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1715
+ var __publicField$d = (obj, key, value) => {
1716
+ __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
1411
1717
  return value;
1412
1718
  };
1413
1719
  const gitlabDefaultAuthHandler = async ({
@@ -1418,10 +1724,10 @@ const gitlabDefaultAuthHandler = async ({
1418
1724
  });
1419
1725
  class GitlabAuthProvider {
1420
1726
  constructor(options) {
1421
- __publicField$c(this, "_strategy");
1422
- __publicField$c(this, "signInResolver");
1423
- __publicField$c(this, "authHandler");
1424
- __publicField$c(this, "resolverContext");
1727
+ __publicField$d(this, "_strategy");
1728
+ __publicField$d(this, "signInResolver");
1729
+ __publicField$d(this, "authHandler");
1730
+ __publicField$d(this, "resolverContext");
1425
1731
  this.resolverContext = options.resolverContext;
1426
1732
  this.authHandler = options.authHandler;
1427
1733
  this.signInResolver = options.signInResolver;
@@ -1529,88 +1835,158 @@ const gitlab = createAuthProviderIntegration({
1529
1835
  }
1530
1836
  });
1531
1837
 
1532
- function adaptLegacyOAuthHandler(authHandler) {
1533
- return authHandler && (async (result, ctx) => authHandler(
1534
- {
1535
- fullProfile: result.fullProfile,
1536
- accessToken: result.session.accessToken,
1537
- params: {
1538
- scope: result.session.scope,
1539
- id_token: result.session.idToken,
1540
- token_type: result.session.tokenType,
1541
- expires_in: result.session.expiresInSeconds
1542
- }
1543
- },
1544
- ctx
1545
- ));
1546
- }
1547
-
1548
- function adaptLegacyOAuthSignInResolver(signInResolver) {
1549
- return signInResolver && (async (input, ctx) => signInResolver(
1550
- {
1551
- profile: input.profile,
1552
- result: {
1553
- fullProfile: input.result.fullProfile,
1554
- accessToken: input.result.session.accessToken,
1555
- refreshToken: input.result.session.refreshToken,
1556
- params: {
1557
- scope: input.result.session.scope,
1558
- id_token: input.result.session.idToken,
1559
- token_type: input.result.session.tokenType,
1560
- expires_in: input.result.session.expiresInSeconds
1561
- }
1838
+ var __defProp$c = Object.defineProperty;
1839
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1840
+ var __publicField$c = (obj, key, value) => {
1841
+ __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
1842
+ return value;
1843
+ };
1844
+ class GoogleAuthProvider {
1845
+ constructor(options) {
1846
+ __publicField$c(this, "strategy");
1847
+ __publicField$c(this, "signInResolver");
1848
+ __publicField$c(this, "authHandler");
1849
+ __publicField$c(this, "resolverContext");
1850
+ this.authHandler = options.authHandler;
1851
+ this.signInResolver = options.signInResolver;
1852
+ this.resolverContext = options.resolverContext;
1853
+ this.strategy = new passportGoogleOauth20.Strategy(
1854
+ {
1855
+ clientID: options.clientId,
1856
+ clientSecret: options.clientSecret,
1857
+ callbackURL: options.callbackUrl,
1858
+ passReqToCallback: false
1859
+ },
1860
+ (accessToken, refreshToken, params, fullProfile, done) => {
1861
+ done(
1862
+ void 0,
1863
+ {
1864
+ fullProfile,
1865
+ params,
1866
+ accessToken,
1867
+ refreshToken
1868
+ },
1869
+ {
1870
+ refreshToken
1871
+ }
1872
+ );
1562
1873
  }
1563
- },
1564
- ctx
1565
- ));
1566
- }
1567
-
1568
- function adaptOAuthSignInResolverToLegacy(resolvers) {
1569
- const legacyResolvers = {};
1570
- for (const name of Object.keys(resolvers)) {
1571
- const resolver = resolvers[name];
1572
- legacyResolvers[name] = () => async (input, ctx) => {
1573
- var _a;
1574
- return resolver(
1874
+ );
1875
+ }
1876
+ async start(req) {
1877
+ return await executeRedirectStrategy(req, this.strategy, {
1878
+ accessType: "offline",
1879
+ prompt: "consent",
1880
+ scope: req.scope,
1881
+ state: encodeState(req.state)
1882
+ });
1883
+ }
1884
+ async handler(req) {
1885
+ const { result, privateInfo } = await executeFrameHandlerStrategy(req, this.strategy);
1886
+ return {
1887
+ response: await this.handleResult(result),
1888
+ refreshToken: privateInfo.refreshToken
1889
+ };
1890
+ }
1891
+ async logout(req) {
1892
+ const oauthClient = new googleAuthLibrary.OAuth2Client();
1893
+ await oauthClient.revokeToken(req.refreshToken);
1894
+ }
1895
+ async refresh(req) {
1896
+ const { accessToken, refreshToken, params } = await executeRefreshTokenStrategy(
1897
+ this.strategy,
1898
+ req.refreshToken,
1899
+ req.scope
1900
+ );
1901
+ const fullProfile = await executeFetchUserProfileStrategy(
1902
+ this.strategy,
1903
+ accessToken
1904
+ );
1905
+ return {
1906
+ response: await this.handleResult({
1907
+ fullProfile,
1908
+ params,
1909
+ accessToken
1910
+ }),
1911
+ refreshToken
1912
+ };
1913
+ }
1914
+ async handleResult(result) {
1915
+ const { profile } = await this.authHandler(result, this.resolverContext);
1916
+ const response = {
1917
+ providerInfo: {
1918
+ idToken: result.params.id_token,
1919
+ accessToken: result.accessToken,
1920
+ scope: result.params.scope,
1921
+ expiresInSeconds: result.params.expires_in
1922
+ },
1923
+ profile
1924
+ };
1925
+ if (this.signInResolver) {
1926
+ response.backstageIdentity = await this.signInResolver(
1575
1927
  {
1576
- profile: input.profile,
1577
- result: {
1578
- fullProfile: input.result.fullProfile,
1579
- session: {
1580
- accessToken: input.result.accessToken,
1581
- expiresInSeconds: input.result.params.expires_in,
1582
- scope: input.result.params.scope,
1583
- idToken: input.result.params.id_token,
1584
- tokenType: (_a = input.result.params.token_type) != null ? _a : "bearer",
1585
- refreshToken: input.result.refreshToken
1586
- }
1587
- }
1928
+ result,
1929
+ profile
1588
1930
  },
1589
- ctx
1931
+ this.resolverContext
1590
1932
  );
1591
- };
1933
+ }
1934
+ return response;
1592
1935
  }
1593
- return legacyResolvers;
1594
1936
  }
1595
-
1596
1937
  const google = createAuthProviderIntegration({
1597
1938
  create(options) {
1598
- var _a;
1599
- return pluginAuthNode.createOAuthProviderFactory({
1600
- authenticator: pluginAuthBackendModuleGoogleProvider.googleAuthenticator,
1601
- profileTransform: adaptLegacyOAuthHandler(options == null ? void 0 : options.authHandler),
1602
- signInResolver: adaptLegacyOAuthSignInResolver((_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver)
1939
+ return ({ providerId, globalConfig, config, resolverContext }) => OAuthEnvironmentHandler.mapConfig(config, (envConfig) => {
1940
+ var _a;
1941
+ const clientId = envConfig.getString("clientId");
1942
+ const clientSecret = envConfig.getString("clientSecret");
1943
+ const customCallbackUrl = envConfig.getOptionalString("callbackUrl");
1944
+ const callbackUrl = customCallbackUrl || `${globalConfig.baseUrl}/${providerId}/handler/frame`;
1945
+ const authHandler = (options == null ? void 0 : options.authHandler) ? options.authHandler : async ({ fullProfile, params }) => ({
1946
+ profile: makeProfileInfo(fullProfile, params.id_token)
1947
+ });
1948
+ const provider = new GoogleAuthProvider({
1949
+ clientId,
1950
+ clientSecret,
1951
+ callbackUrl,
1952
+ signInResolver: (_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver,
1953
+ authHandler,
1954
+ resolverContext
1955
+ });
1956
+ return OAuthAdapter.fromConfig(globalConfig, provider, {
1957
+ providerId,
1958
+ callbackUrl
1959
+ });
1603
1960
  });
1604
1961
  },
1605
- resolvers: adaptOAuthSignInResolverToLegacy({
1606
- emailLocalPartMatchingUserEntityName: pluginAuthNode.commonSignInResolvers.emailLocalPartMatchingUserEntityName(),
1607
- emailMatchingUserEntityProfileEmail: pluginAuthNode.commonSignInResolvers.emailMatchingUserEntityProfileEmail(),
1608
- emailMatchingUserEntityAnnotation: pluginAuthBackendModuleGoogleProvider.googleSignInResolvers.emailMatchingUserEntityAnnotation()
1609
- })
1962
+ resolvers: {
1963
+ /**
1964
+ * Looks up the user by matching their email local part to the entity name.
1965
+ */
1966
+ emailLocalPartMatchingUserEntityName: () => commonByEmailLocalPartResolver,
1967
+ /**
1968
+ * Looks up the user by matching their email to the entity email.
1969
+ */
1970
+ emailMatchingUserEntityProfileEmail: () => commonByEmailResolver,
1971
+ /**
1972
+ * Looks up the user by matching their email to the `google.com/email` annotation.
1973
+ */
1974
+ emailMatchingUserEntityAnnotation() {
1975
+ return async (info, ctx) => {
1976
+ const { profile } = info;
1977
+ if (!profile.email) {
1978
+ throw new Error("Google profile contained no email");
1979
+ }
1980
+ return ctx.signInWithCatalogUser({
1981
+ annotations: {
1982
+ "google.com/email": profile.email
1983
+ }
1984
+ });
1985
+ };
1986
+ }
1987
+ }
1610
1988
  });
1611
1989
 
1612
- const BACKSTAGE_SESSION_EXPIRATION = 3600;
1613
-
1614
1990
  var __defProp$b = Object.defineProperty;
1615
1991
  var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1616
1992
  var __publicField$b = (obj, key, value) => {
@@ -3497,7 +3873,7 @@ async function createRouter(options) {
3497
3873
  database,
3498
3874
  tokenManager,
3499
3875
  tokenFactoryAlgorithm,
3500
- providerFactories = {},
3876
+ providerFactories,
3501
3877
  catalogApi
3502
3878
  } = options;
3503
3879
  const router = Router__default["default"]();
@@ -3514,7 +3890,7 @@ async function createRouter(options) {
3514
3890
  keyStore,
3515
3891
  keyDurationSeconds,
3516
3892
  logger: logger.child({ component: "token-factory" }),
3517
- algorithm: tokenFactoryAlgorithm != null ? tokenFactoryAlgorithm : config.getOptionalString("auth.identityTokenAlgorithm")
3893
+ algorithm: tokenFactoryAlgorithm
3518
3894
  });
3519
3895
  const secret = config.getOptionalString("auth.session.secret");
3520
3896
  if (secret) {
@@ -3540,23 +3916,21 @@ async function createRouter(options) {
3540
3916
  }
3541
3917
  router.use(express__default["default"].urlencoded({ extended: false }));
3542
3918
  router.use(express__default["default"].json());
3543
- const allProviderFactories = options.disableDefaultProviderFactories ? providerFactories : {
3919
+ const allProviderFactories = {
3544
3920
  ...defaultAuthProviderFactories,
3545
3921
  ...providerFactories
3546
3922
  };
3547
- const providersConfig = config.getOptionalConfig("auth.providers");
3923
+ const providersConfig = config.getConfig("auth.providers");
3924
+ const configuredProviders = providersConfig.keys();
3548
3925
  const isOriginAllowed = createOriginFilter(config);
3549
3926
  for (const [providerId, providerFactory] of Object.entries(
3550
3927
  allProviderFactories
3551
3928
  )) {
3552
- if (providersConfig == null ? void 0 : providersConfig.has(providerId)) {
3929
+ if (configuredProviders.includes(providerId)) {
3553
3930
  logger.info(`Configuring auth provider: ${providerId}`);
3554
3931
  try {
3555
3932
  const provider = providerFactory({
3556
3933
  providerId,
3557
- appUrl,
3558
- baseUrl: authUrl,
3559
- isOriginAllowed,
3560
3934
  globalConfig: {
3561
3935
  baseUrl: authUrl,
3562
3936
  appUrl,
@@ -3635,59 +4009,9 @@ function createOriginFilter(config) {
3635
4009
  };
3636
4010
  }
3637
4011
 
3638
- const authPlugin = backendPluginApi.createBackendPlugin({
3639
- pluginId: "auth",
3640
- register(reg) {
3641
- const providers = /* @__PURE__ */ new Map();
3642
- reg.registerExtensionPoint(pluginAuthNode.authProvidersExtensionPoint, {
3643
- registerProvider({ providerId, factory }) {
3644
- if (providers.has(providerId)) {
3645
- throw new Error(
3646
- `Auth provider '${providerId}' was already registered`
3647
- );
3648
- }
3649
- providers.set(providerId, factory);
3650
- }
3651
- });
3652
- reg.registerInit({
3653
- deps: {
3654
- httpRouter: backendPluginApi.coreServices.httpRouter,
3655
- logger: backendPluginApi.coreServices.logger,
3656
- config: backendPluginApi.coreServices.rootConfig,
3657
- database: backendPluginApi.coreServices.database,
3658
- discovery: backendPluginApi.coreServices.discovery,
3659
- tokenManager: backendPluginApi.coreServices.tokenManager,
3660
- catalogApi: alpha.catalogServiceRef
3661
- },
3662
- async init({
3663
- httpRouter,
3664
- logger,
3665
- config,
3666
- database,
3667
- discovery,
3668
- tokenManager,
3669
- catalogApi
3670
- }) {
3671
- const router = await createRouter({
3672
- logger,
3673
- config,
3674
- database,
3675
- discovery,
3676
- tokenManager,
3677
- catalogApi,
3678
- providerFactories: Object.fromEntries(providers),
3679
- disableDefaultProviderFactories: true
3680
- });
3681
- httpRouter.use(router);
3682
- }
3683
- });
3684
- }
3685
- });
3686
-
3687
4012
  exports.CatalogIdentityClient = CatalogIdentityClient;
3688
4013
  exports.OAuthAdapter = OAuthAdapter;
3689
4014
  exports.OAuthEnvironmentHandler = OAuthEnvironmentHandler;
3690
- exports.authPlugin = authPlugin;
3691
4015
  exports.createAuthProviderIntegration = createAuthProviderIntegration;
3692
4016
  exports.createOriginFilter = createOriginFilter;
3693
4017
  exports.createRouter = createRouter;