@openstax/ts-utils 1.12.1 → 1.12.3

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.
@@ -107,8 +107,10 @@ const browserAuthProvider = ({ window, configSpace }) => (configProvider) => {
107
107
  return userDataFromParentWindow;
108
108
  }
109
109
  const userDataFromAuthQuery = await getFetchUser();
110
- if ((0, lodash_1.isEqual)(userDataFromAuthQuery, userDataFromParentWindow)) {
111
- return userDataFromAuthQuery;
110
+ // userDataFromParentWindow has an extra field (role)
111
+ if (userDataFromAuthQuery.token === userDataFromParentWindow.token &&
112
+ (0, lodash_1.isEqual)(userDataFromAuthQuery.user, userDataFromParentWindow.user)) {
113
+ return userDataFromParentWindow;
112
114
  }
113
115
  throw new errors_1.UnauthorizedError();
114
116
  });
@@ -1,5 +1,5 @@
1
1
  import type { FetchConfig } from '../../fetch';
2
- import type { HttpHeaders } from '../../routing';
2
+ import type { HttpHeaders, QueryParams } from '../../routing';
3
3
  export interface TokenUser {
4
4
  id: number;
5
5
  name: string;
@@ -35,15 +35,16 @@ export declare type AuthProvider = {
35
35
  getAuthorizedFetchConfig: () => Promise<FetchConfig>;
36
36
  };
37
37
  export declare type CookieAuthProviderRequest = {
38
- headers: HttpHeaders;
39
38
  cookies?: string[];
39
+ headers: HttpHeaders;
40
+ queryStringParameters?: QueryParams;
40
41
  };
41
42
  export declare type CookieAuthProvider = (inputs: {
42
43
  request: CookieAuthProviderRequest;
43
44
  }) => AuthProvider;
44
45
  export declare type StubAuthProvider = (user: User | undefined) => AuthProvider;
45
46
  export declare const stubAuthProvider: (user?: User | undefined) => AuthProvider;
46
- export declare const getAuthTokenOrCookie: (request: CookieAuthProviderRequest, cookieName: string) => [string, {
47
+ export declare const getAuthTokenOrCookie: (request: CookieAuthProviderRequest, cookieName: string, queryKey?: string) => [string, {
47
48
  Authorization: string;
48
49
  }] | [string, {
49
50
  cookie: string;
@@ -12,12 +12,15 @@ const stubAuthProvider = (user) => ({
12
12
  getAuthorizedFetchConfig: () => Promise.resolve(user ? { headers: { Authorization: user.uuid } } : {})
13
13
  });
14
14
  exports.stubAuthProvider = stubAuthProvider;
15
- const getAuthTokenOrCookie = (request, cookieName) => {
16
- var _a;
15
+ const getAuthTokenOrCookie = (request, cookieName, queryKey = 'auth') => {
16
+ var _a, _b;
17
+ const authParam = request.queryStringParameters ? request.queryStringParameters[queryKey] : undefined;
17
18
  const authHeader = (0, helpers_2.getHeader)(request.headers, 'authorization');
18
- const cookieValue = cookie_1.default.parse(((_a = request.cookies) === null || _a === void 0 ? void 0 : _a.join('; ')) || '')[cookieName];
19
- return authHeader && authHeader.length >= 8 && authHeader.startsWith('Bearer ')
20
- ? (0, helpers_1.tuple)(authHeader.slice(7), { Authorization: authHeader })
21
- : (0, helpers_1.tuple)(cookieValue, { cookie: cookie_1.default.serialize(cookieName, cookieValue) });
19
+ const cookieValue = cookie_1.default.parse((_b = (_a = request.cookies) === null || _a === void 0 ? void 0 : _a.join('; ')) !== null && _b !== void 0 ? _b : '')[cookieName];
20
+ return typeof authParam === 'string'
21
+ ? (0, helpers_1.tuple)(authParam, { Authorization: `Bearer ${authParam}` })
22
+ : authHeader && authHeader.length >= 8 && authHeader.startsWith('Bearer ')
23
+ ? (0, helpers_1.tuple)(authHeader.slice(7), { Authorization: authHeader })
24
+ : (0, helpers_1.tuple)(cookieValue, { cookie: cookie_1.default.serialize(cookieName, cookieValue) });
22
25
  };
23
26
  exports.getAuthTokenOrCookie = getAuthTokenOrCookie;