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

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
@@ -14,18 +14,18 @@ var crypto = require('crypto');
14
14
  var url = require('url');
15
15
  var errors = require('@backstage/errors');
16
16
  var jwtDecoder = require('jwt-decode');
17
+ var pluginAuthBackendModuleAwsAlbProvider = require('@backstage/plugin-auth-backend-module-aws-alb-provider');
18
+ var passportBitbucketOauth2 = require('passport-bitbucket-oauth2');
17
19
  var fetch = require('node-fetch');
18
- var NodeCache = require('node-cache');
19
20
  var jose = require('jose');
20
- var passportBitbucketOauth2 = require('passport-bitbucket-oauth2');
21
21
  var pluginAuthBackendModuleGcpIapProvider = require('@backstage/plugin-auth-backend-module-gcp-iap-provider');
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');
@@ -46,33 +46,13 @@ var config = require('@backstage/config');
46
46
 
47
47
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
48
48
 
49
- function _interopNamespace(e) {
50
- if (e && e.__esModule) return e;
51
- var n = Object.create(null);
52
- if (e) {
53
- Object.keys(e).forEach(function (k) {
54
- if (k !== 'default') {
55
- var d = Object.getOwnPropertyDescriptor(e, k);
56
- Object.defineProperty(n, k, d.get ? d : {
57
- enumerable: true,
58
- get: function () { return e[k]; }
59
- });
60
- }
61
- });
62
- }
63
- n["default"] = e;
64
- return Object.freeze(n);
65
- }
66
-
67
49
  var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
68
50
  var Router__default = /*#__PURE__*/_interopDefaultLegacy(Router);
69
51
  var cookieParser__default = /*#__PURE__*/_interopDefaultLegacy(cookieParser);
70
52
  var Auth0InternalStrategy__default = /*#__PURE__*/_interopDefaultLegacy(Auth0InternalStrategy);
71
53
  var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
72
- var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
73
54
  var jwtDecoder__default = /*#__PURE__*/_interopDefaultLegacy(jwtDecoder);
74
55
  var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
75
- var NodeCache__default = /*#__PURE__*/_interopDefaultLegacy(NodeCache);
76
56
  var session__default = /*#__PURE__*/_interopDefaultLegacy(session);
77
57
  var connectSessionKnex__default = /*#__PURE__*/_interopDefaultLegacy(connectSessionKnex);
78
58
  var passport__default = /*#__PURE__*/_interopDefaultLegacy(passport);
@@ -240,10 +220,10 @@ const ensuresXRequestedWith = (req) => {
240
220
 
241
221
  const prepareBackstageIdentityResponse = pluginAuthNode.prepareBackstageIdentityResponse;
242
222
 
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);
223
+ var __defProp$c = Object.defineProperty;
224
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
225
+ var __publicField$c = (obj, key, value) => {
226
+ __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
247
227
  return value;
248
228
  };
249
229
  const THOUSAND_DAYS_MS = 1e3 * 24 * 60 * 60 * 1e3;
@@ -252,8 +232,8 @@ class OAuthAdapter {
252
232
  constructor(handlers, options) {
253
233
  this.handlers = handlers;
254
234
  this.options = options;
255
- __publicField$f(this, "baseCookieOptions");
256
- __publicField$f(this, "setNonceCookie", (res, nonce, cookieConfig) => {
235
+ __publicField$c(this, "baseCookieOptions");
236
+ __publicField$c(this, "setNonceCookie", (res, nonce, cookieConfig) => {
257
237
  res.cookie(`${this.options.providerId}-nonce`, nonce, {
258
238
  maxAge: TEN_MINUTES_MS,
259
239
  ...this.baseCookieOptions,
@@ -261,34 +241,34 @@ class OAuthAdapter {
261
241
  path: `${cookieConfig.path}/handler`
262
242
  });
263
243
  });
264
- __publicField$f(this, "setGrantedScopeCookie", (res, scope, cookieConfig) => {
244
+ __publicField$c(this, "setGrantedScopeCookie", (res, scope, cookieConfig) => {
265
245
  res.cookie(`${this.options.providerId}-granted-scope`, scope, {
266
246
  maxAge: THOUSAND_DAYS_MS,
267
247
  ...this.baseCookieOptions,
268
248
  ...cookieConfig
269
249
  });
270
250
  });
271
- __publicField$f(this, "getRefreshTokenFromCookie", (req) => {
251
+ __publicField$c(this, "getRefreshTokenFromCookie", (req) => {
272
252
  return req.cookies[`${this.options.providerId}-refresh-token`];
273
253
  });
274
- __publicField$f(this, "getGrantedScopeFromCookie", (req) => {
254
+ __publicField$c(this, "getGrantedScopeFromCookie", (req) => {
275
255
  return req.cookies[`${this.options.providerId}-granted-scope`];
276
256
  });
277
- __publicField$f(this, "setRefreshTokenCookie", (res, refreshToken, cookieConfig) => {
257
+ __publicField$c(this, "setRefreshTokenCookie", (res, refreshToken, cookieConfig) => {
278
258
  res.cookie(`${this.options.providerId}-refresh-token`, refreshToken, {
279
259
  maxAge: THOUSAND_DAYS_MS,
280
260
  ...this.baseCookieOptions,
281
261
  ...cookieConfig
282
262
  });
283
263
  });
284
- __publicField$f(this, "removeRefreshTokenCookie", (res, cookieConfig) => {
264
+ __publicField$c(this, "removeRefreshTokenCookie", (res, cookieConfig) => {
285
265
  res.cookie(`${this.options.providerId}-refresh-token`, "", {
286
266
  maxAge: 0,
287
267
  ...this.baseCookieOptions,
288
268
  ...cookieConfig
289
269
  });
290
270
  });
291
- __publicField$f(this, "getCookieConfig", (origin) => {
271
+ __publicField$c(this, "getCookieConfig", (origin) => {
292
272
  return this.options.cookieConfigurer({
293
273
  providerId: this.options.providerId,
294
274
  baseUrl: this.options.baseUrl,
@@ -586,21 +566,21 @@ const executeFetchUserProfileStrategy = async (providerStrategy, accessToken) =>
586
566
  });
587
567
  };
588
568
 
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);
569
+ var __defProp$b = Object.defineProperty;
570
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
571
+ var __publicField$b = (obj, key, value) => {
572
+ __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
593
573
  return value;
594
574
  };
595
575
  class Auth0AuthProvider {
596
576
  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");
577
+ __publicField$b(this, "_strategy");
578
+ __publicField$b(this, "signInResolver");
579
+ __publicField$b(this, "authHandler");
580
+ __publicField$b(this, "resolverContext");
581
+ __publicField$b(this, "audience");
582
+ __publicField$b(this, "connection");
583
+ __publicField$b(this, "connectionScope");
604
584
  /**
605
585
  * Due to passport-auth0 forcing options.state = true,
606
586
  * passport-oauth2 requires express-session to be installed
@@ -609,7 +589,7 @@ class Auth0AuthProvider {
609
589
  * passport-oauth2, which is the StateStore implementation used when options.state = false,
610
590
  * allowing us to avoid using express-session in order to integrate with auth0.
611
591
  */
612
- __publicField$e(this, "store", {
592
+ __publicField$b(this, "store", {
613
593
  store(_req, cb) {
614
594
  cb(null, null);
615
595
  },
@@ -750,162 +730,29 @@ const auth0 = createAuthProviderIntegration({
750
730
  }
751
731
  });
752
732
 
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);
757
- return value;
758
- };
759
- const ALB_JWT_HEADER = "x-amzn-oidc-data";
760
- const ALB_ACCESS_TOKEN_HEADER = "x-amzn-oidc-accesstoken";
761
- class AwsAlbAuthProvider {
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) => {
770
- if (!header.kid) {
771
- throw new errors.AuthenticationError("No key id was specified in header");
772
- }
773
- const optionalCacheKey = this.keyCache.get(header.kid);
774
- if (optionalCacheKey) {
775
- return crypto__namespace.createPublicKey(optionalCacheKey);
776
- }
777
- const keyText = await fetch__default["default"](
778
- `https://public-keys.auth.elb.${encodeURIComponent(
779
- this.region
780
- )}.amazonaws.com/${encodeURIComponent(header.kid)}`
781
- ).then((response) => response.text());
782
- const keyValue = crypto__namespace.createPublicKey(keyText);
783
- this.keyCache.set(
784
- header.kid,
785
- keyValue.export({ format: "pem", type: "spki" })
786
- );
787
- return keyValue;
788
- });
789
- this.region = options.region;
790
- this.issuer = options.issuer;
791
- this.authHandler = options.authHandler;
792
- this.signInResolver = options.signInResolver;
793
- this.resolverContext = options.resolverContext;
794
- this.keyCache = new NodeCache__default["default"]({ stdTTL: 3600 });
795
- }
796
- frameHandler() {
797
- return Promise.resolve(void 0);
798
- }
799
- async refresh(req, res) {
800
- try {
801
- const result = await this.getResult(req);
802
- const response = await this.handleResult(result);
803
- res.json(response);
804
- } catch (e) {
805
- throw new errors.AuthenticationError(
806
- "Exception occurred during AWS ALB token refresh",
807
- e
808
- );
809
- }
810
- }
811
- start() {
812
- return Promise.resolve(void 0);
813
- }
814
- async getResult(req) {
815
- const jwt = req.header(ALB_JWT_HEADER);
816
- const accessToken = req.header(ALB_ACCESS_TOKEN_HEADER);
817
- if (jwt === void 0) {
818
- throw new errors.AuthenticationError(
819
- `Missing ALB OIDC header: ${ALB_JWT_HEADER}`
820
- );
821
- }
822
- if (accessToken === void 0) {
823
- throw new errors.AuthenticationError(
824
- `Missing ALB OIDC header: ${ALB_ACCESS_TOKEN_HEADER}`
825
- );
826
- }
827
- try {
828
- const verifyResult = await jose.jwtVerify(jwt, this.getKey);
829
- const claims = verifyResult.payload;
830
- if (this.issuer && claims.iss !== this.issuer) {
831
- throw new errors.AuthenticationError("Issuer mismatch on JWT token");
832
- }
833
- const fullProfile = {
834
- provider: "unknown",
835
- id: claims.sub,
836
- displayName: claims.name,
837
- username: claims.email.split("@")[0].toLowerCase(),
838
- name: {
839
- familyName: claims.family_name,
840
- givenName: claims.given_name
841
- },
842
- emails: [{ value: claims.email.toLowerCase() }],
843
- photos: [{ value: claims.picture }]
844
- };
845
- return {
846
- fullProfile,
847
- expiresInSeconds: claims.exp,
848
- accessToken
849
- };
850
- } catch (e) {
851
- throw new Error(`Exception occurred during JWT processing: ${e}`);
852
- }
853
- }
854
- async handleResult(result) {
855
- const { profile } = await this.authHandler(result, this.resolverContext);
856
- const backstageIdentity = await this.signInResolver(
857
- {
858
- result,
859
- profile
860
- },
861
- this.resolverContext
862
- );
863
- return {
864
- providerInfo: {
865
- accessToken: result.accessToken,
866
- expiresInSeconds: result.expiresInSeconds
867
- },
868
- backstageIdentity: prepareBackstageIdentityResponse(backstageIdentity),
869
- profile
870
- };
871
- }
872
- }
873
733
  const awsAlb = createAuthProviderIntegration({
874
734
  create(options) {
875
- return ({ config, resolverContext }) => {
876
- const region = config.getString("region");
877
- const issuer = config.getOptionalString("iss");
878
- if ((options == null ? void 0 : options.signIn.resolver) === void 0) {
879
- throw new Error(
880
- "SignInResolver is required to use this authentication provider"
881
- );
882
- }
883
- const authHandler = (options == null ? void 0 : options.authHandler) ? options.authHandler : async ({ fullProfile }) => ({
884
- profile: makeProfileInfo(fullProfile)
885
- });
886
- return new AwsAlbAuthProvider({
887
- region,
888
- issuer,
889
- signInResolver: options == null ? void 0 : options.signIn.resolver,
890
- authHandler,
891
- resolverContext
892
- });
893
- };
735
+ var _a;
736
+ return pluginAuthNode.createProxyAuthProviderFactory({
737
+ authenticator: pluginAuthBackendModuleAwsAlbProvider.awsAlbAuthenticator,
738
+ profileTransform: options == null ? void 0 : options.authHandler,
739
+ signInResolver: (_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver
740
+ });
894
741
  }
895
742
  });
896
743
 
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);
744
+ var __defProp$a = Object.defineProperty;
745
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
746
+ var __publicField$a = (obj, key, value) => {
747
+ __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
901
748
  return value;
902
749
  };
903
750
  class BitbucketAuthProvider {
904
751
  constructor(options) {
905
- __publicField$c(this, "_strategy");
906
- __publicField$c(this, "signInResolver");
907
- __publicField$c(this, "authHandler");
908
- __publicField$c(this, "resolverContext");
752
+ __publicField$a(this, "_strategy");
753
+ __publicField$a(this, "signInResolver");
754
+ __publicField$a(this, "authHandler");
755
+ __publicField$a(this, "resolverContext");
909
756
  this.signInResolver = options.signInResolver;
910
757
  this.authHandler = options.authHandler;
911
758
  this.resolverContext = options.resolverContext;
@@ -1073,10 +920,10 @@ const commonByEmailResolver = async (info, ctx) => {
1073
920
  });
1074
921
  };
1075
922
 
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);
923
+ var __defProp$9 = Object.defineProperty;
924
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
925
+ var __publicField$9 = (obj, key, value) => {
926
+ __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
1080
927
  return value;
1081
928
  };
1082
929
  const CF_JWT_HEADER = "cf-access-jwt-assertion";
@@ -1084,12 +931,12 @@ const COOKIE_AUTH_NAME = "CF_Authorization";
1084
931
  const CACHE_PREFIX = "providers/cloudflare-access/profile-v1";
1085
932
  class CloudflareAccessAuthProvider {
1086
933
  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");
934
+ __publicField$9(this, "teamName");
935
+ __publicField$9(this, "resolverContext");
936
+ __publicField$9(this, "authHandler");
937
+ __publicField$9(this, "signInResolver");
938
+ __publicField$9(this, "jwtKeySet");
939
+ __publicField$9(this, "cache");
1093
940
  this.teamName = options.teamName;
1094
941
  this.authHandler = options.authHandler;
1095
942
  this.signInResolver = options.signInResolver;
@@ -1319,184 +1166,20 @@ const google = createAuthProviderIntegration({
1319
1166
  })
1320
1167
  });
1321
1168
 
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
1169
  const microsoft = createAuthProviderIntegration({
1444
1170
  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
- });
1171
+ var _a;
1172
+ return pluginAuthNode.createOAuthProviderFactory({
1173
+ authenticator: pluginAuthBackendModuleMicrosoftProvider.microsoftAuthenticator,
1174
+ profileTransform: adaptLegacyOAuthHandler(options == null ? void 0 : options.authHandler),
1175
+ signInResolver: adaptLegacyOAuthSignInResolver((_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver)
1472
1176
  });
1473
1177
  },
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
- }
1178
+ resolvers: adaptOAuthSignInResolverToLegacy({
1179
+ emailLocalPartMatchingUserEntityName: pluginAuthNode.commonSignInResolvers.emailLocalPartMatchingUserEntityName(),
1180
+ emailMatchingUserEntityProfileEmail: pluginAuthNode.commonSignInResolvers.emailMatchingUserEntityProfileEmail(),
1181
+ emailMatchingUserEntityAnnotation: pluginAuthBackendModuleMicrosoftProvider.microsoftSignInResolvers.emailMatchingUserEntityAnnotation()
1182
+ })
1500
1183
  });
1501
1184
 
1502
1185
  const oauth2 = createAuthProviderIntegration({
@@ -1521,166 +1204,21 @@ const oauth2Proxy = createAuthProviderIntegration({
1521
1204
  }
1522
1205
  });
1523
1206
 
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
1207
  const oidc = createAuthProviderIntegration({
1644
1208
  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
- });
1209
+ var _a;
1210
+ const authHandler = options == null ? void 0 : options.authHandler;
1211
+ const signInResolver = (_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver;
1212
+ return pluginAuthNode.createOAuthProviderFactory({
1213
+ authenticator: pluginAuthBackendModuleOidcProvider.oidcAuthenticator,
1214
+ profileTransform: authHandler && ((result, context) => authHandler(result.fullProfile, context)),
1215
+ signInResolver: signInResolver && ((info, context) => signInResolver(
1216
+ {
1217
+ result: info.result.fullProfile,
1218
+ profile: info.profile
1219
+ },
1220
+ context
1221
+ ))
1684
1222
  });
1685
1223
  },
1686
1224
  resolvers: {
@@ -2940,6 +2478,8 @@ _database = new WeakMap();
2940
2478
  _promise = new WeakMap();
2941
2479
  let AuthDatabase = _AuthDatabase;
2942
2480
 
2481
+ const BACKSTAGE_SESSION_EXPIRATION = 3600;
2482
+
2943
2483
  var __defProp = Object.defineProperty;
2944
2484
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2945
2485
  var __publicField = (obj, key, value) => {