@backstage/plugin-auth-backend 0.7.0 → 0.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @backstage/plugin-auth-backend
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 67349916ac: The `sub` claim in Backstage tokens generated by the default Google and OIDC sign-in resolvers are now full entity references of the format `<kind>:<namespace>/<name>`.
8
+
9
+ ### Patch Changes
10
+
11
+ - 033493a8af: Running the `auth-backend` on multiple domains, perhaps different domains depending on the `auth.environment`, was previously not possible as the `domain` name of the cookie was taken from `backend.baseUrl`. This prevented any cookies to be set in the start of the auth flow as the domain of the cookie would not match the domain of the callbackUrl configured in the OAuth app. This change checks if a provider supports custom `callbackUrl`'s to be configured in the application configuration and uses the domain from that, allowing the `domain`'s to match and the cookie to be set.
12
+ - Updated dependencies
13
+ - @backstage/backend-common@0.10.5
14
+
3
15
  ## 0.7.0
4
16
 
5
17
  ### Minor Changes
package/dist/index.cjs.js CHANGED
@@ -149,6 +149,16 @@ const verifyNonce = (req, providerId) => {
149
149
  throw new Error("Invalid nonce");
150
150
  }
151
151
  };
152
+ const getCookieConfig = (authUrl, providerId) => {
153
+ const { hostname: cookieDomain, pathname, protocol } = authUrl;
154
+ const secure = protocol === "https:";
155
+ const cookiePath = pathname.endsWith(`${providerId}/handler/frame`) ? pathname.slice(0, -"/handler/frame".length) : `${pathname}/${providerId}`;
156
+ return {
157
+ cookieDomain,
158
+ cookiePath,
159
+ secure
160
+ };
161
+ };
152
162
 
153
163
  class OAuthEnvironmentHandler {
154
164
  constructor(handlers) {
@@ -313,14 +323,14 @@ class OAuthAdapter {
313
323
  };
314
324
  }
315
325
  static fromConfig(config, handlers, options) {
326
+ var _a;
316
327
  const { origin: appOrigin } = new url.URL(config.appUrl);
317
- const secure = config.baseUrl.startsWith("https://");
318
- const url$1 = new url.URL(config.baseUrl);
319
- const cookiePath = `${url$1.pathname}/${options.providerId}`;
328
+ const authUrl = new url.URL((_a = options.callbackUrl) != null ? _a : config.baseUrl);
329
+ const { cookieDomain, cookiePath, secure } = getCookieConfig(authUrl, options.providerId);
320
330
  return new OAuthAdapter(handlers, {
321
331
  ...options,
322
332
  appOrigin,
323
- cookieDomain: url$1.hostname,
333
+ cookieDomain,
324
334
  cookiePath,
325
335
  secure,
326
336
  isOriginAllowed: config.isOriginAllowed
@@ -1273,7 +1283,8 @@ const createGithubProvider = (options) => {
1273
1283
  return OAuthAdapter.fromConfig(globalConfig, provider, {
1274
1284
  persistScopes: true,
1275
1285
  providerId,
1276
- tokenIssuer
1286
+ tokenIssuer,
1287
+ callbackUrl
1277
1288
  });
1278
1289
  });
1279
1290
  };
@@ -1515,7 +1526,7 @@ const googleDefaultSignInResolver = async (info, ctx) => {
1515
1526
  userId = profile.email.split("@")[0];
1516
1527
  }
1517
1528
  const token = await ctx.tokenIssuer.issueToken({
1518
- claims: { sub: userId, ent: [`user:default/${userId}`] }
1529
+ claims: { sub: `user:default/${userId}`, ent: [`user:default/${userId}`] }
1519
1530
  });
1520
1531
  return { id: userId, token };
1521
1532
  };
@@ -2388,7 +2399,10 @@ const oAuth2DefaultSignInResolver = async (info, ctx) => {
2388
2399
  }
2389
2400
  const userId = profile.email.split("@")[0];
2390
2401
  const token = await ctx.tokenIssuer.issueToken({
2391
- claims: { sub: userId, ent: [`user:default/${userId}`] }
2402
+ claims: {
2403
+ sub: `user:default/${userId}`,
2404
+ ent: [`user:default/${userId}`]
2405
+ }
2392
2406
  });
2393
2407
  return { id: userId, token };
2394
2408
  };