@osdk/oauth 1.1.0-beta.1 → 1.1.0-beta.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/CHANGELOG.md +15 -0
- package/build/browser/AuthorizationServer.test.d.ts +2 -0
- package/build/browser/AuthorizationServer.test.d.ts.map +1 -0
- package/build/browser/AuthorizationServer.test.js +45 -0
- package/build/browser/AuthorizationServer.test.js.map +1 -0
- package/build/browser/__tests__/createPublicOauthClient.test.d.ts +2 -0
- package/build/browser/__tests__/createPublicOauthClient.test.d.ts.map +1 -0
- package/build/browser/__tests__/createPublicOauthClient.test.js +56 -0
- package/build/browser/__tests__/createPublicOauthClient.test.js.map +1 -0
- package/build/browser/common.d.ts +1 -2
- package/build/browser/common.d.ts.map +1 -1
- package/build/browser/common.js +3 -4
- package/build/browser/common.js.map +1 -1
- package/build/browser/createConfidentialOauthClient.d.ts.map +1 -1
- package/build/browser/createConfidentialOauthClient.js +1 -1
- package/build/browser/createConfidentialOauthClient.js.map +1 -1
- package/build/browser/createPublicOauthClient.d.ts +48 -10
- package/build/browser/createPublicOauthClient.d.ts.map +1 -1
- package/build/browser/createPublicOauthClient.js +19 -23
- package/build/browser/createPublicOauthClient.js.map +1 -1
- package/build/browser/publicOauth.test.d.ts +2 -0
- package/build/browser/publicOauth.test.d.ts.map +1 -0
- package/build/browser/publicOauth.test.js +242 -0
- package/build/browser/publicOauth.test.js.map +1 -0
- package/build/browser/utils.d.ts +6 -0
- package/build/browser/utils.d.ts.map +1 -0
- package/build/browser/utils.js +44 -0
- package/build/browser/utils.js.map +1 -0
- package/build/esm/AuthorizationServer.test.d.ts +2 -0
- package/build/esm/AuthorizationServer.test.d.ts.map +1 -0
- package/build/esm/AuthorizationServer.test.js +45 -0
- package/build/esm/AuthorizationServer.test.js.map +1 -0
- package/build/esm/__tests__/createPublicOauthClient.test.d.ts +2 -0
- package/build/esm/__tests__/createPublicOauthClient.test.d.ts.map +1 -0
- package/build/esm/__tests__/createPublicOauthClient.test.js +56 -0
- package/build/esm/__tests__/createPublicOauthClient.test.js.map +1 -0
- package/build/esm/common.d.ts +1 -2
- package/build/esm/common.d.ts.map +1 -1
- package/build/esm/common.js +3 -4
- package/build/esm/common.js.map +1 -1
- package/build/esm/createConfidentialOauthClient.d.ts.map +1 -1
- package/build/esm/createConfidentialOauthClient.js +1 -1
- package/build/esm/createConfidentialOauthClient.js.map +1 -1
- package/build/esm/createPublicOauthClient.d.ts +48 -10
- package/build/esm/createPublicOauthClient.d.ts.map +1 -1
- package/build/esm/createPublicOauthClient.js +19 -23
- package/build/esm/createPublicOauthClient.js.map +1 -1
- package/build/esm/publicOauth.test.d.ts +2 -0
- package/build/esm/publicOauth.test.d.ts.map +1 -0
- package/build/esm/publicOauth.test.js +242 -0
- package/build/esm/publicOauth.test.js.map +1 -0
- package/build/esm/utils.d.ts +6 -0
- package/build/esm/utils.d.ts.map +1 -0
- package/build/esm/utils.js +44 -0
- package/build/esm/utils.js.map +1 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createConfidentialOauthClient.js","names":["clientCredentialsGrantRequest","customFetch","processClientCredentialsResponse","common","createAuthorizationServer","throwIfError","createConfidentialOauthClient","client_id","client_secret","url","scopes","fetchFn","globalThis","fetch","ctxPath","client","authServer","oauthHttpOptions","getToken","makeTokenAndSaveRefresh","URLSearchParams","scope","join","undefined"],"sources":["createConfidentialOauthClient.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { clientCredentialsGrantRequest, customFetch, processClientCredentialsResponse, } from \"oauth4webapi\";\nimport { common, createAuthorizationServer } from \"./common.js\";\nimport { throwIfError } from \"./throwIfError.js\";\n/**\n * @param client_id\n * @param client_secret\n * @param url the base url of your foundry server\n * @param scopes\n * @param fetchFn\n * @param ctxPath\n * @returns which can be used as a token provider\n */\nexport function createConfidentialOauthClient(client_id, client_secret, url, scopes = [\"api:read-data\", \"api:write-data\"], fetchFn = globalThis.fetch, ctxPath = \"
|
|
1
|
+
{"version":3,"file":"createConfidentialOauthClient.js","names":["clientCredentialsGrantRequest","customFetch","processClientCredentialsResponse","common","createAuthorizationServer","throwIfError","createConfidentialOauthClient","client_id","client_secret","url","scopes","fetchFn","globalThis","fetch","ctxPath","client","authServer","oauthHttpOptions","getToken","makeTokenAndSaveRefresh","URLSearchParams","scope","join","undefined"],"sources":["createConfidentialOauthClient.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { clientCredentialsGrantRequest, customFetch, processClientCredentialsResponse, } from \"oauth4webapi\";\nimport { common, createAuthorizationServer } from \"./common.js\";\nimport { throwIfError } from \"./throwIfError.js\";\n/**\n * @param client_id\n * @param client_secret\n * @param url the base url of your foundry server\n * @param scopes\n * @param fetchFn\n * @param ctxPath\n * @returns which can be used as a token provider\n */\nexport function createConfidentialOauthClient(client_id, client_secret, url, scopes = [\"api:read-data\", \"api:write-data\"], fetchFn = globalThis.fetch, ctxPath = \"multipass\") {\n const client = { client_id, client_secret };\n const authServer = createAuthorizationServer(ctxPath, url);\n const oauthHttpOptions = { [customFetch]: fetchFn };\n const { getToken, makeTokenAndSaveRefresh } = common(client, authServer, _signIn, oauthHttpOptions, undefined);\n async function _signIn() {\n return makeTokenAndSaveRefresh(throwIfError(await processClientCredentialsResponse(authServer, client, await clientCredentialsGrantRequest(authServer, client, new URLSearchParams({ scope: scopes.join(\" \") }), oauthHttpOptions))), \"signIn\");\n }\n return getToken;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,6BAA6B,EAAEC,WAAW,EAAEC,gCAAgC,QAAS,cAAc;AAC5G,SAASC,MAAM,EAAEC,yBAAyB,QAAQ,aAAa;AAC/D,SAASC,YAAY,QAAQ,mBAAmB;AAChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,6BAA6BA,CAACC,SAAS,EAAEC,aAAa,EAAEC,GAAG,EAAEC,MAAM,GAAG,CAAC,eAAe,EAAE,gBAAgB,CAAC,EAAEC,OAAO,GAAGC,UAAU,CAACC,KAAK,EAAEC,OAAO,GAAG,WAAW,EAAE;EAC1K,MAAMC,MAAM,GAAG;IAAER,SAAS;IAAEC;EAAc,CAAC;EAC3C,MAAMQ,UAAU,GAAGZ,yBAAyB,CAACU,OAAO,EAAEL,GAAG,CAAC;EAC1D,MAAMQ,gBAAgB,GAAG;IAAE,CAAChB,WAAW,GAAGU;EAAQ,CAAC;EACnD,MAAM;IAAEO,QAAQ;IAAEC;EAAwB,CAAC,GAAGhB,MAAM,CAACY,MAAM,EAAEC,UAAU,EACvE,kBAAyB;IACrB,OAAOG,uBAAuB,CAACd,YAAY,CAAC,MAAMH,gCAAgC,CAACc,UAAU,EAAED,MAAM,EAAE,MAAMf,6BAA6B,CAACgB,UAAU,EAAED,MAAM,EAAE,IAAIK,eAAe,CAAC;MAAEC,KAAK,EAAEX,MAAM,CAACY,IAAI,CAAC,GAAG;IAAE,CAAC,CAAC,EAAEL,gBAAgB,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC;EACnP,CAAC,EAHiFA,gBAAgB,EAAEM,SAAS,CAAC;EAI9G,OAAOL,QAAQ;AACnB","ignoreList":[]}
|
|
@@ -1,15 +1,53 @@
|
|
|
1
1
|
import type { PublicOauthClient } from "./PublicOauthClient.js";
|
|
2
|
+
export interface PublicOauthClientOptions {
|
|
3
|
+
/**
|
|
4
|
+
* If true, uses `history.replaceState()`, otherwise uses `window.location.assign()` (defaults to true)
|
|
5
|
+
*/
|
|
6
|
+
useHistory?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Custom landing page URL prior to logging in
|
|
9
|
+
*/
|
|
10
|
+
loginPage?: string;
|
|
11
|
+
/**
|
|
12
|
+
* URL to return to after completed authentication cycle (defaults to `window.location.toString()`)
|
|
13
|
+
*/
|
|
14
|
+
postLoginPage?: string;
|
|
15
|
+
/**
|
|
16
|
+
* * @param {string[]} [scopes=[]] - OAuth scopes to request. If not provided, defaults to `["api:read-data", "api:write-data"]`
|
|
17
|
+
*/
|
|
18
|
+
scopes?: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Custom fetch function to use for requests (defaults to `globalThis.fetch`)
|
|
21
|
+
*/
|
|
22
|
+
fetchFn?: typeof globalThis.fetch;
|
|
23
|
+
/**
|
|
24
|
+
* Context path for the authorization server (defaults to "multipass")
|
|
25
|
+
*/
|
|
26
|
+
ctxPath?: string;
|
|
27
|
+
}
|
|
2
28
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @param
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
29
|
+
* Creates a PublicOauthClient for authentication.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} clientId - The client_id from the OAuth configuration on the server
|
|
32
|
+
* @param {string} url - The base URL of your Foundry server
|
|
33
|
+
* @param {string} redirectUrl - The URL configured for redirect in the OAuth configuration on the server
|
|
34
|
+
* @param {PublicOauthClientOptions} options - Additional options for the client
|
|
35
|
+
* @returns {PublicOauthClient} A client that can be used as a token provider
|
|
36
|
+
*/
|
|
37
|
+
export declare function createPublicOauthClient(clientId: string, url: string, redirectUrl: string, options?: PublicOauthClientOptions): PublicOauthClient;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a PublicOauthClient for authentication.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} clientId - The client_id from the OAuth configuration on the server
|
|
42
|
+
* @param {string} url - The base URL of your Foundry server
|
|
43
|
+
* @param {string} redirectUrl - The URL configured for redirect in the OAuth configuration on the server
|
|
44
|
+
* @param {boolean} useHistory - If true, uses `history.replaceState()`, otherwise uses `window.location.assign()` (defaults to true)
|
|
45
|
+
* @param {string} loginPage - Custom landing page URL prior to logging in
|
|
46
|
+
* @param {string} postLoginPage - URL to return to after completed authentication cycle (defaults to `window.location.toString()`)
|
|
47
|
+
* @param {string[]} scopes - OAuth scopes to request. If not provided, defaults to `["api:read-data", "api:write-data"]`
|
|
48
|
+
* @param {typeof globalThis.fetch} fetchFn - Custom fetch function to use for requests (defaults to `globalThis.fetch`)
|
|
49
|
+
* @param {string} ctxPath - Context path for the authorization server (defaults to "multipass")
|
|
50
|
+
* @returns {PublicOauthClient} A client that can be used as a token provider
|
|
13
51
|
*/
|
|
14
52
|
export declare function createPublicOauthClient(client_id: string, url: string, redirectUrl: string, useHistory?: boolean, loginPage?: string, postLoginPage?: string, scopes?: string[], fetchFn?: typeof globalThis.fetch, ctxPath?: string): PublicOauthClient;
|
|
15
53
|
//# sourceMappingURL=createPublicOauthClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPublicOauthClient.d.ts","sourceRoot":"","sources":["../../src/createPublicOauthClient.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"createPublicOauthClient.d.ts","sourceRoot":"","sources":["../../src/createPublicOauthClient.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAYhE,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAElC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,wBAAwB,GACjC,iBAAiB,CAAC;AAErB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,OAAO,EACpB,SAAS,CAAC,EAAE,MAAM,EAClB,aAAa,CAAC,EAAE,MAAM,EACtB,MAAM,CAAC,EAAE,MAAM,EAAE,EACjB,OAAO,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,EACjC,OAAO,CAAC,EAAE,MAAM,GACf,iBAAiB,CAAC"}
|
|
@@ -17,19 +17,16 @@ import delay from "delay";
|
|
|
17
17
|
import { authorizationCodeGrantRequest, calculatePKCECodeChallenge, customFetch, generateRandomCodeVerifier, generateRandomState, processAuthorizationCodeOAuth2Response, refreshTokenGrantRequest, validateAuthResponse } from "oauth4webapi";
|
|
18
18
|
import { common, createAuthorizationServer, readLocal, removeLocal, saveLocal } from "./common.js";
|
|
19
19
|
import { throwIfError } from "./throwIfError.js";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* @returns {PublicOauthClient} which can be used as a token provider
|
|
31
|
-
*/
|
|
32
|
-
export function createPublicOauthClient(client_id, url, redirectUrl, useHistory = true, loginPage, postLoginPage = window.location.toString(), scopes = [], fetchFn = globalThis.fetch, ctxPath = "/multipass") {
|
|
20
|
+
import { processOptionsAndAssignDefaults } from "./utils.js";
|
|
21
|
+
export function createPublicOauthClient(client_id, url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {
|
|
22
|
+
({
|
|
23
|
+
useHistory,
|
|
24
|
+
loginPage,
|
|
25
|
+
postLoginPage,
|
|
26
|
+
scopes,
|
|
27
|
+
fetchFn,
|
|
28
|
+
ctxPath
|
|
29
|
+
} = processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath));
|
|
33
30
|
const client = {
|
|
34
31
|
client_id,
|
|
35
32
|
token_endpoint_auth_method: "none"
|
|
@@ -38,9 +35,6 @@ export function createPublicOauthClient(client_id, url, redirectUrl, useHistory
|
|
|
38
35
|
const oauthHttpOptions = {
|
|
39
36
|
[customFetch]: fetchFn
|
|
40
37
|
};
|
|
41
|
-
if (scopes.length === 0) {
|
|
42
|
-
scopes = ["api:read-data", "api:write-data"];
|
|
43
|
-
}
|
|
44
38
|
const {
|
|
45
39
|
makeTokenAndSaveRefresh,
|
|
46
40
|
getToken
|
|
@@ -53,11 +47,12 @@ export function createPublicOauthClient(client_id, url, redirectUrl, useHistory
|
|
|
53
47
|
// 3. If we haven't been able to load the token from one of the two above ways, we need to make the initial auth request
|
|
54
48
|
?? (await initiateLoginRedirect());
|
|
55
49
|
}, oauthHttpOptions, maybeRefresh.bind(globalThis, true));
|
|
56
|
-
|
|
50
|
+
// as an arrow function, `useHistory` is known to be a boolean
|
|
51
|
+
const go = async x => {
|
|
57
52
|
if (useHistory) return window.history.replaceState({}, "", x);else window.location.assign(x);
|
|
58
53
|
await delay(1000);
|
|
59
54
|
throw new Error("Unable to redirect");
|
|
60
|
-
}
|
|
55
|
+
};
|
|
61
56
|
async function maybeRefresh(expectRefreshToken) {
|
|
62
57
|
const {
|
|
63
58
|
refresh_token
|
|
@@ -70,7 +65,7 @@ export function createPublicOauthClient(client_id, url, redirectUrl, useHistory
|
|
|
70
65
|
// note, we don't use processRefreshTokenResponse because the mp oauth implementation
|
|
71
66
|
// doesn't do refresh tokens quite right and this lets us skip the id check
|
|
72
67
|
const result = makeTokenAndSaveRefresh(throwIfError(await processAuthorizationCodeOAuth2Response(authServer, client, await refreshTokenGrantRequest(authServer, client, refresh_token, oauthHttpOptions))), "refresh");
|
|
73
|
-
if (result && window.location.pathname === new URL(
|
|
68
|
+
if (result && window.location.pathname === new URL(redirect_uri).pathname) {
|
|
74
69
|
const {
|
|
75
70
|
oldUrl
|
|
76
71
|
} = readLocal(client);
|
|
@@ -96,7 +91,7 @@ export function createPublicOauthClient(client_id, url, redirectUrl, useHistory
|
|
|
96
91
|
} = readLocal(client);
|
|
97
92
|
if (!codeVerifier) return;
|
|
98
93
|
try {
|
|
99
|
-
const ret = makeTokenAndSaveRefresh(throwIfError(await processAuthorizationCodeOAuth2Response(authServer, client, await authorizationCodeGrantRequest(authServer, client, throwIfError(validateAuthResponse(authServer, client, new URL(window.location.href), state)),
|
|
94
|
+
const ret = makeTokenAndSaveRefresh(throwIfError(await processAuthorizationCodeOAuth2Response(authServer, client, await authorizationCodeGrantRequest(authServer, client, throwIfError(validateAuthResponse(authServer, client, new URL(window.location.href), state)), redirect_uri, codeVerifier, oauthHttpOptions))), "signIn");
|
|
100
95
|
go(oldUrl);
|
|
101
96
|
return ret;
|
|
102
97
|
} catch (e) {
|
|
@@ -107,7 +102,8 @@ export function createPublicOauthClient(client_id, url, redirectUrl, useHistory
|
|
|
107
102
|
removeLocal(client);
|
|
108
103
|
}
|
|
109
104
|
}
|
|
110
|
-
|
|
105
|
+
// As an arrow function, `scopes` and `postLoginPage` are known at compile time
|
|
106
|
+
const initiateLoginRedirect = async () => {
|
|
111
107
|
if (loginPage && window.location.href !== loginPage && window.location.pathname !== loginPage) {
|
|
112
108
|
saveLocal(client, {
|
|
113
109
|
oldUrl: postLoginPage
|
|
@@ -126,7 +122,7 @@ export function createPublicOauthClient(client_id, url, redirectUrl, useHistory
|
|
|
126
122
|
client_id,
|
|
127
123
|
response_type: "code",
|
|
128
124
|
state,
|
|
129
|
-
redirect_uri
|
|
125
|
+
redirect_uri,
|
|
130
126
|
code_challenge: await calculatePKCECodeChallenge(codeVerifier),
|
|
131
127
|
code_challenge_method: "S256",
|
|
132
128
|
scope: ["offline_access", ...scopes].join(" ")
|
|
@@ -134,7 +130,7 @@ export function createPublicOauthClient(client_id, url, redirectUrl, useHistory
|
|
|
134
130
|
// Give time for redirect to happen
|
|
135
131
|
await delay(1000);
|
|
136
132
|
throw new Error("Unable to redirect");
|
|
137
|
-
}
|
|
133
|
+
};
|
|
138
134
|
return getToken;
|
|
139
135
|
}
|
|
140
136
|
//# sourceMappingURL=createPublicOauthClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPublicOauthClient.js","names":["delay","authorizationCodeGrantRequest","calculatePKCECodeChallenge","customFetch","generateRandomCodeVerifier","generateRandomState","processAuthorizationCodeOAuth2Response","refreshTokenGrantRequest","validateAuthResponse","common","createAuthorizationServer","readLocal","removeLocal","saveLocal","throwIfError","createPublicOauthClient","client_id","url","redirectUrl","useHistory","loginPage","postLoginPage","window","location","toString","scopes","fetchFn","globalThis","fetch","ctxPath","client","token_endpoint_auth_method","authServer","oauthHttpOptions","length","makeTokenAndSaveRefresh","getToken","_signIn","maybeRefresh","maybeHandleAuthReturn","initiateLoginRedirect","bind","go","x","history","replaceState","assign","Error","expectRefreshToken","refresh_token","result","pathname","URL","oldUrl","e","process","env","NODE_ENV","console","warn","codeVerifier","state","ret","href","authorization_endpoint","URLSearchParams","response_type","redirect_uri","code_challenge","code_challenge_method","scope","join"],"sources":["createPublicOauthClient.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport delay from \"delay\";\nimport { authorizationCodeGrantRequest, calculatePKCECodeChallenge, customFetch, generateRandomCodeVerifier, generateRandomState, processAuthorizationCodeOAuth2Response, refreshTokenGrantRequest, validateAuthResponse, } from \"oauth4webapi\";\nimport { common, createAuthorizationServer, readLocal, removeLocal, saveLocal, } from \"./common.js\";\nimport { throwIfError } from \"./throwIfError.js\";\n/**\n * @param client_id\n * @param url the base url of your foundry server\n * @param redirectUrl the url configured for redirect in the oauth configuration on the server\n * @param useHistory if true, when possible uses `history.replaceState()`, otherwise uses `window.location.assign()`\n * @param loginPage if you want a custom landing page prior to logging in, set this to that url\n * @param postLoginPage if you want to customize where you return to after a completed authentication cycle. defaults to the url when the page loaded\n * @param scopes\n * @param fetchFn\n * @param ctxPath\n * @returns {PublicOauthClient} which can be used as a token provider\n */\nexport function createPublicOauthClient(client_id, url, redirectUrl, useHistory = true, loginPage, postLoginPage = window.location.toString(), scopes = [], fetchFn = globalThis.fetch, ctxPath = \"/multipass\") {\n const client = { client_id, token_endpoint_auth_method: \"none\" };\n const authServer = createAuthorizationServer(ctxPath, url);\n const oauthHttpOptions = { [customFetch]: fetchFn };\n if (scopes.length === 0) {\n scopes = [\"api:read-data\", \"api:write-data\"];\n }\n const { makeTokenAndSaveRefresh, getToken } = common(client, authServer, _signIn, oauthHttpOptions, maybeRefresh.bind(globalThis, true));\n async function go(x) {\n if (useHistory)\n return window.history.replaceState({}, \"\", x);\n else\n window.location.assign(x);\n await delay(1000);\n throw new Error(\"Unable to redirect\");\n }\n async function maybeRefresh(expectRefreshToken) {\n const { refresh_token } = readLocal(client);\n if (!refresh_token) {\n if (expectRefreshToken)\n throw new Error(\"No refresh token found\");\n return;\n }\n try {\n // note, we don't use processRefreshTokenResponse because the mp oauth implementation\n // doesn't do refresh tokens quite right and this lets us skip the id check\n const result = makeTokenAndSaveRefresh(throwIfError(await processAuthorizationCodeOAuth2Response(authServer, client, await refreshTokenGrantRequest(authServer, client, refresh_token, oauthHttpOptions))), \"refresh\");\n if (result && window.location.pathname === new URL(redirectUrl).pathname) {\n const { oldUrl } = readLocal(client);\n go(oldUrl ?? \"/\");\n }\n return result;\n }\n catch (e) {\n if (process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line no-console\n console.warn(\"Failed to get OAuth2 refresh token. Removing refresh token\", e);\n }\n removeLocal(client);\n if (expectRefreshToken) {\n throw new Error(\"Could not refresh token\");\n }\n }\n }\n async function maybeHandleAuthReturn() {\n const { codeVerifier, state, oldUrl } = readLocal(client);\n if (!codeVerifier)\n return;\n try {\n const ret = makeTokenAndSaveRefresh(throwIfError(await processAuthorizationCodeOAuth2Response(authServer, client, await authorizationCodeGrantRequest(authServer, client, throwIfError(validateAuthResponse(authServer, client, new URL(window.location.href), state)), redirectUrl, codeVerifier, oauthHttpOptions))), \"signIn\");\n go(oldUrl);\n return ret;\n }\n catch (e) {\n if (process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line no-console\n console.warn(\"Failed to get OAuth2 token using PKCE, removing PKCE and starting a new auth flow\", e);\n }\n removeLocal(client);\n }\n }\n async function initiateLoginRedirect() {\n if (loginPage\n && window.location.href !== loginPage\n && window.location.pathname !== loginPage) {\n saveLocal(client, { oldUrl: postLoginPage });\n return await go(loginPage);\n }\n const state = generateRandomState();\n const codeVerifier = generateRandomCodeVerifier();\n const oldUrl = readLocal(client).oldUrl ?? window.location.toString();\n saveLocal(client, { codeVerifier, state, oldUrl });\n window.location.assign(`${authServer\n .authorization_endpoint}?${new URLSearchParams({\n client_id,\n response_type: \"code\",\n state,\n redirect_uri: redirectUrl,\n code_challenge: await calculatePKCECodeChallenge(codeVerifier),\n code_challenge_method: \"S256\",\n scope: [\"offline_access\", ...scopes].join(\" \"),\n })}`);\n // Give time for redirect to happen\n await delay(1000);\n throw new Error(\"Unable to redirect\");\n }\n /** Will throw if there is no token! */\n async function _signIn() {\n // 1. Check if we have a refresh token in local storage\n return await maybeRefresh()\n // 2. If there is no refresh token we are likely trying to perform the callback\n ?? await maybeHandleAuthReturn()\n // 3. If we haven't been able to load the token from one of the two above ways, we need to make the initial auth request\n ?? await initiateLoginRedirect();\n }\n return getToken;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,6BAA6B,EAAEC,0BAA0B,EAAEC,WAAW,EAAEC,0BAA0B,EAAEC,mBAAmB,EAAEC,sCAAsC,EAAEC,wBAAwB,EAAEC,oBAAoB,QAAS,cAAc;AAC/O,SAASC,MAAM,EAAEC,yBAAyB,EAAEC,SAAS,EAAEC,WAAW,EAAEC,SAAS,QAAS,aAAa;AACnG,SAASC,YAAY,QAAQ,mBAAmB;AAChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CAACC,SAAS,EAAEC,GAAG,EAAEC,WAAW,EAAEC,UAAU,GAAG,IAAI,EAAEC,SAAS,EAAEC,aAAa,GAAGC,MAAM,CAACC,QAAQ,CAACC,QAAQ,CAAC,CAAC,EAAEC,MAAM,GAAG,EAAE,EAAEC,OAAO,GAAGC,UAAU,CAACC,KAAK,EAAEC,OAAO,GAAG,YAAY,EAAE;EAC5M,MAAMC,MAAM,G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IAAI,CAAC,GAAG;IACjD,CAAC,CAAC,EAAE,CAAC;IACL;IACA,MAAMvE,KAAK,CAAC,IAAI,CAAC;IACjB,MAAM,IAAI+C,KAAK,CAAC,oBAAoB,CAAC;EACzC;EAUA,OAAOX,QAAQ;AACnB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"createPublicOauthClient.js","names":["delay","authorizationCodeGrantRequest","calculatePKCECodeChallenge","customFetch","generateRandomCodeVerifier","generateRandomState","processAuthorizationCodeOAuth2Response","refreshTokenGrantRequest","validateAuthResponse","common","createAuthorizationServer","readLocal","removeLocal","saveLocal","throwIfError","processOptionsAndAssignDefaults","createPublicOauthClient","client_id","url","redirect_uri","useHistory","loginPage","postLoginPage","scopes","fetchFn","ctxPath","client","token_endpoint_auth_method","authServer","oauthHttpOptions","makeTokenAndSaveRefresh","getToken","_signIn","maybeRefresh","maybeHandleAuthReturn","initiateLoginRedirect","bind","globalThis","go","x","window","history","replaceState","location","assign","Error","expectRefreshToken","refresh_token","result","pathname","URL","oldUrl","e","process","env","NODE_ENV","console","warn","codeVerifier","state","ret","href","toString","authorization_endpoint","URLSearchParams","response_type","code_challenge","code_challenge_method","scope","join"],"sources":["createPublicOauthClient.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport delay from \"delay\";\nimport { authorizationCodeGrantRequest, calculatePKCECodeChallenge, customFetch, generateRandomCodeVerifier, generateRandomState, processAuthorizationCodeOAuth2Response, refreshTokenGrantRequest, validateAuthResponse, } from \"oauth4webapi\";\nimport { common, createAuthorizationServer, readLocal, removeLocal, saveLocal, } from \"./common.js\";\nimport { throwIfError } from \"./throwIfError.js\";\nimport { processOptionsAndAssignDefaults } from \"./utils.js\";\nexport function createPublicOauthClient(client_id, url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {\n ({\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n } = processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath));\n const client = { client_id, token_endpoint_auth_method: \"none\" };\n const authServer = createAuthorizationServer(ctxPath, url);\n const oauthHttpOptions = { [customFetch]: fetchFn };\n const { makeTokenAndSaveRefresh, getToken } = common(client, authServer, _signIn, oauthHttpOptions, maybeRefresh.bind(globalThis, true));\n // as an arrow function, `useHistory` is known to be a boolean\n const go = async (x) => {\n if (useHistory)\n return window.history.replaceState({}, \"\", x);\n else\n window.location.assign(x);\n await delay(1000);\n throw new Error(\"Unable to redirect\");\n };\n async function maybeRefresh(expectRefreshToken) {\n const { refresh_token } = readLocal(client);\n if (!refresh_token) {\n if (expectRefreshToken)\n throw new Error(\"No refresh token found\");\n return;\n }\n try {\n // note, we don't use processRefreshTokenResponse because the mp oauth implementation\n // doesn't do refresh tokens quite right and this lets us skip the id check\n const result = makeTokenAndSaveRefresh(throwIfError(await processAuthorizationCodeOAuth2Response(authServer, client, await refreshTokenGrantRequest(authServer, client, refresh_token, oauthHttpOptions))), \"refresh\");\n if (result && window.location.pathname === new URL(redirect_uri).pathname) {\n const { oldUrl } = readLocal(client);\n go(oldUrl ?? \"/\");\n }\n return result;\n }\n catch (e) {\n if (process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line no-console\n console.warn(\"Failed to get OAuth2 refresh token. Removing refresh token\", e);\n }\n removeLocal(client);\n if (expectRefreshToken) {\n throw new Error(\"Could not refresh token\");\n }\n }\n }\n async function maybeHandleAuthReturn() {\n const { codeVerifier, state, oldUrl } = readLocal(client);\n if (!codeVerifier)\n return;\n try {\n const ret = makeTokenAndSaveRefresh(throwIfError(await processAuthorizationCodeOAuth2Response(authServer, client, await authorizationCodeGrantRequest(authServer, client, throwIfError(validateAuthResponse(authServer, client, new URL(window.location.href), state)), redirect_uri, codeVerifier, oauthHttpOptions))), \"signIn\");\n go(oldUrl);\n return ret;\n }\n catch (e) {\n if (process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line no-console\n console.warn(\"Failed to get OAuth2 token using PKCE, removing PKCE and starting a new auth flow\", e);\n }\n removeLocal(client);\n }\n }\n // As an arrow function, `scopes` and `postLoginPage` are known at compile time\n const initiateLoginRedirect = async () => {\n if (loginPage\n && window.location.href !== loginPage\n && window.location.pathname !== loginPage) {\n saveLocal(client, { oldUrl: postLoginPage });\n return await go(loginPage);\n }\n const state = generateRandomState();\n const codeVerifier = generateRandomCodeVerifier();\n const oldUrl = readLocal(client).oldUrl ?? window.location.toString();\n saveLocal(client, { codeVerifier, state, oldUrl });\n window.location.assign(`${authServer\n .authorization_endpoint}?${new URLSearchParams({\n client_id,\n response_type: \"code\",\n state,\n redirect_uri,\n code_challenge: await calculatePKCECodeChallenge(codeVerifier),\n code_challenge_method: \"S256\",\n scope: [\"offline_access\", ...scopes].join(\" \"),\n })}`);\n // Give time for redirect to happen\n await delay(1000);\n throw new Error(\"Unable to redirect\");\n };\n /** Will throw if there is no token! */\n async function _signIn() {\n // 1. Check if we have a refresh token in local storage\n return await maybeRefresh()\n // 2. If there is no refresh token we are likely trying to perform the callback\n ?? await maybeHandleAuthReturn()\n // 3. If we haven't been able to load the token from one of the two above ways, we need to make the initial auth request\n ?? await initiateLoginRedirect();\n }\n return getToken;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,6BAA6B,EAAEC,0BAA0B,EAAEC,WAAW,EAAEC,0BAA0B,EAAEC,mBAAmB,EAAEC,s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CAAC,CAACyB,MAAM,IAAIX,MAAM,CAACG,QAAQ,CAACmB,QAAQ,CAAC,CAAC;IACrEjD,SAAS,CAACa,MAAM,EAAE;MAAEgC,YAAY;MAAEC,KAAK;MAAER;IAAO,CAAC,CAAC;IAClDX,MAAM,CAACG,QAAQ,CAACC,MAAM,CAAC,GAAGhB,UAAU,CAC/BmC,sBAAsB,IAAI,IAAIC,eAAe,CAAC;MAC/C/C,SAAS;MACTgD,aAAa,EAAE,MAAM;MACrBN,KAAK;MACLxC,YAAY;MACZ+C,cAAc,EAAE,MAAMhE,0BAA0B,CAACwD,YAAY,CAAC;MAC9DS,qBAAqB,EAAE,MAAM;MAC7BC,KAAK,EAAE,CAAC,gBAAgB,EAAE,GAAG7C,MAAM,CAAC,CAAC8C,IAAI,CAAC,GAAG;IACjD,CAAC,CAAC,EAAE,CAAC;IACL;IACA,MAAMrE,KAAK,CAAC,IAAI,CAAC;IACjB,MAAM,IAAI6C,KAAK,CAAC,oBAAoB,CAAC;EACzC,CAAC;EAUD,OAAOd,QAAQ;AACnB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicOauth.test.d.ts","sourceRoot":"","sources":["../../src/publicOauth.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/* eslint-disable @typescript-eslint/consistent-type-imports */
|
|
17
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
18
|
+
import * as commonJs from "./common.js";
|
|
19
|
+
import { createPublicOauthClient } from "./createPublicOauthClient.js";
|
|
20
|
+
const hoistedMocks = vi.hoisted(() => {
|
|
21
|
+
return {
|
|
22
|
+
makeTokenAndSaveRefresh: vi.fn()
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
vi.mock("delay", async importOriginal => {
|
|
26
|
+
const original = await importOriginal();
|
|
27
|
+
return {
|
|
28
|
+
default: vi.fn((ms, opts) => {
|
|
29
|
+
// speed up the tests
|
|
30
|
+
return original.default(ms / 100, opts);
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
vi.mock("./common.js", async importOriginal => {
|
|
35
|
+
const original = await importOriginal();
|
|
36
|
+
return {
|
|
37
|
+
...original,
|
|
38
|
+
common: vi.fn((...args) => {
|
|
39
|
+
const result = original.common(...args);
|
|
40
|
+
return {
|
|
41
|
+
...result,
|
|
42
|
+
makeTokenAndSaveRefresh: hoistedMocks.makeTokenAndSaveRefresh
|
|
43
|
+
};
|
|
44
|
+
}),
|
|
45
|
+
readLocal: vi.spyOn(original, "readLocal")
|
|
46
|
+
// vi.fn(original.readLocal),
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
vi.mock("oauth4webapi");
|
|
50
|
+
describe(createPublicOauthClient, () => {
|
|
51
|
+
const DEFAULT_CUR_URL = new URL("https://fauxurl");
|
|
52
|
+
const fetchFn = vi.fn();
|
|
53
|
+
const mockWindow = {
|
|
54
|
+
location: {
|
|
55
|
+
toString: vi.fn(() => DEFAULT_CUR_URL),
|
|
56
|
+
assign: vi.fn(),
|
|
57
|
+
href: DEFAULT_CUR_URL.href,
|
|
58
|
+
pathname: DEFAULT_CUR_URL.pathname
|
|
59
|
+
},
|
|
60
|
+
history: {
|
|
61
|
+
replaceState: vi.fn()
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const mockLocalStorage = {
|
|
65
|
+
setItem: vi.fn(),
|
|
66
|
+
getItem: vi.fn(),
|
|
67
|
+
removeItem: vi.fn()
|
|
68
|
+
};
|
|
69
|
+
beforeEach(() => {
|
|
70
|
+
vi.restoreAllMocks();
|
|
71
|
+
fetchFn.mockRestore();
|
|
72
|
+
});
|
|
73
|
+
afterEach(() => {
|
|
74
|
+
vi.clearAllMocks();
|
|
75
|
+
fetchFn.mockReset();
|
|
76
|
+
});
|
|
77
|
+
beforeAll(() => {
|
|
78
|
+
vi.stubGlobal("window", mockWindow);
|
|
79
|
+
vi.stubGlobal("localStorage", mockLocalStorage);
|
|
80
|
+
});
|
|
81
|
+
afterAll(() => {
|
|
82
|
+
vi.unstubAllGlobals();
|
|
83
|
+
});
|
|
84
|
+
const BASE_CLIENT_ARGS = {
|
|
85
|
+
clientId: "this-would-be-client-id",
|
|
86
|
+
foundryUrl: "https://a.foundry.url.local",
|
|
87
|
+
redirectUrl: "https://my.redirect.url.local",
|
|
88
|
+
fetchFn
|
|
89
|
+
};
|
|
90
|
+
const fullLoginUrl = new URL("/loginPage", DEFAULT_CUR_URL);
|
|
91
|
+
describe.each([{
|
|
92
|
+
name: "Basic Usage",
|
|
93
|
+
currentUrl: DEFAULT_CUR_URL,
|
|
94
|
+
clientArgs: {
|
|
95
|
+
...BASE_CLIENT_ARGS
|
|
96
|
+
},
|
|
97
|
+
should: {
|
|
98
|
+
redirectToLoginPage: false
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
name: "Base w/ full loginPage and curUrl is root",
|
|
102
|
+
currentUrl: DEFAULT_CUR_URL,
|
|
103
|
+
clientArgs: {
|
|
104
|
+
...BASE_CLIENT_ARGS,
|
|
105
|
+
loginPage: fullLoginUrl.toString()
|
|
106
|
+
},
|
|
107
|
+
should: {
|
|
108
|
+
redirectToLoginPage: true
|
|
109
|
+
}
|
|
110
|
+
}, {
|
|
111
|
+
name: "Base w/ full loginPage and curUrl is login page",
|
|
112
|
+
currentUrl: fullLoginUrl,
|
|
113
|
+
clientArgs: {
|
|
114
|
+
...BASE_CLIENT_ARGS,
|
|
115
|
+
loginPage: fullLoginUrl.toString()
|
|
116
|
+
},
|
|
117
|
+
should: {
|
|
118
|
+
redirectToLoginPage: false
|
|
119
|
+
}
|
|
120
|
+
}, {
|
|
121
|
+
name: "Base w/ short loginPage and curUrl is root",
|
|
122
|
+
currentUrl: DEFAULT_CUR_URL,
|
|
123
|
+
clientArgs: {
|
|
124
|
+
...BASE_CLIENT_ARGS,
|
|
125
|
+
loginPage: "/loginPage"
|
|
126
|
+
},
|
|
127
|
+
should: {
|
|
128
|
+
redirectToLoginPage: true
|
|
129
|
+
}
|
|
130
|
+
}, {
|
|
131
|
+
name: "Base w/ short loginPage and curUrl is loginPage",
|
|
132
|
+
currentUrl: new URL("/loginPage", DEFAULT_CUR_URL),
|
|
133
|
+
clientArgs: {
|
|
134
|
+
...BASE_CLIENT_ARGS,
|
|
135
|
+
loginPage: "/loginPage"
|
|
136
|
+
},
|
|
137
|
+
should: {
|
|
138
|
+
redirectToLoginPage: false
|
|
139
|
+
}
|
|
140
|
+
}])("$name", ({
|
|
141
|
+
clientArgs,
|
|
142
|
+
currentUrl,
|
|
143
|
+
should
|
|
144
|
+
}) => {
|
|
145
|
+
let client;
|
|
146
|
+
beforeEach(() => {
|
|
147
|
+
client = createPublicOauthClient(clientArgs.clientId, clientArgs.foundryUrl, clientArgs.redirectUrl, clientArgs.useHistory, clientArgs.loginPage, clientArgs.postLoginPage, clientArgs.scopes, clientArgs.fetchFn, clientArgs.ctxPath);
|
|
148
|
+
mockWindow.location.href = new URL(currentUrl).href;
|
|
149
|
+
mockWindow.location.pathname = new URL(currentUrl).pathname;
|
|
150
|
+
});
|
|
151
|
+
it("calls common with expected values", () => {
|
|
152
|
+
expect(vi.mocked(commonJs.common)).toHaveBeenCalledWith(expect.objectContaining({
|
|
153
|
+
client_id: clientArgs.clientId,
|
|
154
|
+
token_endpoint_auth_method: "none"
|
|
155
|
+
}), commonJs.createAuthorizationServer(clientArgs.ctxPath ?? "/multipass", clientArgs.foundryUrl), expect.any(Function), expect.anything(), expect.any(Function));
|
|
156
|
+
});
|
|
157
|
+
describe.each([{
|
|
158
|
+
refresh_token: "a-refresh-token"
|
|
159
|
+
}, {
|
|
160
|
+
codeVerifier: "hi",
|
|
161
|
+
state: "mom",
|
|
162
|
+
oldUrl: "https://someoldurl.local"
|
|
163
|
+
}, {}])("Initial Local State: %s", initialLocalState => {
|
|
164
|
+
const ACCESS_TOKEN = (Math.random() + 1).toString(36).substring(7);
|
|
165
|
+
beforeEach(() => {
|
|
166
|
+
vi.mocked(commonJs.readLocal).mockImplementation(() => initialLocalState);
|
|
167
|
+
hoistedMocks.makeTokenAndSaveRefresh.mockImplementation(() => ({
|
|
168
|
+
access_token: ACCESS_TOKEN,
|
|
169
|
+
expires_at: Date.now(),
|
|
170
|
+
expires_in: 10000
|
|
171
|
+
}));
|
|
172
|
+
});
|
|
173
|
+
if (Object.keys(initialLocalState).length === 0) {
|
|
174
|
+
if (should.redirectToLoginPage) {
|
|
175
|
+
it("redirects to login page", async () => {
|
|
176
|
+
const tokenPromise = client();
|
|
177
|
+
expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);
|
|
178
|
+
if (should.redirectToLoginPage) {
|
|
179
|
+
// expect save local
|
|
180
|
+
await expect(tokenPromise).resolves.toBeUndefined();
|
|
181
|
+
expect(mockLocalStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({
|
|
182
|
+
oldUrl: window.location.toString()
|
|
183
|
+
}));
|
|
184
|
+
expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, "", clientArgs.loginPage);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
} else {
|
|
188
|
+
it("redirects to multipass", async () => {
|
|
189
|
+
const tokenPromise = client();
|
|
190
|
+
expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);
|
|
191
|
+
if (should.redirectToLoginPage) {
|
|
192
|
+
// expect save local
|
|
193
|
+
await expect(tokenPromise).resolves.toBeUndefined();
|
|
194
|
+
expect(mockLocalStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({
|
|
195
|
+
oldUrl: window.location.toString()
|
|
196
|
+
}));
|
|
197
|
+
expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, "", clientArgs.loginPage);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
// we assume window.location.assign will take you away therefore we
|
|
201
|
+
// also have to expect in this scenario that the thrown error happens
|
|
202
|
+
await expect(tokenPromise).rejects.toThrowError(new Error("Unable to redirect"));
|
|
203
|
+
expect(mockWindow.location.assign).toHaveBeenCalledOnce();
|
|
204
|
+
const url = new URL(mockWindow.location.assign.mock.calls[0][0]);
|
|
205
|
+
expect(url.origin).toEqual(clientArgs.foundryUrl);
|
|
206
|
+
expect(url.pathname).toEqual("/multipass/api/oauth2/authorize");
|
|
207
|
+
expect(Object.fromEntries(url.searchParams.entries())).toEqual(expect.objectContaining({
|
|
208
|
+
client_id: clientArgs.clientId,
|
|
209
|
+
code_challenge: expect.any(String),
|
|
210
|
+
redirect_uri: clientArgs.redirectUrl,
|
|
211
|
+
response_type: "code",
|
|
212
|
+
code_challenge_method: "S256",
|
|
213
|
+
scope: "offline_access api:read-data api:write-data",
|
|
214
|
+
state: expect.any(String)
|
|
215
|
+
}));
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (initialLocalState.codeVerifier) {
|
|
220
|
+
it("tries to auth with return results", async () => {
|
|
221
|
+
await expect(client()).resolves.toEqual(ACCESS_TOKEN);
|
|
222
|
+
expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);
|
|
223
|
+
expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined,
|
|
224
|
+
// this is only because we didn't mock out the internals
|
|
225
|
+
"signIn");
|
|
226
|
+
expect(mockWindow.history.replaceState).toHaveBeenCalledTimes(1);
|
|
227
|
+
expect(mockWindow.history.replaceState).toBeCalledWith(expect.anything(), expect.anything(), initialLocalState.oldUrl);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
if (initialLocalState.refresh_token) {
|
|
231
|
+
it("refreshes", async () => {
|
|
232
|
+
await expect(client()).resolves.toEqual(ACCESS_TOKEN);
|
|
233
|
+
expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);
|
|
234
|
+
expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined,
|
|
235
|
+
// this is only because we didn't mock out the internals
|
|
236
|
+
"refresh");
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
//# sourceMappingURL=publicOauth.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicOauth.test.js","names":["afterAll","afterEach","beforeAll","beforeEach","describe","expect","it","vi","commonJs","createPublicOauthClient","hoistedMocks","hoisted","makeTokenAndSaveRefresh","fn","mock","importOriginal","original","default","ms","opts","common","args","result","readLocal","spyOn","DEFAULT_CUR_URL","URL","fetchFn","mockWindow","location","toString","assign","href","pathname","history","replaceState","mockLocalStorage","setItem","getItem","removeItem","restoreAllMocks","mockRestore","clearAllMocks","mockReset","stubGlobal","unstubAllGlobals","BASE_CLIENT_ARGS","clientId","foundryUrl","redirectUrl","fullLoginUrl","each","name","currentUrl","clientArgs","should","redirectToLoginPage","loginPage","client","useHistory","postLoginPage","scopes","ctxPath","mocked","toHaveBeenCalledWith","objectContaining","client_id","token_endpoint_auth_method","createAuthorizationServer","any","Function","anything","refresh_token","codeVerifier","state","oldUrl","initialLocalState","ACCESS_TOKEN","Math","random","substring","mockImplementation","access_token","expires_at","Date","now","expires_in","Object","keys","length","tokenPromise","toBeCalledTimes","resolves","toBeUndefined","toBeCalledWith","JSON","stringify","window","rejects","toThrowError","Error","toHaveBeenCalledOnce","url","calls","origin","toEqual","fromEntries","searchParams","entries","code_challenge","String","redirect_uri","response_type","code_challenge_method","scope","toHaveBeenCalledTimes","undefined"],"sources":["publicOauth.test.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n/* eslint-disable @typescript-eslint/consistent-type-imports */\nimport { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi, } from \"vitest\";\nimport * as commonJs from \"./common.js\";\nimport { createPublicOauthClient } from \"./createPublicOauthClient.js\";\nconst hoistedMocks = vi.hoisted(() => {\n return {\n makeTokenAndSaveRefresh: vi.fn(),\n };\n});\nvi.mock(\"delay\", async (importOriginal) => {\n const original = await importOriginal();\n return {\n default: vi.fn((ms, opts) => {\n // speed up the tests\n return original.default(ms / 100, opts);\n }),\n };\n});\nvi.mock(\"./common.js\", async (importOriginal) => {\n const original = await importOriginal();\n return {\n ...original,\n common: vi.fn((...args) => {\n const result = original.common(...args);\n return {\n ...result,\n makeTokenAndSaveRefresh: hoistedMocks.makeTokenAndSaveRefresh,\n };\n }),\n readLocal: vi.spyOn(original, \"readLocal\"),\n // vi.fn(original.readLocal),\n };\n});\nvi.mock(\"oauth4webapi\");\ndescribe(createPublicOauthClient, () => {\n const DEFAULT_CUR_URL = new URL(\"https://fauxurl\");\n const fetchFn = vi.fn();\n const mockWindow = {\n location: {\n toString: vi.fn(() => DEFAULT_CUR_URL),\n assign: vi.fn(),\n href: DEFAULT_CUR_URL.href,\n pathname: DEFAULT_CUR_URL.pathname,\n },\n history: {\n replaceState: vi.fn(),\n },\n };\n const mockLocalStorage = {\n setItem: vi.fn(),\n getItem: vi.fn(),\n removeItem: vi.fn(),\n };\n beforeEach((context) => {\n vi.restoreAllMocks();\n fetchFn.mockRestore();\n });\n afterEach((context) => {\n vi.clearAllMocks();\n fetchFn.mockReset();\n });\n beforeAll(() => {\n vi.stubGlobal(\"window\", mockWindow);\n vi.stubGlobal(\"localStorage\", mockLocalStorage);\n });\n afterAll(() => {\n vi.unstubAllGlobals();\n });\n const BASE_CLIENT_ARGS = {\n clientId: \"this-would-be-client-id\",\n foundryUrl: \"https://a.foundry.url.local\",\n redirectUrl: \"https://my.redirect.url.local\",\n fetchFn,\n };\n const fullLoginUrl = new URL(\"/loginPage\", DEFAULT_CUR_URL);\n describe.each([\n {\n name: \"Basic Usage\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n {\n name: \"Base w/ full loginPage and curUrl is root\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: fullLoginUrl.toString(),\n },\n should: {\n redirectToLoginPage: true,\n },\n },\n {\n name: \"Base w/ full loginPage and curUrl is login page\",\n currentUrl: fullLoginUrl,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: fullLoginUrl.toString(),\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n {\n name: \"Base w/ short loginPage and curUrl is root\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: \"/loginPage\",\n },\n should: {\n redirectToLoginPage: true,\n },\n },\n {\n name: \"Base w/ short loginPage and curUrl is loginPage\",\n currentUrl: new URL(\"/loginPage\", DEFAULT_CUR_URL),\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: \"/loginPage\",\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n ])(\"$name\", ({ clientArgs, currentUrl, should }) => {\n let client;\n beforeEach(() => {\n client = createPublicOauthClient(clientArgs.clientId, clientArgs.foundryUrl, clientArgs.redirectUrl, clientArgs.useHistory, clientArgs.loginPage, clientArgs.postLoginPage, clientArgs.scopes, clientArgs.fetchFn, clientArgs.ctxPath);\n mockWindow.location.href = new URL(currentUrl).href;\n mockWindow.location.pathname = new URL(currentUrl).pathname;\n });\n it(\"calls common with expected values\", () => {\n expect(vi.mocked(commonJs.common)).toHaveBeenCalledWith(expect.objectContaining({\n client_id: clientArgs.clientId,\n token_endpoint_auth_method: \"none\",\n }), commonJs.createAuthorizationServer(clientArgs.ctxPath ?? \"/multipass\", clientArgs.foundryUrl), expect.any(Function), expect.anything(), expect.any(Function));\n });\n describe.each([\n {\n refresh_token: \"a-refresh-token\",\n },\n {\n codeVerifier: \"hi\",\n state: \"mom\",\n oldUrl: \"https://someoldurl.local\",\n },\n {},\n ])(\"Initial Local State: %s\", (initialLocalState) => {\n const ACCESS_TOKEN = (Math.random() + 1).toString(36).substring(7);\n beforeEach(() => {\n vi.mocked(commonJs.readLocal).mockImplementation(() => initialLocalState);\n hoistedMocks.makeTokenAndSaveRefresh.mockImplementation(() => ({\n access_token: ACCESS_TOKEN,\n expires_at: Date.now(),\n expires_in: 10000,\n }));\n });\n if (Object.keys(initialLocalState).length === 0) {\n if (should.redirectToLoginPage) {\n it(\"redirects to login page\", async () => {\n const tokenPromise = client();\n expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);\n if (should.redirectToLoginPage) {\n // expect save local\n await expect(tokenPromise).resolves.toBeUndefined();\n expect(mockLocalStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({ oldUrl: window.location.toString() }));\n expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, \"\", clientArgs.loginPage);\n return;\n }\n });\n }\n else {\n it(\"redirects to multipass\", async () => {\n const tokenPromise = client();\n expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);\n if (should.redirectToLoginPage) {\n // expect save local\n await expect(tokenPromise).resolves.toBeUndefined();\n expect(mockLocalStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({ oldUrl: window.location.toString() }));\n expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, \"\", clientArgs.loginPage);\n return;\n }\n // we assume window.location.assign will take you away therefore we\n // also have to expect in this scenario that the thrown error happens\n await expect(tokenPromise)\n .rejects.toThrowError(new Error(\"Unable to redirect\"));\n expect(mockWindow.location.assign).toHaveBeenCalledOnce();\n const url = new URL(mockWindow.location.assign.mock.calls[0][0]);\n expect(url.origin).toEqual(clientArgs.foundryUrl);\n expect(url.pathname).toEqual(\"/multipass/api/oauth2/authorize\");\n expect(Object.fromEntries(url.searchParams.entries())).toEqual(expect.objectContaining({\n client_id: clientArgs.clientId,\n code_challenge: expect.any(String),\n redirect_uri: clientArgs.redirectUrl,\n response_type: \"code\",\n code_challenge_method: \"S256\",\n scope: \"offline_access api:read-data api:write-data\",\n state: expect.any(String),\n }));\n });\n }\n }\n if (initialLocalState.codeVerifier) {\n it(\"tries to auth with return results\", async () => {\n await expect(client()).resolves.toEqual(ACCESS_TOKEN);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined, // this is only because we didn't mock out the internals\n \"signIn\");\n expect(mockWindow.history.replaceState).toHaveBeenCalledTimes(1);\n expect(mockWindow.history.replaceState).toBeCalledWith(expect.anything(), expect.anything(), initialLocalState.oldUrl);\n });\n }\n if (initialLocalState.refresh_token) {\n it(\"refreshes\", async () => {\n await expect(client()).resolves.toEqual(ACCESS_TOKEN);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined, // this is only because we didn't mock out the internals\n \"refresh\");\n });\n }\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAS,QAAQ;AAC9F,OAAO,KAAKC,QAAQ,MAAM,aAAa;AACvC,SAASC,uBAAuB,QAAQ,8BAA8B;AACtE,MAAMC,YAAY,GAAGH,EAAE,CAACI,OAAO,CAAC,MAAM;EAClC,OAAO;IACHC,uBAAuB,EAAEL,EAAE,CAACM,EAAE,CAAC;EACnC,CAAC;AACL,CAAC,CAAC;AACFN,EAAE,CAACO,IAAI,CAAC,OAAO,EAAE,MAAOC,cAAc,IAAK;EACvC,MAAMC,QAAQ,GAAG,MAAMD,cAAc,CAAC,CAAC;EACvC,OAAO;IACHE,OAAO,EAAEV,EAAE,CAACM,EAAE,CAAC,CAACK,EAAE,EAAEC,IAAI,KAAK;MACzB;MACA,OAAOH,QAAQ,CAACC,OAAO,CAACC,EAAE,GAAG,GAAG,EAAEC,IAAI,CAAC;IAC3C,CAAC;EACL,CAAC;AACL,CAAC,CAAC;AACFZ,EAAE,CAACO,IAAI,CAAC,aAAa,EAAE,MAAOC,cAAc,IAAK;EAC7C,MAAMC,QAAQ,GAAG,MAAMD,cAAc,CAAC,CAAC;EACvC,OAAO;IACH,GAAGC,QAAQ;IACXI,MAAM,EAAEb,EAAE,CAACM,EAAE,CAAC,CAAC,GAAGQ,IAAI,KAAK;MACvB,MAAMC,MAAM,GAAGN,QAAQ,CAACI,MAAM,CAAC,GAAGC,IAAI,CAAC;MACvC,OAAO;QACH,GAAGC,MAAM;QACTV,uBAAuB,EAAEF,YAAY,CAACE;MAC1C,CAAC;IACL,CAAC,CAAC;IACFW,SAAS,EAA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CAAC2D,cAAc,CAACzF,MAAM,CAACkE,QAAQ,CAAC,CAAC,EAAElE,MAAM,CAACkE,QAAQ,CAAC,CAAC,EAAEK,iBAAiB,CAACD,MAAM,CAAC;QAC1H,CAAC,CAAC;MACN;MACA,IAAIC,iBAAiB,CAACJ,aAAa,EAAE;QACjClE,EAAE,CAAC,WAAW,EAAE,YAAY;UACxB,MAAMD,MAAM,CAACqD,MAAM,CAAC,CAAC,CAAC,CAACkC,QAAQ,CAACa,OAAO,CAAC5B,YAAY,CAAC;UACrDxE,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACuG,qBAAqB,CAAC,CAAC,CAAC;UACrE9G,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACoD,oBAAoB,CAACoD,SAAS;UAAE;UAC7E,SAAS,CAAC;QACd,CAAC,CAAC;MACN;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PublicOauthClientOptions } from "./createPublicOauthClient.js";
|
|
2
|
+
export type ProcessedPublicOauthClientOptions = Omit<Required<PublicOauthClientOptions>, "loginPage"> & {
|
|
3
|
+
loginPage?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function processOptionsAndAssignDefaults(url: string, redirect_uri: string, useHistory?: boolean | PublicOauthClientOptions, loginPage?: string, postLoginPage?: string, scopes?: string[], fetchFn?: typeof globalThis.fetch, ctxPath?: string): ProcessedPublicOauthClientOptions;
|
|
6
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAE7E,MAAM,MAAM,iCAAiC,GACzC,IAAI,CAAC,QAAQ,CAAC,wBAAwB,CAAC,EAAE,WAAW,CAAC,GACrD;IACA,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEJ,wBAAgB,+BAA+B,CAC7C,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,EACpB,UAAU,CAAC,EAAE,OAAO,GAAG,wBAAwB,EAC/C,SAAS,CAAC,EAAE,MAAM,EAClB,aAAa,CAAC,EAAE,MAAM,EACtB,MAAM,CAAC,EAAE,MAAM,EAAE,EACjB,OAAO,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,EACjC,OAAO,CAAC,EAAE,MAAM,GACf,iCAAiC,CAgCnC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import invariant from "tiny-invariant";
|
|
17
|
+
export function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {
|
|
18
|
+
let options = {};
|
|
19
|
+
if (typeof useHistory === "object") {
|
|
20
|
+
!(!loginPage && !postLoginPage && !scopes && !fetchFn && !ctxPath) ? process.env.NODE_ENV !== "production" ? invariant(false, "If useHistory is an object, other options should not be provided") : invariant(false) : void 0;
|
|
21
|
+
options = useHistory;
|
|
22
|
+
} else {
|
|
23
|
+
options = {
|
|
24
|
+
useHistory,
|
|
25
|
+
loginPage,
|
|
26
|
+
postLoginPage,
|
|
27
|
+
scopes,
|
|
28
|
+
fetchFn,
|
|
29
|
+
ctxPath
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
!url ? process.env.NODE_ENV !== "production" ? invariant(false, "url is required") : invariant(false) : void 0;
|
|
33
|
+
!redirect_uri ? process.env.NODE_ENV !== "production" ? invariant(false, "redirectUrl is required") : invariant(false) : void 0;
|
|
34
|
+
// Assign defaults
|
|
35
|
+
return {
|
|
36
|
+
useHistory: options.useHistory ?? true,
|
|
37
|
+
loginPage: options.loginPage,
|
|
38
|
+
postLoginPage: options.postLoginPage || window.location.toString(),
|
|
39
|
+
scopes: options.scopes ?? ["api:read-data", "api:write-data"],
|
|
40
|
+
fetchFn: options.fetchFn ?? globalThis.fetch,
|
|
41
|
+
ctxPath: options.ctxPath ?? "multipass"
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["invariant","processOptionsAndAssignDefaults","url","redirect_uri","useHistory","loginPage","postLoginPage","scopes","fetchFn","ctxPath","options","process","env","NODE_ENV","window","location","toString","globalThis","fetch"],"sources":["utils.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport invariant from \"tiny-invariant\";\nexport function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {\n let options = {};\n if (typeof useHistory === \"object\") {\n invariant(!loginPage && !postLoginPage && !scopes && !fetchFn && !ctxPath, \"If useHistory is an object, other options should not be provided\");\n options = useHistory;\n }\n else {\n options = {\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n };\n }\n invariant(url, \"url is required\");\n invariant(redirect_uri, \"redirectUrl is required\");\n // Assign defaults\n return {\n useHistory: options.useHistory ?? true,\n loginPage: options.loginPage,\n postLoginPage: options.postLoginPage || window.location.toString(),\n scopes: options.scopes ?? [\"api:read-data\", \"api:write-data\"],\n fetchFn: options.fetchFn ?? globalThis.fetch,\n ctxPath: options.ctxPath ?? \"multipass\",\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,OAAO,SAASC,+BAA+BA,CAACC,GAAG,EAAEC,YAAY,EAAEC,UAAU,EAAEC,SAAS,EAAEC,aAAa,EAAEC,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE;EAC/H,IAAIC,OAAO,GAAG,CAAC,CAAC;EAChB,IAAI,OAAON,UAAU,KAAK,QAAQ,EAAE;IAChC,EAAU,CAACC,SAAS,IAAI,CAACC,aAAa,IAAI,CAACC,MAAM,IAAI,CAACC,OAAO,IAAI,CAACC,OAAO,IAAAE,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAzEb,SAAS,QAAkE,kEAAkE,IAA7IA,SAAS;IACTU,OAAO,GAAGN,UAAU;EACxB,CAAC,MACI;IACDM,OAAO,GAAG;MACNN,UAAU;MACVC,SAAS;MACTC,aAAa;MACbC,MAAM;MACNC,OAAO;MACPC;IACJ,CAAC;EACL;EACA,CAAUP,GAAG,GAAAS,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAbb,SAAS,QAAM,iBAAiB,IAAhCA,SAAS;EACT,CAAUG,YAAY,GAAAQ,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAtBb,SAAS,QAAe,yBAAyB,IAAjDA,SAAS;EACT;EACA,OAAO;IACHI,UAAU,EAAEM,OAAO,CAACN,UAAU,IAAI,IAAI;IACtCC,SAAS,EAAEK,OAAO,CAACL,SAAS;IAC5BC,aAAa,EAAEI,OAAO,CAACJ,aAAa,IAAIQ,MAAM,CAACC,QAAQ,CAACC,QAAQ,CAAC,CAAC;IAClET,MAAM,EAAEG,OAAO,CAACH,MAAM,IAAI,CAAC,eAAe,EAAE,gBAAgB,CAAC;IAC7DC,OAAO,EAAEE,OAAO,CAACF,OAAO,IAAIS,UAAU,CAACC,KAAK;IAC5CT,OAAO,EAAEC,OAAO,CAACD,OAAO,IAAI;EAChC,CAAC;AACL","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdk/oauth",
|
|
3
|
-
"version": "1.1.0-beta.
|
|
3
|
+
"version": "1.1.0-beta.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"jest-extended": "^4.0.2",
|
|
29
29
|
"typescript": "~5.5.4",
|
|
30
30
|
"@osdk/monorepo.api-extractor": "~0.0.0",
|
|
31
|
-
"@osdk/monorepo.
|
|
32
|
-
"@osdk/monorepo.
|
|
31
|
+
"@osdk/monorepo.tsconfig": "~0.0.0",
|
|
32
|
+
"@osdk/monorepo.tsup": "~0.0.0"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|