@backstage/plugin-auth-backend 0.14.2-next.0 → 0.15.0-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,27 @@
1
1
  # @backstage/plugin-auth-backend
2
2
 
3
+ ## 0.15.0-next.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 9d4040777e: **BREAKING**: Removed all directly exported auth provider factories, option types, and sign-in resolvers. For example: `AwsAlbProviderOptions`, `bitbucketUserIdSignInResolver`, `createGithubProvider`. These are all still accessible via the `providers` export. For example, use `providers.github.create()` rather than `createGithubProvider()`, and `providers.bitbucket.resolvers.userIdMatchingUserEntityAnnotation()` rather than `bitbucketUserIdSignInResolver`.
8
+
9
+ **BREAKING**: Removed the exported `AuthProviderFactoryOptions` type as well as the deprecated option fields of the `AuthProviderFactory` callback. This includes the `tokenManager`, `tokenIssuer`, `discovery`, and `catalogApi` fields. Existing usage of these should be replaced with the new utilities in the `resolverContext` field. The deprecated `TokenIssuer` type is now also removed, since it is no longer used.
10
+
11
+ **BREAKING**: Removed `getEntityClaims`, use `getDefaultOwnershipEntityRefs` instead.
12
+
13
+ **DEPRECATION**: Deprecated `AtlassianAuthProvider` as it was unintentionally exported.
14
+
15
+ ### Patch Changes
16
+
17
+ - f2cf79d62e: Added an option for the auth backend router to select the algorithm for the JWT token signing keys
18
+ - Updated dependencies
19
+ - @backstage/catalog-model@1.1.0-next.1
20
+ - @backstage/backend-common@0.14.1-next.1
21
+ - @backstage/errors@1.1.0-next.0
22
+ - @backstage/catalog-client@1.0.4-next.1
23
+ - @backstage/plugin-auth-node@0.2.3-next.1
24
+
3
25
  ## 0.14.2-next.0
4
26
 
5
27
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -15,6 +15,7 @@ var fetch = require('node-fetch');
15
15
  var NodeCache = require('node-cache');
16
16
  var jose = require('jose');
17
17
  var passportBitbucketOauth2 = require('passport-bitbucket-oauth2');
18
+ var googleAuthLibrary = require('google-auth-library');
18
19
  var passportGithub2 = require('passport-github2');
19
20
  var passportGitlab2 = require('passport-gitlab2');
20
21
  var passportGoogleOauth20 = require('passport-google-oauth20');
@@ -24,7 +25,6 @@ var openidClient = require('openid-client');
24
25
  var passportOktaOauth = require('passport-okta-oauth');
25
26
  var passportOneloginOauth = require('passport-onelogin-oauth');
26
27
  var passportSaml = require('passport-saml');
27
- var googleAuthLibrary = require('google-auth-library');
28
28
  var catalogClient = require('@backstage/catalog-client');
29
29
  var catalogModel = require('@backstage/catalog-model');
30
30
  var luxon = require('luxon');
@@ -645,7 +645,6 @@ const atlassian = createAuthProviderIntegration({
645
645
  });
646
646
  }
647
647
  });
648
- const createAtlassianProvider = atlassian.create;
649
648
 
650
649
  class Auth0Strategy extends OAuth2Strategy__default["default"] {
651
650
  constructor(options, verify) {
@@ -758,7 +757,6 @@ const auth0 = createAuthProviderIntegration({
758
757
  });
759
758
  }
760
759
  });
761
- const createAuth0Provider = auth0.create;
762
760
 
763
761
  const ALB_JWT_HEADER = "x-amzn-oidc-data";
764
762
  const ALB_ACCESS_TOKEN_HEADER = "x-amzn-oidc-accesstoken";
@@ -872,7 +870,6 @@ const awsAlb = createAuthProviderIntegration({
872
870
  };
873
871
  }
874
872
  });
875
- const createAwsAlbProvider = awsAlb.create;
876
873
 
877
874
  class BitbucketAuthProvider {
878
875
  constructor(options) {
@@ -997,9 +994,86 @@ const bitbucket = createAuthProviderIntegration({
997
994
  }
998
995
  }
999
996
  });
1000
- const createBitbucketProvider = bitbucket.create;
1001
- const bitbucketUsernameSignInResolver = bitbucket.resolvers.usernameMatchingUserEntityAnnotation();
1002
- const bitbucketUserIdSignInResolver = bitbucket.resolvers.userIdMatchingUserEntityAnnotation();
997
+
998
+ const IAP_JWT_HEADER = "x-goog-iap-jwt-assertion";
999
+
1000
+ function createTokenValidator(audience, mockClient) {
1001
+ const client = mockClient != null ? mockClient : new googleAuthLibrary.OAuth2Client();
1002
+ return async function tokenValidator(token) {
1003
+ const response = await client.getIapPublicKeys();
1004
+ const ticket = await client.verifySignedJwtWithCertsAsync(token, response.pubkeys, audience, ["https://cloud.google.com/iap"]);
1005
+ const payload = ticket.getPayload();
1006
+ if (!payload) {
1007
+ throw new TypeError("Token had no payload");
1008
+ }
1009
+ return payload;
1010
+ };
1011
+ }
1012
+ async function parseRequestToken(jwtToken, tokenValidator) {
1013
+ if (typeof jwtToken !== "string" || !jwtToken) {
1014
+ throw new errors.AuthenticationError(`Missing Google IAP header: ${IAP_JWT_HEADER}`);
1015
+ }
1016
+ let payload;
1017
+ try {
1018
+ payload = await tokenValidator(jwtToken);
1019
+ } catch (e) {
1020
+ throw new errors.AuthenticationError(`Google IAP token verification failed, ${e}`);
1021
+ }
1022
+ if (!payload.sub || !payload.email) {
1023
+ throw new errors.AuthenticationError("Google IAP token payload is missing sub and/or email claim");
1024
+ }
1025
+ return {
1026
+ iapToken: {
1027
+ ...payload,
1028
+ sub: payload.sub,
1029
+ email: payload.email
1030
+ }
1031
+ };
1032
+ }
1033
+ const defaultAuthHandler$1 = async ({
1034
+ iapToken
1035
+ }) => ({ profile: { email: iapToken.email } });
1036
+
1037
+ class GcpIapProvider {
1038
+ constructor(options) {
1039
+ this.authHandler = options.authHandler;
1040
+ this.signInResolver = options.signInResolver;
1041
+ this.tokenValidator = options.tokenValidator;
1042
+ this.resolverContext = options.resolverContext;
1043
+ }
1044
+ async start() {
1045
+ }
1046
+ async frameHandler() {
1047
+ }
1048
+ async refresh(req, res) {
1049
+ const result = await parseRequestToken(req.header(IAP_JWT_HEADER), this.tokenValidator);
1050
+ const { profile } = await this.authHandler(result, this.resolverContext);
1051
+ const backstageIdentity = await this.signInResolver({ profile, result }, this.resolverContext);
1052
+ const response = {
1053
+ providerInfo: { iapToken: result.iapToken },
1054
+ profile,
1055
+ backstageIdentity: prepareBackstageIdentityResponse(backstageIdentity)
1056
+ };
1057
+ res.json(response);
1058
+ }
1059
+ }
1060
+ const gcpIap = createAuthProviderIntegration({
1061
+ create(options) {
1062
+ return ({ config, resolverContext }) => {
1063
+ var _a;
1064
+ const audience = config.getString("audience");
1065
+ const authHandler = (_a = options.authHandler) != null ? _a : defaultAuthHandler$1;
1066
+ const signInResolver = options.signIn.resolver;
1067
+ const tokenValidator = createTokenValidator(audience);
1068
+ return new GcpIapProvider({
1069
+ authHandler,
1070
+ signInResolver,
1071
+ tokenValidator,
1072
+ resolverContext
1073
+ });
1074
+ };
1075
+ }
1076
+ });
1003
1077
 
1004
1078
  const ACCESS_TOKEN_PREFIX = "access-token.";
1005
1079
  const BACKSTAGE_SESSION_EXPIRATION = 3600;
@@ -1144,7 +1218,6 @@ const github = createAuthProviderIntegration({
1144
1218
  }
1145
1219
  }
1146
1220
  });
1147
- const createGithubProvider = github.create;
1148
1221
 
1149
1222
  const gitlabDefaultAuthHandler = async ({
1150
1223
  fullProfile,
@@ -1240,7 +1313,6 @@ const gitlab = createAuthProviderIntegration({
1240
1313
  });
1241
1314
  }
1242
1315
  });
1243
- const createGitlabProvider = gitlab.create;
1244
1316
 
1245
1317
  const commonByEmailLocalPartResolver = async (info, ctx) => {
1246
1318
  const { profile } = info;
@@ -1375,8 +1447,6 @@ const google = createAuthProviderIntegration({
1375
1447
  }
1376
1448
  }
1377
1449
  });
1378
- const createGoogleProvider = google.create;
1379
- const googleEmailSignInResolver = google.resolvers.emailMatchingUserEntityAnnotation();
1380
1450
 
1381
1451
  class MicrosoftAuthProvider {
1382
1452
  constructor(options) {
@@ -1505,8 +1575,6 @@ const microsoft = createAuthProviderIntegration({
1505
1575
  }
1506
1576
  }
1507
1577
  });
1508
- const createMicrosoftProvider = microsoft.create;
1509
- const microsoftEmailSignInResolver = microsoft.resolvers.emailMatchingUserEntityAnnotation();
1510
1578
 
1511
1579
  class OAuth2AuthProvider {
1512
1580
  constructor(options) {
@@ -1627,7 +1695,6 @@ const oauth2 = createAuthProviderIntegration({
1627
1695
  });
1628
1696
  }
1629
1697
  });
1630
- const createOAuth2Provider = oauth2.create;
1631
1698
 
1632
1699
  const OAUTH2_PROXY_JWT_HEADER = "X-OAUTH2-PROXY-ID-TOKEN";
1633
1700
  class Oauth2ProxyAuthProvider {
@@ -1679,7 +1746,7 @@ class Oauth2ProxyAuthProvider {
1679
1746
  };
1680
1747
  }
1681
1748
  }
1682
- async function defaultAuthHandler$1(result) {
1749
+ async function defaultAuthHandler(result) {
1683
1750
  return {
1684
1751
  profile: {
1685
1752
  email: result.getHeader("x-forwarded-email"),
@@ -1695,12 +1762,11 @@ const oauth2Proxy = createAuthProviderIntegration({
1695
1762
  return new Oauth2ProxyAuthProvider({
1696
1763
  resolverContext,
1697
1764
  signInResolver,
1698
- authHandler: authHandler != null ? authHandler : defaultAuthHandler$1
1765
+ authHandler: authHandler != null ? authHandler : defaultAuthHandler
1699
1766
  });
1700
1767
  };
1701
1768
  }
1702
1769
  });
1703
- const createOauth2ProxyProvider = oauth2Proxy.create;
1704
1770
 
1705
1771
  class OidcAuthProvider {
1706
1772
  constructor(options) {
@@ -1826,7 +1892,6 @@ const oidc = createAuthProviderIntegration({
1826
1892
  });
1827
1893
  }
1828
1894
  });
1829
- const createOidcProvider = oidc.create;
1830
1895
 
1831
1896
  class OktaAuthProvider {
1832
1897
  constructor(options) {
@@ -1955,8 +2020,6 @@ const okta = createAuthProviderIntegration({
1955
2020
  }
1956
2021
  }
1957
2022
  });
1958
- const createOktaProvider = okta.create;
1959
- const oktaEmailSignInResolver = okta.resolvers.emailMatchingUserEntityAnnotation();
1960
2023
 
1961
2024
  class OneLoginProvider {
1962
2025
  constructor(options) {
@@ -2055,7 +2118,6 @@ const onelogin = createAuthProviderIntegration({
2055
2118
  });
2056
2119
  }
2057
2120
  });
2058
- const createOneLoginProvider = onelogin.create;
2059
2121
 
2060
2122
  class SamlAuthProvider {
2061
2123
  constructor(options) {
@@ -2147,89 +2209,6 @@ const saml = createAuthProviderIntegration({
2147
2209
  }
2148
2210
  }
2149
2211
  });
2150
- const createSamlProvider = saml.create;
2151
- const samlNameIdEntityNameSignInResolver = saml.resolvers.nameIdMatchingUserEntityName();
2152
-
2153
- const IAP_JWT_HEADER = "x-goog-iap-jwt-assertion";
2154
-
2155
- function createTokenValidator(audience, mockClient) {
2156
- const client = mockClient != null ? mockClient : new googleAuthLibrary.OAuth2Client();
2157
- return async function tokenValidator(token) {
2158
- const response = await client.getIapPublicKeys();
2159
- const ticket = await client.verifySignedJwtWithCertsAsync(token, response.pubkeys, audience, ["https://cloud.google.com/iap"]);
2160
- const payload = ticket.getPayload();
2161
- if (!payload) {
2162
- throw new TypeError("Token had no payload");
2163
- }
2164
- return payload;
2165
- };
2166
- }
2167
- async function parseRequestToken(jwtToken, tokenValidator) {
2168
- if (typeof jwtToken !== "string" || !jwtToken) {
2169
- throw new errors.AuthenticationError(`Missing Google IAP header: ${IAP_JWT_HEADER}`);
2170
- }
2171
- let payload;
2172
- try {
2173
- payload = await tokenValidator(jwtToken);
2174
- } catch (e) {
2175
- throw new errors.AuthenticationError(`Google IAP token verification failed, ${e}`);
2176
- }
2177
- if (!payload.sub || !payload.email) {
2178
- throw new errors.AuthenticationError("Google IAP token payload is missing sub and/or email claim");
2179
- }
2180
- return {
2181
- iapToken: {
2182
- ...payload,
2183
- sub: payload.sub,
2184
- email: payload.email
2185
- }
2186
- };
2187
- }
2188
- const defaultAuthHandler = async ({
2189
- iapToken
2190
- }) => ({ profile: { email: iapToken.email } });
2191
-
2192
- class GcpIapProvider {
2193
- constructor(options) {
2194
- this.authHandler = options.authHandler;
2195
- this.signInResolver = options.signInResolver;
2196
- this.tokenValidator = options.tokenValidator;
2197
- this.resolverContext = options.resolverContext;
2198
- }
2199
- async start() {
2200
- }
2201
- async frameHandler() {
2202
- }
2203
- async refresh(req, res) {
2204
- const result = await parseRequestToken(req.header(IAP_JWT_HEADER), this.tokenValidator);
2205
- const { profile } = await this.authHandler(result, this.resolverContext);
2206
- const backstageIdentity = await this.signInResolver({ profile, result }, this.resolverContext);
2207
- const response = {
2208
- providerInfo: { iapToken: result.iapToken },
2209
- profile,
2210
- backstageIdentity: prepareBackstageIdentityResponse(backstageIdentity)
2211
- };
2212
- res.json(response);
2213
- }
2214
- }
2215
- const gcpIap = createAuthProviderIntegration({
2216
- create(options) {
2217
- return ({ config, resolverContext }) => {
2218
- var _a;
2219
- const audience = config.getString("audience");
2220
- const authHandler = (_a = options.authHandler) != null ? _a : defaultAuthHandler;
2221
- const signInResolver = options.signIn.resolver;
2222
- const tokenValidator = createTokenValidator(audience);
2223
- return new GcpIapProvider({
2224
- authHandler,
2225
- signInResolver,
2226
- tokenValidator,
2227
- resolverContext
2228
- });
2229
- };
2230
- }
2231
- });
2232
- const createGcpIapProvider = gcpIap.create;
2233
2212
 
2234
2213
  const providers = Object.freeze({
2235
2214
  atlassian,
@@ -2248,21 +2227,20 @@ const providers = Object.freeze({
2248
2227
  onelogin,
2249
2228
  saml
2250
2229
  });
2251
-
2252
- const factories = {
2253
- google: createGoogleProvider(),
2254
- github: createGithubProvider(),
2255
- gitlab: createGitlabProvider(),
2256
- saml: createSamlProvider(),
2257
- okta: createOktaProvider(),
2258
- auth0: createAuth0Provider(),
2259
- microsoft: createMicrosoftProvider(),
2260
- oauth2: createOAuth2Provider(),
2261
- oidc: createOidcProvider(),
2262
- onelogin: createOneLoginProvider(),
2263
- awsalb: createAwsAlbProvider(),
2264
- bitbucket: createBitbucketProvider(),
2265
- atlassian: createAtlassianProvider()
2230
+ const defaultAuthProviderFactories = {
2231
+ google: google.create(),
2232
+ github: github.create(),
2233
+ gitlab: gitlab.create(),
2234
+ saml: saml.create(),
2235
+ okta: okta.create(),
2236
+ auth0: auth0.create(),
2237
+ microsoft: microsoft.create(),
2238
+ oauth2: oauth2.create(),
2239
+ oidc: oidc.create(),
2240
+ onelogin: onelogin.create(),
2241
+ awsalb: awsAlb.create(),
2242
+ bitbucket: bitbucket.create(),
2243
+ atlassian: atlassian.create()
2266
2244
  };
2267
2245
 
2268
2246
  function createOidcRouter(options) {
@@ -2598,16 +2576,6 @@ class CatalogIdentityClient {
2598
2576
  }
2599
2577
  }
2600
2578
 
2601
- function getEntityClaims(entity) {
2602
- var _a, _b;
2603
- const userRef = catalogModel.stringifyEntityRef(entity);
2604
- const membershipRefs = (_b = (_a = entity.relations) == null ? void 0 : _a.filter((r) => r.type === catalogModel.RELATION_MEMBER_OF && r.targetRef.startsWith("group:")).map((r) => r.targetRef)) != null ? _b : [];
2605
- return {
2606
- sub: userRef,
2607
- ent: [userRef, ...membershipRefs]
2608
- };
2609
- }
2610
-
2611
2579
  function getDefaultOwnershipEntityRefs(entity) {
2612
2580
  var _a, _b;
2613
2581
  const membershipRefs = (_b = (_a = entity.relations) == null ? void 0 : _a.filter((r) => r.type === catalogModel.RELATION_MEMBER_OF && r.targetRef.startsWith("group:")).map((r) => r.targetRef)) != null ? _b : [];
@@ -2687,6 +2655,7 @@ async function createRouter(options) {
2687
2655
  discovery,
2688
2656
  database,
2689
2657
  tokenManager,
2658
+ tokenFactoryAlgorithm,
2690
2659
  providerFactories
2691
2660
  } = options;
2692
2661
  const router = Router__default["default"]();
@@ -2698,7 +2667,8 @@ async function createRouter(options) {
2698
2667
  issuer: authUrl,
2699
2668
  keyStore,
2700
2669
  keyDurationSeconds,
2701
- logger: logger.child({ component: "token-factory" })
2670
+ logger: logger.child({ component: "token-factory" }),
2671
+ algorithm: tokenFactoryAlgorithm
2702
2672
  });
2703
2673
  const catalogApi = new catalogClient.CatalogClient({ discoveryApi: discovery });
2704
2674
  const secret = config.getOptionalString("auth.session.secret");
@@ -2719,7 +2689,7 @@ async function createRouter(options) {
2719
2689
  router.use(express__default["default"].urlencoded({ extended: false }));
2720
2690
  router.use(express__default["default"].json());
2721
2691
  const allProviderFactories = {
2722
- ...factories,
2692
+ ...defaultAuthProviderFactories,
2723
2693
  ...providerFactories
2724
2694
  };
2725
2695
  const providersConfig = config.getConfig("auth.providers");
@@ -2738,10 +2708,6 @@ async function createRouter(options) {
2738
2708
  },
2739
2709
  config: providersConfig.getConfig(providerId),
2740
2710
  logger,
2741
- tokenManager,
2742
- tokenIssuer,
2743
- discovery,
2744
- catalogApi,
2745
2711
  resolverContext: CatalogAuthResolverContext.create({
2746
2712
  logger,
2747
2713
  catalogApi,
@@ -2800,40 +2766,19 @@ function createOriginFilter(config) {
2800
2766
  };
2801
2767
  }
2802
2768
 
2769
+ exports.AtlassianAuthProvider = AtlassianAuthProvider;
2803
2770
  exports.CatalogIdentityClient = CatalogIdentityClient;
2804
2771
  exports.OAuthAdapter = OAuthAdapter;
2805
2772
  exports.OAuthEnvironmentHandler = OAuthEnvironmentHandler;
2806
- exports.bitbucketUserIdSignInResolver = bitbucketUserIdSignInResolver;
2807
- exports.bitbucketUsernameSignInResolver = bitbucketUsernameSignInResolver;
2808
- exports.createAtlassianProvider = createAtlassianProvider;
2809
- exports.createAuth0Provider = createAuth0Provider;
2810
- exports.createAwsAlbProvider = createAwsAlbProvider;
2811
- exports.createBitbucketProvider = createBitbucketProvider;
2812
- exports.createGcpIapProvider = createGcpIapProvider;
2813
- exports.createGithubProvider = createGithubProvider;
2814
- exports.createGitlabProvider = createGitlabProvider;
2815
- exports.createGoogleProvider = createGoogleProvider;
2816
- exports.createMicrosoftProvider = createMicrosoftProvider;
2817
- exports.createOAuth2Provider = createOAuth2Provider;
2818
- exports.createOauth2ProxyProvider = createOauth2ProxyProvider;
2819
- exports.createOidcProvider = createOidcProvider;
2820
- exports.createOktaProvider = createOktaProvider;
2821
- exports.createOneLoginProvider = createOneLoginProvider;
2822
2773
  exports.createOriginFilter = createOriginFilter;
2823
2774
  exports.createRouter = createRouter;
2824
- exports.createSamlProvider = createSamlProvider;
2825
- exports.defaultAuthProviderFactories = factories;
2775
+ exports.defaultAuthProviderFactories = defaultAuthProviderFactories;
2826
2776
  exports.encodeState = encodeState;
2827
2777
  exports.ensuresXRequestedWith = ensuresXRequestedWith;
2828
2778
  exports.getDefaultOwnershipEntityRefs = getDefaultOwnershipEntityRefs;
2829
- exports.getEntityClaims = getEntityClaims;
2830
- exports.googleEmailSignInResolver = googleEmailSignInResolver;
2831
- exports.microsoftEmailSignInResolver = microsoftEmailSignInResolver;
2832
- exports.oktaEmailSignInResolver = oktaEmailSignInResolver;
2833
2779
  exports.postMessageResponse = postMessageResponse;
2834
2780
  exports.prepareBackstageIdentityResponse = prepareBackstageIdentityResponse;
2835
2781
  exports.providers = providers;
2836
2782
  exports.readState = readState;
2837
- exports.samlNameIdEntityNameSignInResolver = samlNameIdEntityNameSignInResolver;
2838
2783
  exports.verifyNonce = verifyNonce;
2839
2784
  //# sourceMappingURL=index.cjs.js.map