@backstage/plugin-auth-backend 0.20.4-next.0 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @backstage/plugin-auth-backend
2
2
 
3
+ ## 0.20.4-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 23a98f8: Migrated the AWS ALB auth provider to new `@backstage/plugin-auth-backend-module-aws-alb-provider` module package.
8
+ - Updated dependencies
9
+ - @backstage/catalog-model@1.4.4-next.0
10
+ - @backstage/catalog-client@1.6.0-next.1
11
+ - @backstage/backend-plugin-api@0.6.10-next.1
12
+ - @backstage/backend-common@0.21.0-next.1
13
+ - @backstage/plugin-auth-backend-module-aws-alb-provider@0.1.0-next.0
14
+ - @backstage/config@1.1.1
15
+ - @backstage/errors@1.2.3
16
+ - @backstage/plugin-auth-backend-module-atlassian-provider@0.1.2-next.1
17
+ - @backstage/plugin-auth-backend-module-gcp-iap-provider@0.2.4-next.1
18
+ - @backstage/plugin-auth-backend-module-github-provider@0.1.7-next.1
19
+ - @backstage/plugin-auth-backend-module-gitlab-provider@0.1.7-next.1
20
+ - @backstage/plugin-auth-backend-module-google-provider@0.1.7-next.1
21
+ - @backstage/plugin-auth-backend-module-microsoft-provider@0.1.5-next.1
22
+ - @backstage/plugin-auth-backend-module-oauth2-provider@0.1.7-next.1
23
+ - @backstage/plugin-auth-backend-module-oauth2-proxy-provider@0.1.2-next.1
24
+ - @backstage/plugin-auth-backend-module-oidc-provider@0.1.0-next.1
25
+ - @backstage/plugin-auth-backend-module-okta-provider@0.0.3-next.1
26
+ - @backstage/plugin-auth-node@0.4.4-next.1
27
+ - @backstage/plugin-catalog-node@1.6.2-next.1
28
+
3
29
  ## 0.20.4-next.0
4
30
 
5
31
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -14,10 +14,10 @@ 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');
@@ -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$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);
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$d(this, "baseCookieOptions");
256
- __publicField$d(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$d(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$d(this, "getRefreshTokenFromCookie", (req) => {
251
+ __publicField$c(this, "getRefreshTokenFromCookie", (req) => {
272
252
  return req.cookies[`${this.options.providerId}-refresh-token`];
273
253
  });
274
- __publicField$d(this, "getGrantedScopeFromCookie", (req) => {
254
+ __publicField$c(this, "getGrantedScopeFromCookie", (req) => {
275
255
  return req.cookies[`${this.options.providerId}-granted-scope`];
276
256
  });
277
- __publicField$d(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$d(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$d(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$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);
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$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");
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$c(this, "store", {
592
+ __publicField$b(this, "store", {
613
593
  store(_req, cb) {
614
594
  cb(null, null);
615
595
  },
@@ -750,147 +730,14 @@ const auth0 = createAuthProviderIntegration({
750
730
  }
751
731
  });
752
732
 
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
- 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$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
- 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