@osdk/oauth 1.8.0-beta.4 → 1.8.0-beta.5

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/browser/Logger.js +2 -0
  3. package/build/browser/Logger.js.map +1 -0
  4. package/build/browser/createPublicOauthClient.js +5 -5
  5. package/build/browser/createPublicOauthClient.js.map +1 -1
  6. package/build/browser/index.js.map +1 -1
  7. package/build/browser/utils.js +2 -1
  8. package/build/browser/utils.js.map +1 -1
  9. package/build/cjs/index.cjs +7 -4
  10. package/build/cjs/index.cjs.map +1 -1
  11. package/build/cjs/index.d.cts +10 -1
  12. package/build/esm/Logger.js +2 -0
  13. package/build/esm/Logger.js.map +1 -0
  14. package/build/esm/createPublicOauthClient.js +5 -5
  15. package/build/esm/createPublicOauthClient.js.map +1 -1
  16. package/build/esm/index.js.map +1 -1
  17. package/build/esm/utils.js +2 -1
  18. package/build/esm/utils.js.map +1 -1
  19. package/build/types/Logger.d.ts +3 -0
  20. package/build/types/Logger.d.ts.map +1 -0
  21. package/build/types/createPublicOauthClient.d.ts +6 -0
  22. package/build/types/createPublicOauthClient.d.ts.map +1 -1
  23. package/build/types/index.d.ts +1 -0
  24. package/build/types/index.d.ts.map +1 -1
  25. package/build/types/utils.d.ts +3 -1
  26. package/build/types/utils.d.ts.map +1 -1
  27. package/package.json +3 -3
  28. package/build/browser/AuthorizationServer.test.js +0 -53
  29. package/build/browser/AuthorizationServer.test.js.map +0 -1
  30. package/build/browser/__tests__/createPublicOauthClient.test.js +0 -59
  31. package/build/browser/__tests__/createPublicOauthClient.test.js.map +0 -1
  32. package/build/browser/common.test.js +0 -68
  33. package/build/browser/common.test.js.map +0 -1
  34. package/build/browser/createAuthlessClient.test.js +0 -31
  35. package/build/browser/createAuthlessClient.test.js.map +0 -1
  36. package/build/browser/publicOauth.test.js +0 -430
  37. package/build/browser/publicOauth.test.js.map +0 -1
  38. package/build/esm/AuthorizationServer.test.js +0 -53
  39. package/build/esm/AuthorizationServer.test.js.map +0 -1
  40. package/build/esm/__tests__/createPublicOauthClient.test.js +0 -59
  41. package/build/esm/__tests__/createPublicOauthClient.test.js.map +0 -1
  42. package/build/esm/common.test.js +0 -68
  43. package/build/esm/common.test.js.map +0 -1
  44. package/build/esm/createAuthlessClient.test.js +0 -31
  45. package/build/esm/createAuthlessClient.test.js.map +0 -1
  46. package/build/esm/publicOauth.test.js +0 -430
  47. package/build/esm/publicOauth.test.js.map +0 -1
  48. package/build/types/AuthorizationServer.test.d.ts +0 -1
  49. package/build/types/AuthorizationServer.test.d.ts.map +0 -1
  50. package/build/types/__tests__/createPublicOauthClient.test.d.ts +0 -1
  51. package/build/types/__tests__/createPublicOauthClient.test.d.ts.map +0 -1
  52. package/build/types/common.test.d.ts +0 -1
  53. package/build/types/common.test.d.ts.map +0 -1
  54. package/build/types/createAuthlessClient.test.d.ts +0 -1
  55. package/build/types/createAuthlessClient.test.d.ts.map +0 -1
  56. package/build/types/publicOauth.test.d.ts +0 -1
  57. package/build/types/publicOauth.test.d.ts.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"createPublicOauthClient.test.js","names":["createPublicOauthClient","oauthModule","describe","expect","it","vi","utilsModule","originalCreatePublicOauthClient","FOUNDRY_CLIENT_ID","FOUNDRY_URL","REDIRECT_URI","stubGlobal","location","toString","fn","mockReturnValue","mockProcessOptionsAndAssignDefaults","spyOn","mockImplementation","args","processOptionsAndAssignDefaults","_client_id","rest","authClient","undefined","fetch","toBeDefined","toHaveBeenCalledTimes","authClientWithOptions","useHistory","fetchFn","result1","result2","mock","results","value","toEqual"],"sources":["createPublicOauthClient.test.ts"],"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\nimport { createPublicOauthClient } from \"@osdk/oauth\";\nimport * as oauthModule from \"@osdk/oauth\";\nimport { describe, expect, it, vi } from \"vitest\";\nimport * as utilsModule from \"../utils.js\";\n\nconst originalCreatePublicOauthClient = oauthModule.createPublicOauthClient;\n\nconst FOUNDRY_CLIENT_ID = \"example-foundry-client-id\";\nconst FOUNDRY_URL = \"http://example-foundry-url.com\";\nconst REDIRECT_URI = \"http://localhost:8080/auth/callback\";\n\nvi.stubGlobal(\"window\", {\n location: {\n toString: vi.fn().mockReturnValue(\"http://example.com\"),\n },\n});\n\ntype CreatePublicOauthClientParams = Parameters<typeof createPublicOauthClient>;\n\ntype ProcessedPublicOauthClientOptionsParams = Parameters<\n typeof utilsModule.processOptionsAndAssignDefaults\n>;\n\ntype ProcessedPublicOauthClientOptionsReturn = ReturnType<\n typeof utilsModule.processOptionsAndAssignDefaults\n>;\n\ndescribe(\"createPublicOauthClient\", () => {\n it(\"should return the same processed options for both client creation methods\", async () => {\n const mockProcessOptionsAndAssignDefaults = vi.fn<\n (\n ...args: ProcessedPublicOauthClientOptionsParams\n ) => ProcessedPublicOauthClientOptionsReturn\n >();\n\n // Mock processOptionsAndAssignDefaults to call the mock function\n vi.spyOn(utilsModule, \"processOptionsAndAssignDefaults\").mockImplementation(\n (\n ...args: ProcessedPublicOauthClientOptionsParams\n ) => {\n mockProcessOptionsAndAssignDefaults(...args);\n return utilsModule.processOptionsAndAssignDefaults(...args);\n },\n );\n\n // Mock createPublicOauthClient to call both the mock and the original function\n vi.spyOn(oauthModule, \"createPublicOauthClient\").mockImplementation(\n (\n ...args: CreatePublicOauthClientParams\n ) => {\n const [_client_id, ...rest] = args;\n mockProcessOptionsAndAssignDefaults(...rest);\n return originalCreatePublicOauthClient(...args);\n },\n );\n\n const authClient = createPublicOauthClient(\n FOUNDRY_CLIENT_ID,\n FOUNDRY_URL,\n REDIRECT_URI,\n true,\n undefined,\n undefined,\n undefined,\n fetch,\n undefined,\n );\n\n expect(authClient).toBeDefined();\n expect(mockProcessOptionsAndAssignDefaults).toHaveBeenCalledTimes(1);\n\n const authClientWithOptions = createPublicOauthClient(\n FOUNDRY_CLIENT_ID,\n FOUNDRY_URL,\n REDIRECT_URI,\n {\n useHistory: true,\n fetchFn: fetch,\n },\n );\n\n expect(authClientWithOptions).toBeDefined();\n expect(mockProcessOptionsAndAssignDefaults).toHaveBeenCalledTimes(2);\n\n const [result1, result2] = mockProcessOptionsAndAssignDefaults.mock.results;\n expect(result1.value).toEqual(result2.value);\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,uBAAuB,QAAQ,aAAa;AACrD,OAAO,KAAKC,WAAW,MAAM,aAAa;AAC1C,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,QAAQ;AACjD,OAAO,KAAKC,WAAW,MAAM,aAAa;AAE1C,MAAMC,+BAA+B,GAAGN,WAAW,CAACD,uBAAuB;AAE3E,MAAMQ,iBAAiB,GAAG,2BAA2B;AACrD,MAAMC,WAAW,GAAG,gCAAgC;AACpD,MAAMC,YAAY,GAAG,qCAAqC;AAE1DL,EAAE,CAACM,UAAU,CAAC,QAAQ,EAAE;EACtBC,QAAQ,EAAE;IACRC,QAAQ,EAAER,EAAE,CAACS,EAAE,CAAC,CAAC,CAACC,eAAe,CAAC,oBAAoB;EACxD;AACF,CAAC,CAAC;AAYFb,QAAQ,CAAC,yBAAyB,EAAE,MAAM;EACxCE,EAAE,CAAC,2EAA2E,EAAE,YAAY;IAC1F,MAAMY,mCAAmC,GAAGX,EAAE,CAACS,EAAE,CAI/C,CAAC;;IAEH;IACAT,EAAE,CAACY,KAAK,CAACX,W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C,CAAC","ignoreList":[]}
@@ -1,68 +0,0 @@
1
- /*
2
- * Copyright 2025 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
-
17
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
18
- import { common, createAuthorizationServer, readLocal, removeLocal, saveLocal } from "./common.js";
19
- describe("local functions", () => {
20
- beforeEach(() => {
21
- vi.stubGlobal("localStorage", {
22
- setItem: vi.fn(),
23
- removeItem: vi.fn(),
24
- getItem: vi.fn()
25
- });
26
- });
27
- afterEach(() => {
28
- vi.unstubAllGlobals();
29
- });
30
- it("should use the old style keys when there is no refresh token marker", () => {
31
- const client = {
32
- client_id: "hi_mom",
33
- $refreshTokenMarker: undefined
34
- };
35
- const oldLocalStorageKey = `@osdk/oauth : refresh : ${client.client_id}`;
36
- const storage = globalThis.localStorage;
37
- readLocal(client, storage);
38
- removeLocal(client, storage);
39
- saveLocal(client, {}, storage);
40
- expect(vi.mocked(globalThis.localStorage.getItem)).toBeCalledWith(oldLocalStorageKey);
41
- expect(vi.mocked(globalThis.localStorage.setItem)).toBeCalledWith(oldLocalStorageKey, expect.anything());
42
- expect(vi.mocked(globalThis.localStorage.removeItem)).toBeCalledWith(oldLocalStorageKey);
43
- });
44
- it("should save the refreshTokenMaker if it exists, as well as the requested scopes", () => {
45
- const client = {
46
- client_id: "hi_mom"
47
- };
48
- const signIn = vi.fn();
49
- const refresh = vi.fn();
50
- const storage = globalThis.localStorage;
51
- const authServer = createAuthorizationServer("multipass", "https://stack.palantir.com");
52
- const {
53
- makeTokenAndSaveRefresh
54
- } = common(client, authServer, signIn, {}, refresh, "marker marker", "yay:my-fun-scope sad:my-boring-scope", storage);
55
- makeTokenAndSaveRefresh({
56
- refresh_token: "refresh",
57
- access_token: "access",
58
- token_type: "idk",
59
- expires_in: 10_000
60
- }, "signIn");
61
- expect(globalThis.localStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${client.client_id}`, JSON.stringify({
62
- refresh_token: "refresh",
63
- refreshTokenMarker: "marker marker",
64
- requestedScopes: "yay:my-fun-scope sad:my-boring-scope"
65
- }));
66
- });
67
- });
68
- //# sourceMappingURL=common.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.test.js","names":["afterEach","beforeEach","describe","expect","it","vi","common","createAuthorizationServer","readLocal","removeLocal","saveLocal","stubGlobal","setItem","fn","removeItem","getItem","unstubAllGlobals","client","client_id","$refreshTokenMarker","undefined","oldLocalStorageKey","storage","globalThis","localStorage","mocked","toBeCalledWith","anything","signIn","refresh","authServer","makeTokenAndSaveRefresh","refresh_token","access_token","token_type","expires_in","JSON","stringify","refreshTokenMarker","requestedScopes"],"sources":["common.test.ts"],"sourcesContent":["/*\n * Copyright 2025 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\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport {\n common,\n createAuthorizationServer,\n readLocal,\n removeLocal,\n saveLocal,\n} from \"./common.js\";\n\ndescribe(\"local functions\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"localStorage\", {\n setItem: vi.fn(),\n removeItem: vi.fn(),\n getItem: vi.fn(),\n });\n });\n\n afterEach(() => {\n vi.unstubAllGlobals();\n });\n\n it(\"should use the old style keys when there is no refresh token marker\", () => {\n const client = {\n client_id: \"hi_mom\",\n $refreshTokenMarker: undefined,\n };\n\n const oldLocalStorageKey = `@osdk/oauth : refresh : ${client.client_id}`;\n const storage = globalThis.localStorage;\n\n readLocal(client, storage);\n removeLocal(client, storage);\n saveLocal(client, {}, storage);\n\n expect(vi.mocked(globalThis.localStorage.getItem)).toBeCalledWith(\n oldLocalStorageKey,\n );\n\n expect(vi.mocked(globalThis.localStorage.setItem)).toBeCalledWith(\n oldLocalStorageKey,\n expect.anything(),\n );\n\n expect(vi.mocked(globalThis.localStorage.removeItem)).toBeCalledWith(\n oldLocalStorageKey,\n );\n });\n\n it(\"should save the refreshTokenMaker if it exists, as well as the requested scopes\", () => {\n const client = {\n client_id: \"hi_mom\",\n };\n\n const signIn = vi.fn();\n const refresh = vi.fn();\n const storage = globalThis.localStorage;\n\n const authServer = createAuthorizationServer(\n \"multipass\",\n \"https://stack.palantir.com\",\n );\n\n const { makeTokenAndSaveRefresh } = common(\n client,\n authServer,\n signIn,\n {},\n refresh,\n \"marker marker\",\n \"yay:my-fun-scope sad:my-boring-scope\",\n storage,\n );\n\n makeTokenAndSaveRefresh({\n refresh_token: \"refresh\",\n access_token: \"access\",\n token_type: \"idk\",\n expires_in: 10_000,\n }, \"signIn\");\n\n expect(globalThis.localStorage.setItem).toBeCalledWith(\n `@osdk/oauth : refresh : ${client.client_id}`,\n JSON.stringify({\n refresh_token: \"refresh\",\n refreshTokenMarker: \"marker marker\",\n requestedScopes: \"yay:my-fun-scope sad:my-boring-scope\",\n }),\n );\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,QAAQ;AACxE,SACEC,MAAM,E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AAC;EACH,CAAC,CAAC;EAEFjB,EAAE,CAAC,iFAAiF,EAAE,MAAM;IAC1F,MAAMa,MAAM,GAAG;MACbC,SAAS,EAAE;IACb,CAAC;IAED,MAAMU,MAAM,GAAGvB,EAAE,CAACQ,EAAE,CAAC,CAAC;IACtB,MAAMgB,OAAO,GAAGxB,EAAE,CAACQ,EAAE,CAAC,CAAC;IACvB,MAAMS,OAAO,GAAGC,UAAU,CAACC,YAAY;IAEvC,MAAMM,UAAU,GAAGvB,yBAAyB,CAC1C,WAAW,EACX,4BACF,CAAC;IAED,MAAM;MAAEwB;IAAwB,CAAC,GAAGzB,MAAM,CACxCW,MAAM,EACNa,UAAU,EACVF,MAAM,EACN,CAAC,CAAC,EACFC,OAAO,EACP,eAAe,EACf,sCAAsC,EACtCP,OACF,CAAC;IAEDS,uBAAuB,CAAC;MACtBC,aAAa,EAAE,SAAS;MACxBC,YAAY,EAAE,QAAQ;MACtBC,UAAU,EAAE,KAAK;MACjBC,UAAU,EAAE;IACd,CAAC,EAAE,QAAQ,CAAC;IAEZhC,MAAM,CAACoB,UAAU,CAACC,YAAY,CAACZ,OAAO,CAAC,CAACc,cAAc,CACpD,2BAA2BT,MAAM,CAACC,SAAS,EAAE,EAC7CkB,IAAI,CAACC,SAAS,CAAC;MACbL,aAAa,EAAE,SAAS;MACxBM,kBAAkB,EAAE,eAAe;MACnCC,eAAe,EAAE;IACnB,CAAC,CACH,CAAC;EACH,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -1,31 +0,0 @@
1
- /*
2
- * Copyright 2025 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
-
17
- import { describe, expect, it } from "vitest";
18
- import { createAuthlessClient } from "./createAuthlessClient.js";
19
- describe(createAuthlessClient, () => {
20
- it("should return \"PUBLIC\" when called", async () => {
21
- const authlessClientProvider = createAuthlessClient();
22
- const result = await authlessClientProvider();
23
- expect(result).toBe("PUBLIC");
24
- });
25
- it("should return a Promise", () => {
26
- const authlessClientProvider = createAuthlessClient();
27
- const resultPromise = authlessClientProvider();
28
- expect(resultPromise).toBeInstanceOf(Promise);
29
- });
30
- });
31
- //# sourceMappingURL=createAuthlessClient.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAuthlessClient.test.js","names":["describe","expect","it","createAuthlessClient","authlessClientProvider","result","toBe","resultPromise","toBeInstanceOf","Promise"],"sources":["createAuthlessClient.test.ts"],"sourcesContent":["/*\n * Copyright 2025 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\nimport { describe, expect, it } from \"vitest\";\nimport { createAuthlessClient } from \"./createAuthlessClient.js\";\n\ndescribe(createAuthlessClient, () => {\n it(\"should return \\\"PUBLIC\\\" when called\", async () => {\n const authlessClientProvider = createAuthlessClient();\n const result = await authlessClientProvider();\n expect(result).toBe(\"PUBLIC\");\n });\n\n it(\"should return a Promise\", () => {\n const authlessClientProvider = createAuthlessClient();\n const resultPromise = authlessClientProvider();\n expect(resultPromise).toBeInstanceOf(Promise);\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,SAASC,oBAAoB,QAAQ,2BAA2B;AAEhEH,QAAQ,CAACG,oBAAoB,EAAE,MAAM;EACnCD,EAAE,CAAC,sCAAsC,EAAE,YAAY;IACrD,MAAME,sBAAsB,GAAGD,oBAAoB,CAAC,CAAC;IACrD,MAAME,MAAM,GAAG,MAAMD,sBAAsB,CAAC,CAAC;IAC7CH,MAAM,CAACI,MAAM,CAAC,CAACC,IAAI,CAAC,QAAQ,CAAC;EAC/B,CAAC,CAAC;EAEFJ,EAAE,CAAC,yBAAyB,EAAE,MAAM;IAClC,MAAME,sBAAsB,GAAGD,oBAAoB,CAAC,CAAC;IACrD,MAAMI,aAAa,GAAGH,sBAAsB,CAAC,CAAC;IAC9CH,MAAM,CAACM,aAAa,CAAC,CAACC,cAAc,CAACC,OAAO,CAAC;EAC/C,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -1,430 +0,0 @@
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
-
17
- /* eslint-disable @typescript-eslint/consistent-type-imports */
18
- import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
19
- import * as commonJs from "./common.js";
20
- import { createPublicOauthClient } from "./createPublicOauthClient.js";
21
- const hoistedMocks = vi.hoisted(() => {
22
- return {
23
- makeTokenAndSaveRefresh: vi.fn()
24
- };
25
- });
26
- vi.mock("./delay.js", () => ({
27
- delay: vi.fn(ms => new Promise(resolve => setTimeout(resolve, ms / 100)))
28
- }));
29
- vi.mock("./common.js", async importOriginal => {
30
- const original = await importOriginal();
31
- return {
32
- ...original,
33
- common: vi.fn((...args) => {
34
- const result = original.common(...args);
35
- return {
36
- ...result,
37
- makeTokenAndSaveRefresh: hoistedMocks.makeTokenAndSaveRefresh
38
- };
39
- }),
40
- readLocal: vi.spyOn(original, "readLocal"),
41
- readSession: vi.spyOn(original, "readSession")
42
- // vi.fn(original.readLocal),
43
- };
44
- });
45
- vi.mock("oauth4webapi");
46
- describe(createPublicOauthClient, () => {
47
- const DEFAULT_CUR_URL = new URL("https://fauxurl");
48
- const fetchFn = vi.fn();
49
- const mockWindow = {
50
- location: {
51
- toString: vi.fn(() => DEFAULT_CUR_URL),
52
- assign: vi.fn(),
53
- href: DEFAULT_CUR_URL.href,
54
- pathname: DEFAULT_CUR_URL.pathname
55
- },
56
- history: {
57
- replaceState: vi.fn()
58
- }
59
- };
60
- const mockLocalStorage = {
61
- setItem: vi.fn(),
62
- getItem: vi.fn(),
63
- removeItem: vi.fn()
64
- };
65
- const mockSessionStorage = {
66
- setItem: vi.fn(),
67
- getItem: vi.fn(),
68
- removeItem: vi.fn()
69
- };
70
- beforeEach(() => {
71
- vi.restoreAllMocks();
72
- fetchFn.mockRestore();
73
- });
74
- afterEach(() => {
75
- vi.clearAllMocks();
76
- fetchFn.mockReset();
77
- });
78
- beforeAll(() => {
79
- vi.stubGlobal("window", mockWindow);
80
- vi.stubGlobal("localStorage", mockLocalStorage);
81
- vi.stubGlobal("sessionStorage", mockSessionStorage);
82
- });
83
- afterAll(() => {
84
- vi.unstubAllGlobals();
85
- });
86
- const BASE_CLIENT_ARGS = {
87
- clientId: "this-would-be-client-id",
88
- foundryUrl: "https://a.foundry.url.local",
89
- redirectUrl: "https://my.redirect.url.local",
90
- fetchFn
91
- };
92
- const fullLoginUrl = new URL("/loginPage", DEFAULT_CUR_URL);
93
- function setupWindowLocation(currentUrl) {
94
- mockWindow.location.href = new URL(currentUrl).href;
95
- mockWindow.location.pathname = new URL(currentUrl).pathname;
96
- }
97
- function setupLocalState(initialLocalState) {
98
- vi.mocked(commonJs.readLocal).mockImplementation(() => initialLocalState);
99
- }
100
- let client;
101
- let clientArgs;
102
- function setupClient(clientArgs_) {
103
- clientArgs = clientArgs_;
104
- if (clientArgs.refreshTokenMarker) {
105
- client = createPublicOauthClient(clientArgs.clientId, clientArgs.foundryUrl, clientArgs.redirectUrl, clientArgs);
106
- } else {
107
- client = createPublicOauthClient(clientArgs.clientId, clientArgs.foundryUrl, clientArgs.redirectUrl, clientArgs.useHistory, clientArgs.loginPage, clientArgs.postLoginPage, clientArgs.scopes, clientArgs.fetchFn, clientArgs.ctxPath);
108
- }
109
- }
110
- beforeEach(() => {
111
- // prevents mistakes like forgetting to initialize the client with an
112
- // old value around
113
- client = undefined;
114
- clientArgs = undefined;
115
- });
116
- async function expectRedirectToMultipass(tokenPromise) {
117
- // we assume window.location.assign will take you away therefore we
118
- // also have to expect in this scenario that the thrown error happens
119
- await expect(tokenPromise).rejects.toThrowError(new Error("Unable to redirect"));
120
- expect(mockWindow.location.assign).toHaveBeenCalledOnce();
121
- const url = new URL(mockWindow.location.assign.mock.calls[0][0]);
122
- expect(url.origin).toEqual(clientArgs.foundryUrl);
123
- expect(url.pathname).toEqual("/multipass/api/oauth2/authorize");
124
- expect(Object.fromEntries(url.searchParams.entries())).toEqual(expect.objectContaining({
125
- client_id: clientArgs.clientId,
126
- code_challenge: expect.any(String),
127
- redirect_uri: clientArgs.redirectUrl,
128
- response_type: "code",
129
- code_challenge_method: "S256",
130
- scope: ["offline_access", ...(clientArgs.scopes ?? ["api:read-data", "api:write-data", "api:use-ontologies-read", "api:use-ontologies-write"].sort())].join(" "),
131
- state: expect.any(String)
132
- }));
133
- }
134
- describe("refresh token marker and scopes", () => {
135
- beforeEach(() => {
136
- setupWindowLocation("https://foundry.local");
137
- });
138
-
139
- // Backwards compatibility from when we didn't store scopes
140
- it("should not allow refresh if scopes in local storage is undefined", async () => {
141
- setupLocalState({
142
- refresh_token: "refreshToken"
143
- });
144
- setupClient({
145
- ...BASE_CLIENT_ARGS
146
- // Testing with default scopes
147
- });
148
- await expectRedirectToMultipass(client());
149
- });
150
- it("should not allow refresh if requested scopes are different", async () => {
151
- setupLocalState({
152
- refresh_token: "refreshToken",
153
- requestedScopes: "api:read-data"
154
- });
155
- setupClient({
156
- ...BASE_CLIENT_ARGS,
157
- scopes: ["api:write-data"]
158
- });
159
- await expectRedirectToMultipass(client());
160
- });
161
- it("should not allow refresh if the refresh markers do not match", async () => {
162
- setupLocalState({
163
- refresh_token: "refreshToken",
164
- refreshTokenMarker: "not-the-right-marker",
165
- requestedScopes: "api:read-data"
166
- });
167
- setupClient({
168
- ...BASE_CLIENT_ARGS,
169
- refreshTokenMarker: "marker",
170
- scopes: ["api:read-data"]
171
- });
172
- await expectRedirectToMultipass(client());
173
- });
174
- it("should try to refresh if refresh markers match and requested scopes are equal", async () => {
175
- setupLocalState({
176
- refresh_token: "refreshToken",
177
- refreshTokenMarker: "marker",
178
- requestedScopes: "api:admin-read api:datasets-read"
179
- });
180
- setupClient({
181
- ...BASE_CLIENT_ARGS,
182
- refreshTokenMarker: "marker",
183
- scopes: ["api:datasets-read", "api:admin-read"]
184
- });
185
- hoistedMocks.makeTokenAndSaveRefresh.mockImplementationOnce(() => ({
186
- access_token: "some token",
187
- expires_at: Date.now(),
188
- expires_in: 10000
189
- }));
190
- const tokenPromise = client();
191
- await expect(tokenPromise).resolves.toEqual("some token");
192
- expect(hoistedMocks.makeTokenAndSaveRefresh).toBeCalledTimes(1);
193
- });
194
- });
195
- describe.each([{
196
- name: "Basic Usage",
197
- currentUrl: DEFAULT_CUR_URL,
198
- clientArgs: {
199
- ...BASE_CLIENT_ARGS
200
- },
201
- should: {
202
- redirectToLoginPage: false
203
- }
204
- }, {
205
- name: "Base w/ full loginPage and curUrl is root",
206
- currentUrl: DEFAULT_CUR_URL,
207
- clientArgs: {
208
- ...BASE_CLIENT_ARGS,
209
- loginPage: fullLoginUrl.toString()
210
- },
211
- should: {
212
- redirectToLoginPage: true
213
- }
214
- }, {
215
- name: "Base w/ full loginPage and curUrl is login page",
216
- currentUrl: fullLoginUrl,
217
- clientArgs: {
218
- ...BASE_CLIENT_ARGS,
219
- loginPage: fullLoginUrl.toString()
220
- },
221
- should: {
222
- redirectToLoginPage: false
223
- }
224
- }, {
225
- name: "Base w/ short loginPage and curUrl is root",
226
- currentUrl: DEFAULT_CUR_URL,
227
- clientArgs: {
228
- ...BASE_CLIENT_ARGS,
229
- loginPage: "/loginPage"
230
- },
231
- should: {
232
- redirectToLoginPage: true
233
- }
234
- }, {
235
- name: "Base w/ short loginPage and curUrl is loginPage",
236
- currentUrl: new URL("/loginPage", DEFAULT_CUR_URL),
237
- clientArgs: {
238
- ...BASE_CLIENT_ARGS,
239
- loginPage: "/loginPage"
240
- },
241
- should: {
242
- redirectToLoginPage: false
243
- }
244
- }])("$name", ({
245
- clientArgs,
246
- currentUrl,
247
- should
248
- }) => {
249
- beforeEach(() => {
250
- setupClient(clientArgs);
251
- setupWindowLocation(currentUrl.toString());
252
- });
253
- it("calls common with expected values", () => {
254
- expect(vi.mocked(commonJs.common)).toHaveBeenCalledWith(expect.objectContaining({
255
- client_id: clientArgs.clientId,
256
- token_endpoint_auth_method: "none"
257
- }), commonJs.createAuthorizationServer(clientArgs.ctxPath ?? "/multipass", clientArgs.foundryUrl), expect.any(Function), expect.anything(), expect.any(Function), undefined, (clientArgs.scopes ?? ["api:read-data", "api:write-data", "api:use-ontologies-read", "api:use-ontologies-write"]).sort().join(" "), undefined);
258
- });
259
- describe.each([{
260
- localStorage: {
261
- refresh_token: "a-refresh-token",
262
- requestedScopes: (clientArgs.scopes ?? ["api:read-data", "api:write-data", "api:use-ontologies-read", "api:use-ontologies-write"]).sort().join(" ")
263
- },
264
- sessionStorage: {}
265
- }, {
266
- localStorage: {},
267
- sessionStorage: {
268
- codeVerifier: "hi",
269
- state: "mom",
270
- oldUrl: "https://someoldurl.local"
271
- }
272
- }, {
273
- localStorage: {},
274
- sessionStorage: {}
275
- }])("Initial Local State: %s", initialState => {
276
- const ACCESS_TOKEN = (Math.random() + 1).toString(36).substring(7);
277
- beforeEach(() => {
278
- vi.mocked(commonJs.readLocal).mockImplementation(() => initialState.localStorage);
279
- vi.mocked(commonJs.readSession).mockImplementation(() => initialState.sessionStorage);
280
- hoistedMocks.makeTokenAndSaveRefresh.mockImplementation(() => ({
281
- access_token: ACCESS_TOKEN,
282
- expires_at: Date.now(),
283
- expires_in: 10000
284
- }));
285
- });
286
- if (Object.keys(initialState.localStorage).length === 0 && Object.keys(initialState.sessionStorage).length === 0) {
287
- if (should.redirectToLoginPage) {
288
- it("redirects to login page", async () => {
289
- const tokenPromise = client();
290
- expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);
291
- if (should.redirectToLoginPage) {
292
- // expect save local
293
- await expect(tokenPromise).resolves.toBeUndefined();
294
- expect(mockSessionStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({
295
- oldUrl: window.location.toString()
296
- }));
297
- expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, "", clientArgs.loginPage);
298
- }
299
- });
300
- } else {
301
- it("redirects to multipass", async () => {
302
- const tokenPromise = client();
303
- expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);
304
- if (should.redirectToLoginPage) {
305
- // expect save local
306
- await expect(tokenPromise).resolves.toBeUndefined();
307
- expect(mockSessionStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({
308
- oldUrl: window.location.toString()
309
- }));
310
- expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, "", clientArgs.loginPage);
311
- return;
312
- }
313
- await expectRedirectToMultipass(tokenPromise);
314
- });
315
- }
316
- }
317
- if (initialState.sessionStorage.codeVerifier) {
318
- it("tries to auth with return results", async () => {
319
- await expect(client()).resolves.toEqual(ACCESS_TOKEN);
320
- expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);
321
- expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined,
322
- // this is only because we didn't mock out the internals
323
- "signIn");
324
- expect(mockWindow.history.replaceState).toHaveBeenCalledTimes(1);
325
- expect(mockWindow.history.replaceState).toBeCalledWith(expect.anything(), expect.anything(), initialState.sessionStorage.oldUrl);
326
- });
327
- }
328
- if (initialState.localStorage.refresh_token) {
329
- it("refreshes", async () => {
330
- await expect(client()).resolves.toEqual(ACCESS_TOKEN);
331
- expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);
332
- expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined,
333
- // this is only because we didn't mock out the internals
334
- "refresh");
335
- });
336
- }
337
- });
338
- });
339
- describe("tokenStorage option", () => {
340
- beforeEach(() => {
341
- setupWindowLocation("https://foundry.local");
342
- setupLocalState({});
343
- vi.mocked(commonJs.readSession).mockImplementation(() => ({}));
344
- // getStorage() checks process.env.TARGET to determine if we're in a browser
345
- vi.stubGlobal("process", {
346
- env: {
347
- TARGET: "browser"
348
- }
349
- });
350
- });
351
- afterEach(() => {
352
- vi.unstubAllGlobals();
353
- // Re-stub the globals that the outer describe needs
354
- vi.stubGlobal("window", mockWindow);
355
- vi.stubGlobal("localStorage", mockLocalStorage);
356
- vi.stubGlobal("sessionStorage", mockSessionStorage);
357
- });
358
- it("should pass localStorage to common when tokenStorage is 'localStorage'", () => {
359
- createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl, {
360
- tokenStorage: "localStorage"
361
- });
362
-
363
- // common() is called with 8 args, the last one being the storage
364
- const lastArg = vi.mocked(commonJs.common).mock.calls[0][7];
365
- expect(lastArg).toBe(mockLocalStorage);
366
- });
367
- it("should pass sessionStorage to common when tokenStorage is 'sessionStorage'", () => {
368
- createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl, {
369
- tokenStorage: "sessionStorage"
370
- });
371
- const lastArg = vi.mocked(commonJs.common).mock.calls[0][7];
372
- expect(lastArg).toBe(mockSessionStorage);
373
- });
374
- it("should pass undefined to common when tokenStorage is 'none'", () => {
375
- createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl, {
376
- tokenStorage: "none"
377
- });
378
- const lastArg = vi.mocked(commonJs.common).mock.calls[0][7];
379
- expect(lastArg).toBeUndefined();
380
- });
381
- it("should not include offline_access scope when tokenStorage is 'none'", async () => {
382
- const client = createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl, {
383
- tokenStorage: "none"
384
- });
385
-
386
- // Trigger the auth flow - this should redirect to multipass
387
- await expect(client()).rejects.toThrowError("Unable to redirect");
388
- expect(mockWindow.location.assign).toHaveBeenCalledOnce();
389
- const url = new URL(mockWindow.location.assign.mock.calls[0][0]);
390
- const scope = url.searchParams.get("scope");
391
-
392
- // Should NOT include offline_access
393
- expect(scope).not.toContain("offline_access");
394
- // Should still include the regular scopes
395
- expect(scope).toContain("api:read-data");
396
- });
397
- it("should pass localStorage to common when tokenStorage is not provided", () => {
398
- createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl);
399
- const lastArg = vi.mocked(commonJs.common).mock.calls[0][7];
400
- expect(lastArg).toBe(mockLocalStorage);
401
- });
402
- it("should include offline_access scope when tokenStorage is 'localStorage'", async () => {
403
- const client = createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl, {
404
- tokenStorage: "localStorage"
405
- });
406
- await expect(client()).rejects.toThrowError("Unable to redirect");
407
- const url = new URL(mockWindow.location.assign.mock.calls[0][0]);
408
- const scope = url.searchParams.get("scope");
409
- expect(scope).toContain("offline_access");
410
- });
411
- it("should include offline_access scope when tokenStorage is 'sessionStorage'", async () => {
412
- const client = createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl, {
413
- tokenStorage: "sessionStorage"
414
- });
415
- await expect(client()).rejects.toThrowError("Unable to redirect");
416
- const url = new URL(mockWindow.location.assign.mock.calls[0][0]);
417
- const scope = url.searchParams.get("scope");
418
- expect(scope).toContain("offline_access");
419
- });
420
- it("should not attempt to read from storage when tokenStorage is 'none'", async () => {
421
- vi.mocked(commonJs.readLocal).mockClear();
422
- const client = createPublicOauthClient(BASE_CLIENT_ARGS.clientId, BASE_CLIENT_ARGS.foundryUrl, BASE_CLIENT_ARGS.redirectUrl, {
423
- tokenStorage: "none"
424
- });
425
- await expect(client()).rejects.toThrowError("Unable to redirect");
426
- expect(vi.mocked(commonJs.readLocal)).not.toHaveBeenCalled();
427
- });
428
- });
429
- });
430
- //# sourceMappingURL=publicOauth.test.js.map