@backstage/plugin-auth-backend 0.20.0 → 0.20.1-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
@@ -8,12 +8,12 @@ var alpha = require('@backstage/plugin-catalog-node/alpha');
8
8
  var express = require('express');
9
9
  var Router = require('express-promise-router');
10
10
  var cookieParser = require('cookie-parser');
11
- var OAuth2Strategy = require('passport-oauth2');
11
+ var pluginAuthBackendModuleAtlassianProvider = require('@backstage/plugin-auth-backend-module-atlassian-provider');
12
+ var Auth0InternalStrategy = require('passport-auth0');
12
13
  var crypto = require('crypto');
13
14
  var url = require('url');
14
15
  var errors = require('@backstage/errors');
15
16
  var jwtDecoder = require('jwt-decode');
16
- var Auth0InternalStrategy = require('passport-auth0');
17
17
  var fetch = require('node-fetch');
18
18
  var NodeCache = require('node-cache');
19
19
  var jose = require('jose');
@@ -25,9 +25,10 @@ var pluginAuthBackendModuleGoogleProvider = require('@backstage/plugin-auth-back
25
25
  var passportMicrosoft = require('passport-microsoft');
26
26
  var pluginAuthBackendModuleOauth2Provider = require('@backstage/plugin-auth-backend-module-oauth2-provider');
27
27
  var openidClient = require('openid-client');
28
- var passportOktaOauth = require('@davidzemon/passport-okta-oauth');
28
+ var pluginAuthBackendModuleOktaProvider = require('@backstage/plugin-auth-backend-module-okta-provider');
29
29
  var passportOneloginOauth = require('passport-onelogin-oauth');
30
30
  var passportSaml = require('passport-saml');
31
+ var passportOauth2 = require('passport-oauth2');
31
32
  var catalogClient = require('@backstage/catalog-client');
32
33
  var catalogModel = require('@backstage/catalog-model');
33
34
  var luxon = require('luxon');
@@ -65,82 +66,109 @@ function _interopNamespace(e) {
65
66
  var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
66
67
  var Router__default = /*#__PURE__*/_interopDefaultLegacy(Router);
67
68
  var cookieParser__default = /*#__PURE__*/_interopDefaultLegacy(cookieParser);
68
- var OAuth2Strategy__default = /*#__PURE__*/_interopDefaultLegacy(OAuth2Strategy);
69
+ var Auth0InternalStrategy__default = /*#__PURE__*/_interopDefaultLegacy(Auth0InternalStrategy);
69
70
  var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
70
71
  var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
71
72
  var jwtDecoder__default = /*#__PURE__*/_interopDefaultLegacy(jwtDecoder);
72
- var Auth0InternalStrategy__default = /*#__PURE__*/_interopDefaultLegacy(Auth0InternalStrategy);
73
73
  var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
74
74
  var NodeCache__default = /*#__PURE__*/_interopDefaultLegacy(NodeCache);
75
75
  var session__default = /*#__PURE__*/_interopDefaultLegacy(session);
76
76
  var connectSessionKnex__default = /*#__PURE__*/_interopDefaultLegacy(connectSessionKnex);
77
77
  var passport__default = /*#__PURE__*/_interopDefaultLegacy(passport);
78
78
 
79
- var __defProp$j = Object.defineProperty;
80
- var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
81
- var __publicField$j = (obj, key, value) => {
82
- __defNormalProp$j(obj, typeof key !== "symbol" ? key + "" : key, value);
83
- return value;
84
- };
85
- const defaultScopes = ["offline_access", "read:me"];
86
- class AtlassianStrategy extends OAuth2Strategy__default["default"] {
87
- constructor(options, verify) {
88
- if (!options.scope) {
89
- throw new TypeError("Atlassian requires a scope option");
90
- }
91
- const scopes = options.scope.split(" ");
92
- const optionsWithURLs = {
93
- ...options,
94
- authorizationURL: `https://auth.atlassian.com/authorize`,
95
- tokenURL: `https://auth.atlassian.com/oauth/token`,
96
- scope: Array.from(/* @__PURE__ */ new Set([...defaultScopes, ...scopes]))
97
- };
98
- super(optionsWithURLs, verify);
99
- __publicField$j(this, "profileURL");
100
- this.profileURL = "https://api.atlassian.com/me";
101
- this.name = "atlassian";
102
- this._oauth2.useAuthorizationHeaderforGET(true);
103
- }
104
- authorizationParams() {
105
- return {
106
- audience: "api.atlassian.com",
107
- prompt: "consent"
108
- };
109
- }
110
- userProfile(accessToken, done) {
111
- this._oauth2.get(this.profileURL, accessToken, (err, body) => {
112
- if (err) {
113
- return done(
114
- new OAuth2Strategy.InternalOAuthError(
115
- "Failed to fetch user profile",
116
- err.statusCode
117
- )
118
- );
119
- }
120
- if (!body) {
121
- return done(
122
- new Error("Failed to fetch user profile, body cannot be empty")
123
- );
79
+ function createAuthProviderIntegration(config) {
80
+ var _a;
81
+ return Object.freeze({
82
+ ...config,
83
+ resolvers: Object.freeze((_a = config.resolvers) != null ? _a : {})
84
+ });
85
+ }
86
+
87
+ function adaptLegacyOAuthHandler(authHandler) {
88
+ return authHandler && (async (result, ctx) => authHandler(
89
+ {
90
+ fullProfile: result.fullProfile,
91
+ accessToken: result.session.accessToken,
92
+ params: {
93
+ scope: result.session.scope,
94
+ id_token: result.session.idToken,
95
+ token_type: result.session.tokenType,
96
+ expires_in: result.session.expiresInSeconds
124
97
  }
125
- try {
126
- const json = typeof body !== "string" ? body.toString() : body;
127
- const profile = AtlassianStrategy.parse(json);
128
- return done(null, profile);
129
- } catch (e) {
130
- return done(new Error("Failed to parse user profile"));
98
+ },
99
+ ctx
100
+ ));
101
+ }
102
+
103
+ function adaptLegacyOAuthSignInResolver(signInResolver) {
104
+ return signInResolver && (async (input, ctx) => signInResolver(
105
+ {
106
+ profile: input.profile,
107
+ result: {
108
+ fullProfile: input.result.fullProfile,
109
+ accessToken: input.result.session.accessToken,
110
+ refreshToken: input.result.session.refreshToken,
111
+ params: {
112
+ scope: input.result.session.scope,
113
+ id_token: input.result.session.idToken,
114
+ token_type: input.result.session.tokenType,
115
+ expires_in: input.result.session.expiresInSeconds
116
+ }
131
117
  }
118
+ },
119
+ ctx
120
+ ));
121
+ }
122
+
123
+ function adaptOAuthSignInResolverToLegacy(resolvers) {
124
+ const legacyResolvers = {};
125
+ for (const name of Object.keys(resolvers)) {
126
+ const resolver = resolvers[name];
127
+ legacyResolvers[name] = () => async (input, ctx) => {
128
+ var _a;
129
+ return resolver(
130
+ {
131
+ profile: input.profile,
132
+ result: {
133
+ fullProfile: input.result.fullProfile,
134
+ session: {
135
+ accessToken: input.result.accessToken,
136
+ expiresInSeconds: input.result.params.expires_in,
137
+ scope: input.result.params.scope,
138
+ idToken: input.result.params.id_token,
139
+ tokenType: (_a = input.result.params.token_type) != null ? _a : "bearer",
140
+ refreshToken: input.result.refreshToken
141
+ }
142
+ }
143
+ },
144
+ ctx
145
+ );
146
+ };
147
+ }
148
+ return legacyResolvers;
149
+ }
150
+
151
+ const atlassian = createAuthProviderIntegration({
152
+ create(options) {
153
+ var _a;
154
+ return pluginAuthNode.createOAuthProviderFactory({
155
+ authenticator: pluginAuthBackendModuleAtlassianProvider.atlassianAuthenticator,
156
+ profileTransform: adaptLegacyOAuthHandler(options == null ? void 0 : options.authHandler),
157
+ signInResolver: adaptLegacyOAuthSignInResolver((_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver)
132
158
  });
133
159
  }
134
- static parse(json) {
135
- const resp = JSON.parse(json);
136
- return {
137
- id: resp.account_id,
138
- provider: "atlassian",
139
- username: resp.nickname,
140
- displayName: resp.name,
141
- emails: [{ value: resp.email }],
142
- photos: [{ value: resp.picture }]
160
+ });
161
+
162
+ class Auth0Strategy extends Auth0InternalStrategy__default["default"] {
163
+ constructor(options, verify) {
164
+ const optionsWithURLs = {
165
+ ...options,
166
+ authorizationURL: `https://${options.domain}/authorize`,
167
+ tokenURL: `https://${options.domain}/oauth/token`,
168
+ userInfoURL: `https://${options.domain}/userinfo`,
169
+ apiUrl: `https://${options.domain}/api`
143
170
  };
171
+ super(optionsWithURLs, verify);
144
172
  }
145
173
  }
146
174
 
@@ -211,10 +239,10 @@ const ensuresXRequestedWith = (req) => {
211
239
 
212
240
  const prepareBackstageIdentityResponse = pluginAuthNode.prepareBackstageIdentityResponse;
213
241
 
214
- var __defProp$i = Object.defineProperty;
215
- var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
216
- var __publicField$i = (obj, key, value) => {
217
- __defNormalProp$i(obj, typeof key !== "symbol" ? key + "" : key, value);
242
+ var __defProp$g = Object.defineProperty;
243
+ var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
244
+ var __publicField$g = (obj, key, value) => {
245
+ __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
218
246
  return value;
219
247
  };
220
248
  const THOUSAND_DAYS_MS = 1e3 * 24 * 60 * 60 * 1e3;
@@ -223,8 +251,8 @@ class OAuthAdapter {
223
251
  constructor(handlers, options) {
224
252
  this.handlers = handlers;
225
253
  this.options = options;
226
- __publicField$i(this, "baseCookieOptions");
227
- __publicField$i(this, "setNonceCookie", (res, nonce, cookieConfig) => {
254
+ __publicField$g(this, "baseCookieOptions");
255
+ __publicField$g(this, "setNonceCookie", (res, nonce, cookieConfig) => {
228
256
  res.cookie(`${this.options.providerId}-nonce`, nonce, {
229
257
  maxAge: TEN_MINUTES_MS,
230
258
  ...this.baseCookieOptions,
@@ -232,34 +260,34 @@ class OAuthAdapter {
232
260
  path: `${cookieConfig.path}/handler`
233
261
  });
234
262
  });
235
- __publicField$i(this, "setGrantedScopeCookie", (res, scope, cookieConfig) => {
263
+ __publicField$g(this, "setGrantedScopeCookie", (res, scope, cookieConfig) => {
236
264
  res.cookie(`${this.options.providerId}-granted-scope`, scope, {
237
265
  maxAge: THOUSAND_DAYS_MS,
238
266
  ...this.baseCookieOptions,
239
267
  ...cookieConfig
240
268
  });
241
269
  });
242
- __publicField$i(this, "getRefreshTokenFromCookie", (req) => {
270
+ __publicField$g(this, "getRefreshTokenFromCookie", (req) => {
243
271
  return req.cookies[`${this.options.providerId}-refresh-token`];
244
272
  });
245
- __publicField$i(this, "getGrantedScopeFromCookie", (req) => {
273
+ __publicField$g(this, "getGrantedScopeFromCookie", (req) => {
246
274
  return req.cookies[`${this.options.providerId}-granted-scope`];
247
275
  });
248
- __publicField$i(this, "setRefreshTokenCookie", (res, refreshToken, cookieConfig) => {
276
+ __publicField$g(this, "setRefreshTokenCookie", (res, refreshToken, cookieConfig) => {
249
277
  res.cookie(`${this.options.providerId}-refresh-token`, refreshToken, {
250
278
  maxAge: THOUSAND_DAYS_MS,
251
279
  ...this.baseCookieOptions,
252
280
  ...cookieConfig
253
281
  });
254
282
  });
255
- __publicField$i(this, "removeRefreshTokenCookie", (res, cookieConfig) => {
283
+ __publicField$g(this, "removeRefreshTokenCookie", (res, cookieConfig) => {
256
284
  res.cookie(`${this.options.providerId}-refresh-token`, "", {
257
285
  maxAge: 0,
258
286
  ...this.baseCookieOptions,
259
287
  ...cookieConfig
260
288
  });
261
289
  });
262
- __publicField$i(this, "getCookieConfig", (origin) => {
290
+ __publicField$g(this, "getCookieConfig", (origin) => {
263
291
  return this.options.cookieConfigurer({
264
292
  providerId: this.options.providerId,
265
293
  baseUrl: this.options.baseUrl,
@@ -557,164 +585,21 @@ const executeFetchUserProfileStrategy = async (providerStrategy, accessToken) =>
557
585
  });
558
586
  };
559
587
 
560
- function createAuthProviderIntegration(config) {
561
- var _a;
562
- return Object.freeze({
563
- ...config,
564
- resolvers: Object.freeze((_a = config.resolvers) != null ? _a : {})
565
- });
566
- }
567
-
568
- var __defProp$h = Object.defineProperty;
569
- var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
570
- var __publicField$h = (obj, key, value) => {
571
- __defNormalProp$h(obj, typeof key !== "symbol" ? key + "" : key, value);
572
- return value;
573
- };
574
- const atlassianDefaultAuthHandler = async ({
575
- fullProfile,
576
- params
577
- }) => ({
578
- profile: makeProfileInfo(fullProfile, params.id_token)
579
- });
580
- class AtlassianAuthProvider {
581
- constructor(options) {
582
- __publicField$h(this, "_strategy");
583
- __publicField$h(this, "signInResolver");
584
- __publicField$h(this, "authHandler");
585
- __publicField$h(this, "resolverContext");
586
- this.resolverContext = options.resolverContext;
587
- this.authHandler = options.authHandler;
588
- this.signInResolver = options.signInResolver;
589
- this._strategy = new AtlassianStrategy(
590
- {
591
- clientID: options.clientId,
592
- clientSecret: options.clientSecret,
593
- callbackURL: options.callbackUrl,
594
- scope: options.scopes
595
- },
596
- (accessToken, refreshToken, params, fullProfile, done) => {
597
- done(void 0, {
598
- fullProfile,
599
- accessToken,
600
- refreshToken,
601
- params
602
- });
603
- }
604
- );
605
- }
606
- async start(req) {
607
- return await executeRedirectStrategy(req, this._strategy, {
608
- state: encodeState(req.state)
609
- });
610
- }
611
- async handler(req) {
612
- const { result } = await executeFrameHandlerStrategy(
613
- req,
614
- this._strategy
615
- );
616
- return {
617
- response: await this.handleResult(result),
618
- refreshToken: result.refreshToken
619
- };
620
- }
621
- async handleResult(result) {
622
- const { profile } = await this.authHandler(result, this.resolverContext);
623
- const response = {
624
- providerInfo: {
625
- idToken: result.params.id_token,
626
- accessToken: result.accessToken,
627
- scope: result.params.scope,
628
- expiresInSeconds: result.params.expires_in
629
- },
630
- profile
631
- };
632
- if (this.signInResolver) {
633
- response.backstageIdentity = await this.signInResolver(
634
- {
635
- result,
636
- profile
637
- },
638
- this.resolverContext
639
- );
640
- }
641
- return response;
642
- }
643
- async refresh(req) {
644
- const { accessToken, params, refreshToken } = await executeRefreshTokenStrategy(
645
- this._strategy,
646
- req.refreshToken,
647
- req.scope
648
- );
649
- const fullProfile = await executeFetchUserProfileStrategy(
650
- this._strategy,
651
- accessToken
652
- );
653
- return {
654
- response: await this.handleResult({
655
- fullProfile,
656
- params,
657
- accessToken
658
- }),
659
- refreshToken
660
- };
661
- }
662
- }
663
- const atlassian = createAuthProviderIntegration({
664
- create(options) {
665
- return ({ providerId, globalConfig, config, resolverContext }) => OAuthEnvironmentHandler.mapConfig(config, (envConfig) => {
666
- var _a, _b;
667
- const clientId = envConfig.getString("clientId");
668
- const clientSecret = envConfig.getString("clientSecret");
669
- const scopes = envConfig.getString("scopes");
670
- const customCallbackUrl = envConfig.getOptionalString("callbackUrl");
671
- const callbackUrl = customCallbackUrl || `${globalConfig.baseUrl}/${providerId}/handler/frame`;
672
- const authHandler = (_a = options == null ? void 0 : options.authHandler) != null ? _a : atlassianDefaultAuthHandler;
673
- const provider = new AtlassianAuthProvider({
674
- clientId,
675
- clientSecret,
676
- scopes,
677
- callbackUrl,
678
- authHandler,
679
- signInResolver: (_b = options == null ? void 0 : options.signIn) == null ? void 0 : _b.resolver,
680
- resolverContext
681
- });
682
- return OAuthAdapter.fromConfig(globalConfig, provider, {
683
- providerId,
684
- callbackUrl
685
- });
686
- });
687
- }
688
- });
689
-
690
- class Auth0Strategy extends Auth0InternalStrategy__default["default"] {
691
- constructor(options, verify) {
692
- const optionsWithURLs = {
693
- ...options,
694
- authorizationURL: `https://${options.domain}/authorize`,
695
- tokenURL: `https://${options.domain}/oauth/token`,
696
- userInfoURL: `https://${options.domain}/userinfo`,
697
- apiUrl: `https://${options.domain}/api`
698
- };
699
- super(optionsWithURLs, verify);
700
- }
701
- }
702
-
703
- var __defProp$g = Object.defineProperty;
704
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
705
- var __publicField$g = (obj, key, value) => {
706
- __defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
588
+ var __defProp$f = Object.defineProperty;
589
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
590
+ var __publicField$f = (obj, key, value) => {
591
+ __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
707
592
  return value;
708
593
  };
709
594
  class Auth0AuthProvider {
710
595
  constructor(options) {
711
- __publicField$g(this, "_strategy");
712
- __publicField$g(this, "signInResolver");
713
- __publicField$g(this, "authHandler");
714
- __publicField$g(this, "resolverContext");
715
- __publicField$g(this, "audience");
716
- __publicField$g(this, "connection");
717
- __publicField$g(this, "connectionScope");
596
+ __publicField$f(this, "_strategy");
597
+ __publicField$f(this, "signInResolver");
598
+ __publicField$f(this, "authHandler");
599
+ __publicField$f(this, "resolverContext");
600
+ __publicField$f(this, "audience");
601
+ __publicField$f(this, "connection");
602
+ __publicField$f(this, "connectionScope");
718
603
  /**
719
604
  * Due to passport-auth0 forcing options.state = true,
720
605
  * passport-oauth2 requires express-session to be installed
@@ -723,7 +608,7 @@ class Auth0AuthProvider {
723
608
  * passport-oauth2, which is the StateStore implementation used when options.state = false,
724
609
  * allowing us to avoid using express-session in order to integrate with auth0.
725
610
  */
726
- __publicField$g(this, "store", {
611
+ __publicField$f(this, "store", {
727
612
  store(_req, cb) {
728
613
  cb(null, null);
729
614
  },
@@ -864,23 +749,23 @@ const auth0 = createAuthProviderIntegration({
864
749
  }
865
750
  });
866
751
 
867
- var __defProp$f = Object.defineProperty;
868
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
869
- var __publicField$f = (obj, key, value) => {
870
- __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
752
+ var __defProp$e = Object.defineProperty;
753
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
754
+ var __publicField$e = (obj, key, value) => {
755
+ __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
871
756
  return value;
872
757
  };
873
758
  const ALB_JWT_HEADER = "x-amzn-oidc-data";
874
759
  const ALB_ACCESS_TOKEN_HEADER = "x-amzn-oidc-accesstoken";
875
760
  class AwsAlbAuthProvider {
876
761
  constructor(options) {
877
- __publicField$f(this, "region");
878
- __publicField$f(this, "issuer");
879
- __publicField$f(this, "resolverContext");
880
- __publicField$f(this, "keyCache");
881
- __publicField$f(this, "authHandler");
882
- __publicField$f(this, "signInResolver");
883
- __publicField$f(this, "getKey", async (header) => {
762
+ __publicField$e(this, "region");
763
+ __publicField$e(this, "issuer");
764
+ __publicField$e(this, "resolverContext");
765
+ __publicField$e(this, "keyCache");
766
+ __publicField$e(this, "authHandler");
767
+ __publicField$e(this, "signInResolver");
768
+ __publicField$e(this, "getKey", async (header) => {
884
769
  if (!header.kid) {
885
770
  throw new errors.AuthenticationError("No key id was specified in header");
886
771
  }
@@ -1008,18 +893,18 @@ const awsAlb = createAuthProviderIntegration({
1008
893
  }
1009
894
  });
1010
895
 
1011
- var __defProp$e = Object.defineProperty;
1012
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1013
- var __publicField$e = (obj, key, value) => {
1014
- __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
896
+ var __defProp$d = Object.defineProperty;
897
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
898
+ var __publicField$d = (obj, key, value) => {
899
+ __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
1015
900
  return value;
1016
901
  };
1017
902
  class BitbucketAuthProvider {
1018
903
  constructor(options) {
1019
- __publicField$e(this, "_strategy");
1020
- __publicField$e(this, "signInResolver");
1021
- __publicField$e(this, "authHandler");
1022
- __publicField$e(this, "resolverContext");
904
+ __publicField$d(this, "_strategy");
905
+ __publicField$d(this, "signInResolver");
906
+ __publicField$d(this, "authHandler");
907
+ __publicField$d(this, "resolverContext");
1023
908
  this.signInResolver = options.signInResolver;
1024
909
  this.authHandler = options.authHandler;
1025
910
  this.resolverContext = options.resolverContext;
@@ -1187,10 +1072,10 @@ const commonByEmailResolver = async (info, ctx) => {
1187
1072
  });
1188
1073
  };
1189
1074
 
1190
- var __defProp$d = Object.defineProperty;
1191
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1192
- var __publicField$d = (obj, key, value) => {
1193
- __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
1075
+ var __defProp$c = Object.defineProperty;
1076
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1077
+ var __publicField$c = (obj, key, value) => {
1078
+ __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
1194
1079
  return value;
1195
1080
  };
1196
1081
  const CF_JWT_HEADER = "cf-access-jwt-assertion";
@@ -1198,12 +1083,12 @@ const COOKIE_AUTH_NAME = "CF_Authorization";
1198
1083
  const CACHE_PREFIX = "providers/cloudflare-access/profile-v1";
1199
1084
  class CloudflareAccessAuthProvider {
1200
1085
  constructor(options) {
1201
- __publicField$d(this, "teamName");
1202
- __publicField$d(this, "resolverContext");
1203
- __publicField$d(this, "authHandler");
1204
- __publicField$d(this, "signInResolver");
1205
- __publicField$d(this, "jwtKeySet");
1206
- __publicField$d(this, "cache");
1086
+ __publicField$c(this, "teamName");
1087
+ __publicField$c(this, "resolverContext");
1088
+ __publicField$c(this, "authHandler");
1089
+ __publicField$c(this, "signInResolver");
1090
+ __publicField$c(this, "jwtKeySet");
1091
+ __publicField$c(this, "cache");
1207
1092
  this.teamName = options.teamName;
1208
1093
  this.authHandler = options.authHandler;
1209
1094
  this.signInResolver = options.signInResolver;
@@ -1406,70 +1291,6 @@ const github = createAuthProviderIntegration({
1406
1291
  }
1407
1292
  });
1408
1293
 
1409
- function adaptLegacyOAuthHandler(authHandler) {
1410
- return authHandler && (async (result, ctx) => authHandler(
1411
- {
1412
- fullProfile: result.fullProfile,
1413
- accessToken: result.session.accessToken,
1414
- params: {
1415
- scope: result.session.scope,
1416
- id_token: result.session.idToken,
1417
- token_type: result.session.tokenType,
1418
- expires_in: result.session.expiresInSeconds
1419
- }
1420
- },
1421
- ctx
1422
- ));
1423
- }
1424
-
1425
- function adaptLegacyOAuthSignInResolver(signInResolver) {
1426
- return signInResolver && (async (input, ctx) => signInResolver(
1427
- {
1428
- profile: input.profile,
1429
- result: {
1430
- fullProfile: input.result.fullProfile,
1431
- accessToken: input.result.session.accessToken,
1432
- refreshToken: input.result.session.refreshToken,
1433
- params: {
1434
- scope: input.result.session.scope,
1435
- id_token: input.result.session.idToken,
1436
- token_type: input.result.session.tokenType,
1437
- expires_in: input.result.session.expiresInSeconds
1438
- }
1439
- }
1440
- },
1441
- ctx
1442
- ));
1443
- }
1444
-
1445
- function adaptOAuthSignInResolverToLegacy(resolvers) {
1446
- const legacyResolvers = {};
1447
- for (const name of Object.keys(resolvers)) {
1448
- const resolver = resolvers[name];
1449
- legacyResolvers[name] = () => async (input, ctx) => {
1450
- var _a;
1451
- return resolver(
1452
- {
1453
- profile: input.profile,
1454
- result: {
1455
- fullProfile: input.result.fullProfile,
1456
- session: {
1457
- accessToken: input.result.accessToken,
1458
- expiresInSeconds: input.result.params.expires_in,
1459
- scope: input.result.params.scope,
1460
- idToken: input.result.params.id_token,
1461
- tokenType: (_a = input.result.params.token_type) != null ? _a : "bearer",
1462
- refreshToken: input.result.refreshToken
1463
- }
1464
- }
1465
- },
1466
- ctx
1467
- );
1468
- };
1469
- }
1470
- return legacyResolvers;
1471
- }
1472
-
1473
1294
  const gitlab = createAuthProviderIntegration({
1474
1295
  create(options) {
1475
1296
  var _a;
@@ -1499,20 +1320,20 @@ const google = createAuthProviderIntegration({
1499
1320
 
1500
1321
  const BACKSTAGE_SESSION_EXPIRATION = 3600;
1501
1322
 
1502
- var __defProp$c = Object.defineProperty;
1503
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1504
- var __publicField$c = (obj, key, value) => {
1505
- __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
1323
+ var __defProp$b = Object.defineProperty;
1324
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1325
+ var __publicField$b = (obj, key, value) => {
1326
+ __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
1506
1327
  return value;
1507
1328
  };
1508
1329
  class MicrosoftAuthProvider {
1509
1330
  constructor(options) {
1510
- __publicField$c(this, "_strategy");
1511
- __publicField$c(this, "signInResolver");
1512
- __publicField$c(this, "authHandler");
1513
- __publicField$c(this, "logger");
1514
- __publicField$c(this, "resolverContext");
1515
- __publicField$c(this, "skipUserProfile", (accessToken) => {
1331
+ __publicField$b(this, "_strategy");
1332
+ __publicField$b(this, "signInResolver");
1333
+ __publicField$b(this, "authHandler");
1334
+ __publicField$b(this, "logger");
1335
+ __publicField$b(this, "resolverContext");
1336
+ __publicField$b(this, "skipUserProfile", (accessToken) => {
1516
1337
  const { aud, scp } = jose.decodeJwt(accessToken);
1517
1338
  const hasGraphReadScope = aud === "00000003-0000-0000-c000-000000000000" && scp.split(" ").map((s) => s.toLowerCase()).includes("user.read");
1518
1339
  return !hasGraphReadScope;
@@ -1688,18 +1509,18 @@ const oauth2 = createAuthProviderIntegration({
1688
1509
  }
1689
1510
  });
1690
1511
 
1691
- var __defProp$b = Object.defineProperty;
1692
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1693
- var __publicField$b = (obj, key, value) => {
1694
- __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
1512
+ var __defProp$a = Object.defineProperty;
1513
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1514
+ var __publicField$a = (obj, key, value) => {
1515
+ __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
1695
1516
  return value;
1696
1517
  };
1697
1518
  const OAUTH2_PROXY_JWT_HEADER = "X-OAUTH2-PROXY-ID-TOKEN";
1698
1519
  class Oauth2ProxyAuthProvider {
1699
1520
  constructor(options) {
1700
- __publicField$b(this, "resolverContext");
1701
- __publicField$b(this, "signInResolver");
1702
- __publicField$b(this, "authHandler");
1521
+ __publicField$a(this, "resolverContext");
1522
+ __publicField$a(this, "signInResolver");
1523
+ __publicField$a(this, "authHandler");
1703
1524
  this.resolverContext = options.resolverContext;
1704
1525
  this.signInResolver = options.signInResolver;
1705
1526
  this.authHandler = options.authHandler;
@@ -1774,20 +1595,20 @@ const oauth2Proxy = createAuthProviderIntegration({
1774
1595
  }
1775
1596
  });
1776
1597
 
1777
- var __defProp$a = Object.defineProperty;
1778
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1779
- var __publicField$a = (obj, key, value) => {
1780
- __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
1598
+ var __defProp$9 = Object.defineProperty;
1599
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1600
+ var __publicField$9 = (obj, key, value) => {
1601
+ __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
1781
1602
  return value;
1782
1603
  };
1783
1604
  class OidcAuthProvider {
1784
1605
  constructor(options) {
1785
- __publicField$a(this, "implementation");
1786
- __publicField$a(this, "scope");
1787
- __publicField$a(this, "prompt");
1788
- __publicField$a(this, "signInResolver");
1789
- __publicField$a(this, "authHandler");
1790
- __publicField$a(this, "resolverContext");
1606
+ __publicField$9(this, "implementation");
1607
+ __publicField$9(this, "scope");
1608
+ __publicField$9(this, "prompt");
1609
+ __publicField$9(this, "signInResolver");
1610
+ __publicField$9(this, "authHandler");
1611
+ __publicField$9(this, "resolverContext");
1791
1612
  this.implementation = this.setupStrategy(options);
1792
1613
  this.scope = options.scope;
1793
1614
  this.prompt = options.prompt;
@@ -1948,176 +1769,16 @@ const oidc = createAuthProviderIntegration({
1948
1769
  }
1949
1770
  });
1950
1771
 
1951
- var __defProp$9 = Object.defineProperty;
1952
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1953
- var __publicField$9 = (obj, key, value) => {
1954
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
1955
- return value;
1956
- };
1957
- class OktaAuthProvider {
1958
- constructor(options) {
1959
- __publicField$9(this, "strategy");
1960
- __publicField$9(this, "signInResolver");
1961
- __publicField$9(this, "authHandler");
1962
- __publicField$9(this, "resolverContext");
1963
- __publicField$9(this, "additionalScopes");
1964
- /**
1965
- * Due to passport-okta-oauth forcing options.state = true,
1966
- * passport-oauth2 requires express-session to be installed
1967
- * so that the 'state' parameter of the oauth2 flow can be stored.
1968
- * This implementation of StateStore matches the NullStore found within
1969
- * passport-oauth2, which is the StateStore implementation used when options.state = false,
1970
- * allowing us to avoid using express-session in order to integrate with Okta.
1971
- */
1972
- __publicField$9(this, "store", {
1973
- store(_req, cb) {
1974
- cb(null, null);
1975
- },
1976
- verify(_req, _state, cb) {
1977
- cb(null, true);
1978
- }
1979
- });
1980
- this.signInResolver = options.signInResolver;
1981
- this.authHandler = options.authHandler;
1982
- this.resolverContext = options.resolverContext;
1983
- this.additionalScopes = options.additionalScopes || "";
1984
- this.strategy = new passportOktaOauth.Strategy(
1985
- {
1986
- clientID: options.clientId,
1987
- clientSecret: options.clientSecret,
1988
- callbackURL: options.callbackUrl,
1989
- audience: options.audience,
1990
- authServerID: options.authServerId,
1991
- idp: options.idp,
1992
- passReqToCallback: false,
1993
- store: this.store,
1994
- response_type: "code"
1995
- },
1996
- (accessToken, refreshToken, params, fullProfile, done) => {
1997
- done(
1998
- void 0,
1999
- {
2000
- accessToken,
2001
- refreshToken,
2002
- params,
2003
- fullProfile
2004
- },
2005
- {
2006
- refreshToken
2007
- }
2008
- );
2009
- }
2010
- );
2011
- }
2012
- combineScopeStrings(scopesA, scopesB) {
2013
- const scopesAArray = scopesA.split(" ");
2014
- const scopesBArray = scopesB.split(" ");
2015
- const combinedScopes = /* @__PURE__ */ new Set([...scopesAArray, ...scopesBArray]);
2016
- return Array.from(combinedScopes).join(" ");
2017
- }
2018
- async start(req) {
2019
- const scope = this.combineScopeStrings(req.scope, this.additionalScopes);
2020
- return await executeRedirectStrategy(req, this.strategy, {
2021
- accessType: "offline",
2022
- prompt: "consent",
2023
- scope,
2024
- state: encodeState(req.state)
2025
- });
2026
- }
2027
- async handler(req) {
2028
- const { result, privateInfo } = await executeFrameHandlerStrategy(req, this.strategy);
2029
- return {
2030
- response: await this.handleResult(result),
2031
- refreshToken: privateInfo.refreshToken
2032
- };
2033
- }
2034
- async refresh(req) {
2035
- const scope = this.combineScopeStrings(req.scope, this.additionalScopes);
2036
- const { accessToken, refreshToken, params } = await executeRefreshTokenStrategy(this.strategy, req.refreshToken, scope);
2037
- const fullProfile = await executeFetchUserProfileStrategy(
2038
- this.strategy,
2039
- accessToken
2040
- );
2041
- return {
2042
- response: await this.handleResult({
2043
- fullProfile,
2044
- params,
2045
- accessToken
2046
- }),
2047
- refreshToken
2048
- };
2049
- }
2050
- async handleResult(result) {
2051
- const { profile } = await this.authHandler(result, this.resolverContext);
2052
- const response = {
2053
- providerInfo: {
2054
- idToken: result.params.id_token,
2055
- accessToken: result.accessToken,
2056
- scope: result.params.scope,
2057
- expiresInSeconds: result.params.expires_in
2058
- },
2059
- profile
2060
- };
2061
- if (this.signInResolver) {
2062
- response.backstageIdentity = await this.signInResolver(
2063
- {
2064
- result,
2065
- profile
2066
- },
2067
- this.resolverContext
2068
- );
2069
- }
2070
- return response;
2071
- }
2072
- }
2073
1772
  const okta = createAuthProviderIntegration({
2074
1773
  create(options) {
2075
- return ({ providerId, globalConfig, config, resolverContext }) => OAuthEnvironmentHandler.mapConfig(config, (envConfig) => {
2076
- var _a;
2077
- const clientId = envConfig.getString("clientId");
2078
- const clientSecret = envConfig.getString("clientSecret");
2079
- const audience = envConfig.getString("audience");
2080
- const authServerId = envConfig.getOptionalString("authServerId");
2081
- const idp = envConfig.getOptionalString("idp");
2082
- const customCallbackUrl = envConfig.getOptionalString("callbackUrl");
2083
- const callbackUrl = customCallbackUrl || `${globalConfig.baseUrl}/${providerId}/handler/frame`;
2084
- const additionalScopes = envConfig.getOptionalString("additionalScopes");
2085
- if (!audience.startsWith("https://")) {
2086
- throw new Error("URL for 'audience' must start with 'https://'.");
2087
- }
2088
- const authHandler = (options == null ? void 0 : options.authHandler) ? options.authHandler : async ({ fullProfile, params }) => ({
2089
- profile: makeProfileInfo(fullProfile, params.id_token)
2090
- });
2091
- const provider = new OktaAuthProvider({
2092
- audience,
2093
- authServerId,
2094
- idp,
2095
- clientId,
2096
- clientSecret,
2097
- callbackUrl,
2098
- authHandler,
2099
- signInResolver: (_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver,
2100
- resolverContext,
2101
- additionalScopes
2102
- });
2103
- return OAuthAdapter.fromConfig(globalConfig, provider, {
2104
- providerId,
2105
- callbackUrl
2106
- });
1774
+ var _a;
1775
+ return pluginAuthNode.createOAuthProviderFactory({
1776
+ authenticator: pluginAuthBackendModuleOktaProvider.oktaAuthenticator,
1777
+ profileTransform: adaptLegacyOAuthHandler(options == null ? void 0 : options.authHandler),
1778
+ signInResolver: adaptLegacyOAuthSignInResolver((_a = options == null ? void 0 : options.signIn) == null ? void 0 : _a.resolver)
2107
1779
  });
2108
1780
  },
2109
1781
  resolvers: {
2110
- /**
2111
- * Looks up the user by matching their email local part to the entity name.
2112
- */
2113
- emailLocalPartMatchingUserEntityName: () => commonByEmailLocalPartResolver,
2114
- /**
2115
- * Looks up the user by matching their email to the entity email.
2116
- */
2117
- emailMatchingUserEntityProfileEmail: () => commonByEmailResolver,
2118
- /**
2119
- * Looks up the user by matching their email to the `okta.com/email` annotation.
2120
- */
2121
1782
  emailMatchingUserEntityAnnotation() {
2122
1783
  return async (info, ctx) => {
2123
1784
  const { profile } = info;
@@ -2386,7 +2047,7 @@ class BitbucketServerAuthProvider {
2386
2047
  this.signInResolver = options.signInResolver;
2387
2048
  this.authHandler = options.authHandler;
2388
2049
  this.resolverContext = options.resolverContext;
2389
- this.strategy = new OAuth2Strategy.Strategy(
2050
+ this.strategy = new passportOauth2.Strategy(
2390
2051
  {
2391
2052
  authorizationURL: options.authorizationUrl,
2392
2053
  tokenURL: options.tokenUrl,