@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.
- package/dist/cjs/services/authProvider/browser.js +4 -2
- package/dist/cjs/services/authProvider/index.d.ts +4 -3
- package/dist/cjs/services/authProvider/index.js +9 -6
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/esm/services/authProvider/browser.js +4 -2
- package/dist/esm/services/authProvider/index.d.ts +4 -3
- package/dist/esm/services/authProvider/index.js +9 -6
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -104,8 +104,10 @@ export const browserAuthProvider = ({ window, configSpace }) => (configProvider)
|
|
|
104
104
|
return userDataFromParentWindow;
|
|
105
105
|
}
|
|
106
106
|
const userDataFromAuthQuery = await getFetchUser();
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
// userDataFromParentWindow has an extra field (role)
|
|
108
|
+
if (userDataFromAuthQuery.token === userDataFromParentWindow.token &&
|
|
109
|
+
isEqual(userDataFromAuthQuery.user, userDataFromParentWindow.user)) {
|
|
110
|
+
return userDataFromParentWindow;
|
|
109
111
|
}
|
|
110
112
|
throw new UnauthorizedError();
|
|
111
113
|
});
|
|
@@ -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;
|
|
@@ -5,11 +5,14 @@ export const stubAuthProvider = (user) => ({
|
|
|
5
5
|
getUser: () => Promise.resolve(user),
|
|
6
6
|
getAuthorizedFetchConfig: () => Promise.resolve(user ? { headers: { Authorization: user.uuid } } : {})
|
|
7
7
|
});
|
|
8
|
-
export const getAuthTokenOrCookie = (request, cookieName) => {
|
|
9
|
-
var _a;
|
|
8
|
+
export const getAuthTokenOrCookie = (request, cookieName, queryKey = 'auth') => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
const authParam = request.queryStringParameters ? request.queryStringParameters[queryKey] : undefined;
|
|
10
11
|
const authHeader = getHeader(request.headers, 'authorization');
|
|
11
|
-
const cookieValue = cookie.parse(((_a = request.cookies) === null || _a === void 0 ? void 0 : _a.join('; '))
|
|
12
|
-
return
|
|
13
|
-
? tuple(
|
|
14
|
-
:
|
|
12
|
+
const cookieValue = cookie.parse((_b = (_a = request.cookies) === null || _a === void 0 ? void 0 : _a.join('; ')) !== null && _b !== void 0 ? _b : '')[cookieName];
|
|
13
|
+
return typeof authParam === 'string'
|
|
14
|
+
? tuple(authParam, { Authorization: `Bearer ${authParam}` })
|
|
15
|
+
: authHeader && authHeader.length >= 8 && authHeader.startsWith('Bearer ')
|
|
16
|
+
? tuple(authHeader.slice(7), { Authorization: authHeader })
|
|
17
|
+
: tuple(cookieValue, { cookie: cookie.serialize(cookieName, cookieValue) });
|
|
15
18
|
};
|