@backstage/plugin-auth-backend 0.20.3-next.2 → 0.20.4-next.0

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
@@ -22,10 +22,10 @@ var pluginAuthBackendModuleGcpIapProvider = require('@backstage/plugin-auth-back
22
22
  var pluginAuthBackendModuleGithubProvider = require('@backstage/plugin-auth-backend-module-github-provider');
23
23
  var pluginAuthBackendModuleGitlabProvider = require('@backstage/plugin-auth-backend-module-gitlab-provider');
24
24
  var pluginAuthBackendModuleGoogleProvider = require('@backstage/plugin-auth-backend-module-google-provider');
25
- var passportMicrosoft = require('passport-microsoft');
25
+ var pluginAuthBackendModuleMicrosoftProvider = require('@backstage/plugin-auth-backend-module-microsoft-provider');
26
26
  var pluginAuthBackendModuleOauth2Provider = require('@backstage/plugin-auth-backend-module-oauth2-provider');
27
27
  var pluginAuthBackendModuleOauth2ProxyProvider = require('@backstage/plugin-auth-backend-module-oauth2-proxy-provider');
28
- var openidClient = require('openid-client');
28
+ var pluginAuthBackendModuleOidcProvider = require('@backstage/plugin-auth-backend-module-oidc-provider');
29
29
  var pluginAuthBackendModuleOktaProvider = require('@backstage/plugin-auth-backend-module-okta-provider');
30
30
  var passportOneloginOauth = require('passport-onelogin-oauth');
31
31
  var passportSaml = require('passport-saml');
@@ -240,10 +240,10 @@ const ensuresXRequestedWith = (req) => {
240
240
 
241
241
  const prepareBackstageIdentityResponse = pluginAuthNode.prepareBackstageIdentityResponse;
242
242
 
243
- var __defProp$f = Object.defineProperty;
244
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
245
- var __publicField$f = (obj, key, value) => {
246
- __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
243
+ var __defProp$d = Object.defineProperty;
244
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
245
+ var __publicField$d = (obj, key, value) => {
246
+ __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
247
247
  return value;
248
248
  };
249
249
  const THOUSAND_DAYS_MS = 1e3 * 24 * 60 * 60 * 1e3;
@@ -252,8 +252,8 @@ class OAuthAdapter {
252
252
  constructor(handlers, options) {
253
253
  this.handlers = handlers;
254
254
  this.options = options;
255
- __publicField$f(this, "baseCookieOptions");
256
- __publicField$f(this, "setNonceCookie", (res, nonce, cookieConfig) => {
255
+ __publicField$d(this, "baseCookieOptions");
256
+ __publicField$d(this, "setNonceCookie", (res, nonce, cookieConfig) => {
257
257
  res.cookie(`${this.options.providerId}-nonce`, nonce, {
258
258
  maxAge: TEN_MINUTES_MS,
259
259
  ...this.baseCookieOptions,
@@ -261,34 +261,34 @@ class OAuthAdapter {
261
261
  path: `${cookieConfig.path}/handler`
262
262
  });
263
263
  });
264
- __publicField$f(this, "setGrantedScopeCookie", (res, scope, cookieConfig) => {
264
+ __publicField$d(this, "setGrantedScopeCookie", (res, scope, cookieConfig) => {
265
265
  res.cookie(`${this.options.providerId}-granted-scope`, scope, {
266
266
  maxAge: THOUSAND_DAYS_MS,
267
267
  ...this.baseCookieOptions,
268
268
  ...cookieConfig
269
269
  });
270
270
  });
271
- __publicField$f(this, "getRefreshTokenFromCookie", (req) => {
271
+ __publicField$d(this, "getRefreshTokenFromCookie", (req) => {
272
272
  return req.cookies[`${this.options.providerId}-refresh-token`];
273
273
  });
274
- __publicField$f(this, "getGrantedScopeFromCookie", (req) => {
274
+ __publicField$d(this, "getGrantedScopeFromCookie", (req) => {
275
275
  return req.cookies[`${this.options.providerId}-granted-scope`];
276
276
  });
277
- __publicField$f(this, "setRefreshTokenCookie", (res, refreshToken, cookieConfig) => {
277
+ __publicField$d(this, "setRefreshTokenCookie", (res, refreshToken, cookieConfig) => {
278
278
  res.cookie(`${this.options.providerId}-refresh-token`, refreshToken, {
279
279
  maxAge: THOUSAND_DAYS_MS,
280
280
  ...this.baseCookieOptions,
281
281
  ...cookieConfig
282
282
  });
283
283
  });
284
- __publicField$f(this, "removeRefreshTokenCookie", (res, cookieConfig) => {
284
+ __publicField$d(this, "removeRefreshTokenCookie", (res, cookieConfig) => {
285
285
  res.cookie(`${this.options.providerId}-refresh-token`, "", {
286
286
  maxAge: 0,
287
287
  ...this.baseCookieOptions,
288
288
  ...cookieConfig
289
289
  });
290
290
  });
291
- __publicField$f(this, "getCookieConfig", (origin) => {
291
+ __publicField$d(this, "getCookieConfig", (origin) => {
292
292
  return this.options.cookieConfigurer({
293
293
  providerId: this.options.providerId,
294
294
  baseUrl: this.options.baseUrl,
@@ -586,21 +586,21 @@ const executeFetchUserProfileStrategy = async (providerStrategy, accessToken) =>
586
586
  });
587
587
  };
588
588
 
589
- var __defProp$e = Object.defineProperty;
590
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
591
- var __publicField$e = (obj, key, value) => {
592
- __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
589
+ var __defProp$c = Object.defineProperty;
590
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
591
+ var __publicField$c = (obj, key, value) => {
592
+ __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
593
593
  return value;
594
594
  };
595
595
  class Auth0AuthProvider {
596
596
  constructor(options) {
597
- __publicField$e(this, "_strategy");
598
- __publicField$e(this, "signInResolver");
599
- __publicField$e(this, "authHandler");
600
- __publicField$e(this, "resolverContext");
601
- __publicField$e(this, "audience");
602
- __publicField$e(this, "connection");
603
- __publicField$e(this, "connectionScope");
597
+ __publicField$c(this, "_strategy");
598
+ __publicField$c(this, "signInResolver");
599
+ __publicField$c(this, "authHandler");
600
+ __publicField$c(this, "resolverContext");
601
+ __publicField$c(this, "audience");
602
+ __publicField$c(this, "connection");
603
+ __publicField$c(this, "connectionScope");
604
604
  /**
605
605
  * Due to passport-auth0 forcing options.state = true,
606
606
  * passport-oauth2 requires express-session to be installed
@@ -609,7 +609,7 @@ class Auth0AuthProvider {
609
609
  * passport-oauth2, which is the StateStore implementation used when options.state = false,
610
610
  * allowing us to avoid using express-session in order to integrate with auth0.
611
611
  */
612
- __publicField$e(this, "store", {
612
+ __publicField$c(this, "store", {
613
613
  store(_req, cb) {
614
614
  cb(null, null);
615
615
  },
@@ -750,23 +750,23 @@ const auth0 = createAuthProviderIntegration({
750
750
  }
751
751
  });
752
752
 
753
- var __defProp$d = Object.defineProperty;
754
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
755
- var __publicField$d = (obj, key, value) => {
756
- __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
753
+ var __defProp$b = Object.defineProperty;
754
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
755
+ var __publicField$b = (obj, key, value) => {
756
+ __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
757
757
  return value;
758
758
  };
759
759
  const ALB_JWT_HEADER = "x-amzn-oidc-data";
760
760
  const ALB_ACCESS_TOKEN_HEADER = "x-amzn-oidc-accesstoken";
761
761
  class AwsAlbAuthProvider {
762
762
  constructor(options) {
763
- __publicField$d(this, "region");
764
- __publicField$d(this, "issuer");
765
- __publicField$d(this, "resolverContext");
766
- __publicField$d(this, "keyCache");
767
- __publicField$d(this, "authHandler");
768
- __publicField$d(this, "signInResolver");
769
- __publicField$d(this, "getKey", async (header) => {
763
+ __publicField$b(this, "region");
764
+ __publicField$b(this, "issuer");
765
+ __publicField$b(this, "resolverContext");
766
+ __publicField$b(this, "keyCache");
767
+ __publicField$b(this, "authHandler");
768
+ __publicField$b(this, "signInResolver");
769
+ __publicField$b(this, "getKey", async (header) => {
770
770
  if (!header.kid) {
771
771
  throw new errors.AuthenticationError("No key id was specified in header");
772
772
  }
@@ -894,18 +894,18 @@ const awsAlb = createAuthProviderIntegration({
894
894
  }
895
895
  });
896
896
 
897
- var __defProp$c = Object.defineProperty;
898
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
899
- var __publicField$c = (obj, key, value) => {
900
- __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
897
+ var __defProp$a = Object.defineProperty;
898
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
899
+ var __publicField$a = (obj, key, value) => {
900
+ __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
901
901
  return value;
902
902
  };
903
903
  class BitbucketAuthProvider {
904
904
  constructor(options) {
905
- __publicField$c(this, "_strategy");
906
- __publicField$c(this, "signInResolver");
907
- __publicField$c(this, "authHandler");
908
- __publicField$c(this, "resolverContext");
905
+ __publicField$a(this, "_strategy");
906
+ __publicField$a(this, "signInResolver");
907
+ __publicField$a(this, "authHandler");
908
+ __publicField$a(this, "resolverContext");
909
909
  this.signInResolver = options.signInResolver;
910
910
  this.authHandler = options.authHandler;
911
911
  this.resolverContext = options.resolverContext;
@@ -1073,10 +1073,10 @@ const commonByEmailResolver = async (info, ctx) => {
1073
1073
  });
1074
1074
  };
1075
1075
 
1076
- var __defProp$b = Object.defineProperty;
1077
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1078
- var __publicField$b = (obj, key, value) => {
1079
- __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
1076
+ var __defProp$9 = Object.defineProperty;
1077
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1078
+ var __publicField$9 = (obj, key, value) => {
1079
+ __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
1080
1080
  return value;
1081
1081
  };
1082
1082
  const CF_JWT_HEADER = "cf-access-jwt-assertion";
@@ -1084,12 +1084,12 @@ const COOKIE_AUTH_NAME = "CF_Authorization";
1084
1084
  const CACHE_PREFIX = "providers/cloudflare-access/profile-v1";
1085
1085
  class CloudflareAccessAuthProvider {
1086
1086
  constructor(options) {
1087
- __publicField$b(this, "teamName");
1088
- __publicField$b(this, "resolverContext");
1089
- __publicField$b(this, "authHandler");
1090
- __publicField$b(this, "signInResolver");
1091
- __publicField$b(this, "jwtKeySet");
1092
- __publicField$b(this, "cache");
1087
+ __publicField$9(this, "teamName");
1088
+ __publicField$9(this, "resolverContext");
1089
+ __publicField$9(this, "authHandler");
1090
+ __publicField$9(this, "signInResolver");
1091
+ __publicField$9(this, "jwtKeySet");
1092
+ __publicField$9(this, "cache");
1093
1093
  this.teamName = options.teamName;
1094
1094
  this.authHandler = options.authHandler;
1095
1095
  this.signInResolver = options.signInResolver;
@@ -1319,184 +1319,20 @@ const google = createAuthProviderIntegration({
1319
1319
  })
1320
1320
  });
1321
1321
 
1322
- const BACKSTAGE_SESSION_EXPIRATION = 3600;
1323
-
1324
- var __defProp$a = Object.defineProperty;
1325
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1326
- var __publicField$a = (obj, key, value) => {
1327
- __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
1328
- return value;
1329
- };
1330
- class MicrosoftAuthProvider {
1331
- constructor(options) {
1332
- __publicField$a(this, "_strategy");
1333
- __publicField$a(this, "signInResolver");
1334
- __publicField$a(this, "authHandler");
1335
- __publicField$a(this, "logger");
1336
- __publicField$a(this, "resolverContext");
1337
- __publicField$a(this, "skipUserProfile", (accessToken) => {
1338
- const { aud, scp } = jose.decodeJwt(accessToken);
1339
- const hasGraphReadScope = aud === "00000003-0000-0000-c000-000000000000" && scp.split(" ").map((s) => s.toLowerCase()).includes("user.read");
1340
- return !hasGraphReadScope;
1341
- });
1342
- this.signInResolver = options.signInResolver;
1343
- this.authHandler = options.authHandler;
1344
- this.logger = options.logger;
1345
- this.resolverContext = options.resolverContext;
1346
- this._strategy = new passportMicrosoft.Strategy(
1347
- {
1348
- clientID: options.clientId,
1349
- clientSecret: options.clientSecret,
1350
- callbackURL: options.callbackUrl,
1351
- authorizationURL: options.authorizationUrl,
1352
- tokenURL: options.tokenUrl,
1353
- passReqToCallback: false,
1354
- skipUserProfile: (accessToken, done) => {
1355
- done(null, this.skipUserProfile(accessToken));
1356
- }
1357
- },
1358
- (accessToken, refreshToken, params, fullProfile, done) => {
1359
- done(void 0, { fullProfile, accessToken, params }, { refreshToken });
1360
- }
1361
- );
1362
- }
1363
- async start(req) {
1364
- return await executeRedirectStrategy(req, this._strategy, {
1365
- scope: req.scope,
1366
- state: encodeState(req.state)
1367
- });
1368
- }
1369
- async handler(req) {
1370
- const { result, privateInfo } = await executeFrameHandlerStrategy(req, this._strategy);
1371
- return {
1372
- response: await this.handleResult(result),
1373
- refreshToken: privateInfo.refreshToken
1374
- };
1375
- }
1376
- async refresh(req) {
1377
- const { accessToken, refreshToken, params } = await executeRefreshTokenStrategy(
1378
- this._strategy,
1379
- req.refreshToken,
1380
- req.scope
1381
- );
1382
- return {
1383
- response: await this.handleResult({
1384
- params,
1385
- accessToken,
1386
- ...!this.skipUserProfile(accessToken) && {
1387
- fullProfile: await executeFetchUserProfileStrategy(
1388
- this._strategy,
1389
- accessToken
1390
- )
1391
- }
1392
- }),
1393
- refreshToken
1394
- };
1395
- }
1396
- async handleResult(result) {
1397
- let profile = {};
1398
- if (result.fullProfile) {
1399
- const photo = await this.getUserPhoto(result.accessToken);
1400
- result.fullProfile.photos = photo ? [{ value: photo }] : void 0;
1401
- ({ profile } = await this.authHandler(
1402
- result,
1403
- this.resolverContext
1404
- ));
1405
- }
1406
- const expiresInSeconds = result.params.expires_in === void 0 ? BACKSTAGE_SESSION_EXPIRATION : Math.min(result.params.expires_in, BACKSTAGE_SESSION_EXPIRATION);
1407
- return {
1408
- providerInfo: {
1409
- accessToken: result.accessToken,
1410
- scope: result.params.scope,
1411
- expiresInSeconds,
1412
- ...{ idToken: result.params.id_token }
1413
- },
1414
- profile,
1415
- ...result.fullProfile && this.signInResolver && {
1416
- backstageIdentity: await this.signInResolver(
1417
- { result, profile },
1418
- this.resolverContext
1419
- )
1420
- }
1421
- };
1422
- }
1423
- async getUserPhoto(accessToken) {
1424
- try {
1425
- const res = await fetch__default["default"](
1426
- "https://graph.microsoft.com/v1.0/me/photos/48x48/$value",
1427
- {
1428
- headers: {
1429
- Authorization: `Bearer ${accessToken}`
1430
- }
1431
- }
1432
- );
1433
- const data = await res.buffer();
1434
- return `data:image/jpeg;base64,${data.toString("base64")}`;
1435
- } catch (error) {
1436
- this.logger.warn(
1437
- `Could not retrieve user profile photo from Microsoft Graph API: ${error}`
1438
- );
1439
- return void 0;
1440
- }
1441
- }
1442
- }
1443
1322
  const microsoft = createAuthProviderIntegration({
1444
1323
  create(options) {
1445
- return ({ providerId, globalConfig, config, logger, resolverContext }) => OAuthEnvironmentHandler.mapConfig(config, (envConfig) => {
1446
- var _a;
1447
- const clientId = envConfig.getString("clientId");
1448
- const clientSecret = envConfig.getString("clientSecret");
1449
- const tenantId = envConfig.getString("tenantId");
1450
- const customCallbackUrl = envConfig.getOptionalString("callbackUrl");
1451
- const callbackUrl = customCallbackUrl || `${globalConfig.baseUrl}/${providerId}/handler/frame`;
1452
- const authorizationUrl = `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/authorize`;
1453
- const tokenUrl = `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`;
1454
- const authHandler = (options == null ? void 0 : options.authHandler) ? options.authHandler : async ({ fullProfile, params }) => ({
1455
- profile: makeProfileInfo(fullProfile != null ? fullProfile : {}, params.id_token)
1456
- });
1457
- const provider = new MicrosoftAuthProvider({
1458
- clientId,
1459
- clientSecret,
1460
- callbackUrl,
1461
- authorizationUrl,
1462
- tokenUrl,
1463
- authHandler,
1464
- signInResolver: (_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver,
1465
- logger,
1466
- resolverContext
1467
- });
1468
- return OAuthAdapter.fromConfig(globalConfig, provider, {
1469
- providerId,
1470
- callbackUrl
1471
- });
1324
+ var _a;
1325
+ return pluginAuthNode.createOAuthProviderFactory({
1326
+ authenticator: pluginAuthBackendModuleMicrosoftProvider.microsoftAuthenticator,
1327
+ profileTransform: adaptLegacyOAuthHandler(options == null ? void 0 : options.authHandler),
1328
+ signInResolver: adaptLegacyOAuthSignInResolver((_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver)
1472
1329
  });
1473
1330
  },
1474
- resolvers: {
1475
- /**
1476
- * Looks up the user by matching their email local part to the entity name.
1477
- */
1478
- emailLocalPartMatchingUserEntityName: () => commonByEmailLocalPartResolver,
1479
- /**
1480
- * Looks up the user by matching their email to the entity email.
1481
- */
1482
- emailMatchingUserEntityProfileEmail: () => commonByEmailResolver,
1483
- /**
1484
- * Looks up the user by matching their email to the `microsoft.com/email` annotation.
1485
- */
1486
- emailMatchingUserEntityAnnotation() {
1487
- return async (info, ctx) => {
1488
- const { profile } = info;
1489
- if (!profile.email) {
1490
- throw new Error("Microsoft profile contained no email");
1491
- }
1492
- return ctx.signInWithCatalogUser({
1493
- annotations: {
1494
- "microsoft.com/email": profile.email
1495
- }
1496
- });
1497
- };
1498
- }
1499
- }
1331
+ resolvers: adaptOAuthSignInResolverToLegacy({
1332
+ emailLocalPartMatchingUserEntityName: pluginAuthNode.commonSignInResolvers.emailLocalPartMatchingUserEntityName(),
1333
+ emailMatchingUserEntityProfileEmail: pluginAuthNode.commonSignInResolvers.emailMatchingUserEntityProfileEmail(),
1334
+ emailMatchingUserEntityAnnotation: pluginAuthBackendModuleMicrosoftProvider.microsoftSignInResolvers.emailMatchingUserEntityAnnotation()
1335
+ })
1500
1336
  });
1501
1337
 
1502
1338
  const oauth2 = createAuthProviderIntegration({
@@ -1521,166 +1357,21 @@ const oauth2Proxy = createAuthProviderIntegration({
1521
1357
  }
1522
1358
  });
1523
1359
 
1524
- var __defProp$9 = Object.defineProperty;
1525
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1526
- var __publicField$9 = (obj, key, value) => {
1527
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
1528
- return value;
1529
- };
1530
- class OidcAuthProvider {
1531
- constructor(options) {
1532
- __publicField$9(this, "implementation");
1533
- __publicField$9(this, "scope");
1534
- __publicField$9(this, "prompt");
1535
- __publicField$9(this, "signInResolver");
1536
- __publicField$9(this, "authHandler");
1537
- __publicField$9(this, "resolverContext");
1538
- this.implementation = this.setupStrategy(options);
1539
- this.scope = options.scope;
1540
- this.prompt = options.prompt;
1541
- this.signInResolver = options.signInResolver;
1542
- this.authHandler = options.authHandler;
1543
- this.resolverContext = options.resolverContext;
1544
- }
1545
- async start(req) {
1546
- const { strategy } = await this.implementation;
1547
- const options = {
1548
- scope: req.scope || this.scope || "openid profile email",
1549
- state: encodeState(req.state)
1550
- };
1551
- const prompt = this.prompt || "none";
1552
- if (prompt !== "auto") {
1553
- options.prompt = prompt;
1554
- }
1555
- return await executeRedirectStrategy(req, strategy, options);
1556
- }
1557
- async handler(req) {
1558
- const { strategy } = await this.implementation;
1559
- const { result, privateInfo } = await executeFrameHandlerStrategy(req, strategy);
1560
- return {
1561
- response: await this.handleResult(result),
1562
- refreshToken: privateInfo.refreshToken
1563
- };
1564
- }
1565
- async refresh(req) {
1566
- const { client } = await this.implementation;
1567
- const tokenset = await client.refresh(req.refreshToken);
1568
- if (!tokenset.access_token) {
1569
- throw new Error("Refresh failed");
1570
- }
1571
- if (!tokenset.scope) {
1572
- tokenset.scope = req.scope;
1573
- }
1574
- const userinfo = await client.userinfo(tokenset.access_token);
1575
- return {
1576
- response: await this.handleResult({ tokenset, userinfo }),
1577
- refreshToken: tokenset.refresh_token
1578
- };
1579
- }
1580
- async setupStrategy(options) {
1581
- const issuer = await openidClient.Issuer.discover(options.metadataUrl);
1582
- const client = new issuer.Client({
1583
- access_type: "offline",
1584
- // this option must be passed to provider to receive a refresh token
1585
- client_id: options.clientId,
1586
- client_secret: options.clientSecret,
1587
- redirect_uris: [options.callbackUrl],
1588
- response_types: ["code"],
1589
- token_endpoint_auth_method: options.tokenEndpointAuthMethod || "client_secret_basic",
1590
- id_token_signed_response_alg: options.tokenSignedResponseAlg || "RS256",
1591
- scope: options.scope || ""
1592
- });
1593
- const strategy = new openidClient.Strategy(
1594
- {
1595
- client,
1596
- passReqToCallback: false
1597
- },
1598
- (tokenset, userinfo, done) => {
1599
- if (typeof done !== "function") {
1600
- throw new Error(
1601
- "OIDC IdP must provide a userinfo_endpoint in the metadata response"
1602
- );
1603
- }
1604
- done(
1605
- void 0,
1606
- { tokenset, userinfo },
1607
- {
1608
- refreshToken: tokenset.refresh_token
1609
- }
1610
- );
1611
- }
1612
- );
1613
- strategy.error = console.error;
1614
- return { strategy, client };
1615
- }
1616
- // Use this function to grab the user profile info from the token
1617
- // Then populate the profile with it
1618
- async handleResult(result) {
1619
- const { profile } = await this.authHandler(result, this.resolverContext);
1620
- const expiresInSeconds = result.tokenset.expires_in === void 0 ? BACKSTAGE_SESSION_EXPIRATION : Math.min(result.tokenset.expires_in, BACKSTAGE_SESSION_EXPIRATION);
1621
- let backstageIdentity = void 0;
1622
- if (this.signInResolver) {
1623
- backstageIdentity = await this.signInResolver(
1624
- {
1625
- result,
1626
- profile
1627
- },
1628
- this.resolverContext
1629
- );
1630
- }
1631
- return {
1632
- backstageIdentity,
1633
- providerInfo: {
1634
- idToken: result.tokenset.id_token,
1635
- accessToken: result.tokenset.access_token,
1636
- scope: result.tokenset.scope,
1637
- expiresInSeconds
1638
- },
1639
- profile
1640
- };
1641
- }
1642
- }
1643
1360
  const oidc = createAuthProviderIntegration({
1644
1361
  create(options) {
1645
- return ({ providerId, globalConfig, config, resolverContext }) => OAuthEnvironmentHandler.mapConfig(config, (envConfig) => {
1646
- var _a;
1647
- const clientId = envConfig.getString("clientId");
1648
- const clientSecret = envConfig.getString("clientSecret");
1649
- const customCallbackUrl = envConfig.getOptionalString("callbackUrl");
1650
- const callbackUrl = customCallbackUrl || `${globalConfig.baseUrl}/${providerId}/handler/frame`;
1651
- const metadataUrl = envConfig.getString("metadataUrl");
1652
- const tokenEndpointAuthMethod = envConfig.getOptionalString(
1653
- "tokenEndpointAuthMethod"
1654
- );
1655
- const tokenSignedResponseAlg = envConfig.getOptionalString(
1656
- "tokenSignedResponseAlg"
1657
- );
1658
- const scope = envConfig.getOptionalString("scope");
1659
- const prompt = envConfig.getOptionalString("prompt");
1660
- const authHandler = (options == null ? void 0 : options.authHandler) ? options.authHandler : async ({ userinfo }) => ({
1661
- profile: {
1662
- displayName: userinfo.name,
1663
- email: userinfo.email,
1664
- picture: userinfo.picture
1665
- }
1666
- });
1667
- const provider = new OidcAuthProvider({
1668
- clientId,
1669
- clientSecret,
1670
- callbackUrl,
1671
- tokenEndpointAuthMethod,
1672
- tokenSignedResponseAlg,
1673
- metadataUrl,
1674
- scope,
1675
- prompt,
1676
- signInResolver: (_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver,
1677
- authHandler,
1678
- resolverContext
1679
- });
1680
- return OAuthAdapter.fromConfig(globalConfig, provider, {
1681
- providerId,
1682
- callbackUrl
1683
- });
1362
+ var _a;
1363
+ const authHandler = options == null ? void 0 : options.authHandler;
1364
+ const signInResolver = (_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver;
1365
+ return pluginAuthNode.createOAuthProviderFactory({
1366
+ authenticator: pluginAuthBackendModuleOidcProvider.oidcAuthenticator,
1367
+ profileTransform: authHandler && ((result, context) => authHandler(result.fullProfile, context)),
1368
+ signInResolver: signInResolver && ((info, context) => signInResolver(
1369
+ {
1370
+ result: info.result.fullProfile,
1371
+ profile: info.profile
1372
+ },
1373
+ context
1374
+ ))
1684
1375
  });
1685
1376
  },
1686
1377
  resolvers: {
@@ -2940,6 +2631,8 @@ _database = new WeakMap();
2940
2631
  _promise = new WeakMap();
2941
2632
  let AuthDatabase = _AuthDatabase;
2942
2633
 
2634
+ const BACKSTAGE_SESSION_EXPIRATION = 3600;
2635
+
2943
2636
  var __defProp = Object.defineProperty;
2944
2637
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2945
2638
  var __publicField = (obj, key, value) => {