@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.
Files changed (56) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/build/browser/AuthorizationServer.test.d.ts +2 -0
  3. package/build/browser/AuthorizationServer.test.d.ts.map +1 -0
  4. package/build/browser/AuthorizationServer.test.js +45 -0
  5. package/build/browser/AuthorizationServer.test.js.map +1 -0
  6. package/build/browser/__tests__/createPublicOauthClient.test.d.ts +2 -0
  7. package/build/browser/__tests__/createPublicOauthClient.test.d.ts.map +1 -0
  8. package/build/browser/__tests__/createPublicOauthClient.test.js +56 -0
  9. package/build/browser/__tests__/createPublicOauthClient.test.js.map +1 -0
  10. package/build/browser/common.d.ts +1 -2
  11. package/build/browser/common.d.ts.map +1 -1
  12. package/build/browser/common.js +3 -4
  13. package/build/browser/common.js.map +1 -1
  14. package/build/browser/createConfidentialOauthClient.d.ts.map +1 -1
  15. package/build/browser/createConfidentialOauthClient.js +1 -1
  16. package/build/browser/createConfidentialOauthClient.js.map +1 -1
  17. package/build/browser/createPublicOauthClient.d.ts +48 -10
  18. package/build/browser/createPublicOauthClient.d.ts.map +1 -1
  19. package/build/browser/createPublicOauthClient.js +19 -23
  20. package/build/browser/createPublicOauthClient.js.map +1 -1
  21. package/build/browser/publicOauth.test.d.ts +2 -0
  22. package/build/browser/publicOauth.test.d.ts.map +1 -0
  23. package/build/browser/publicOauth.test.js +242 -0
  24. package/build/browser/publicOauth.test.js.map +1 -0
  25. package/build/browser/utils.d.ts +6 -0
  26. package/build/browser/utils.d.ts.map +1 -0
  27. package/build/browser/utils.js +44 -0
  28. package/build/browser/utils.js.map +1 -0
  29. package/build/esm/AuthorizationServer.test.d.ts +2 -0
  30. package/build/esm/AuthorizationServer.test.d.ts.map +1 -0
  31. package/build/esm/AuthorizationServer.test.js +45 -0
  32. package/build/esm/AuthorizationServer.test.js.map +1 -0
  33. package/build/esm/__tests__/createPublicOauthClient.test.d.ts +2 -0
  34. package/build/esm/__tests__/createPublicOauthClient.test.d.ts.map +1 -0
  35. package/build/esm/__tests__/createPublicOauthClient.test.js +56 -0
  36. package/build/esm/__tests__/createPublicOauthClient.test.js.map +1 -0
  37. package/build/esm/common.d.ts +1 -2
  38. package/build/esm/common.d.ts.map +1 -1
  39. package/build/esm/common.js +3 -4
  40. package/build/esm/common.js.map +1 -1
  41. package/build/esm/createConfidentialOauthClient.d.ts.map +1 -1
  42. package/build/esm/createConfidentialOauthClient.js +1 -1
  43. package/build/esm/createConfidentialOauthClient.js.map +1 -1
  44. package/build/esm/createPublicOauthClient.d.ts +48 -10
  45. package/build/esm/createPublicOauthClient.d.ts.map +1 -1
  46. package/build/esm/createPublicOauthClient.js +19 -23
  47. package/build/esm/createPublicOauthClient.js.map +1 -1
  48. package/build/esm/publicOauth.test.d.ts +2 -0
  49. package/build/esm/publicOauth.test.d.ts.map +1 -0
  50. package/build/esm/publicOauth.test.js +242 -0
  51. package/build/esm/publicOauth.test.js.map +1 -0
  52. package/build/esm/utils.d.ts +6 -0
  53. package/build/esm/utils.d.ts.map +1 -0
  54. package/build/esm/utils.js +44 -0
  55. package/build/esm/utils.js.map +1 -0
  56. package/package.json +3 -3
@@ -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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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":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=AuthorizationServer.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthorizationServer.test.d.ts","sourceRoot":"","sources":["../../src/AuthorizationServer.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,45 @@
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 { describe, expect, it } from "vitest";
17
+ import { createAuthorizationServer } from "./common.js";
18
+ describe("Create authorization server", () => {
19
+ it("works with old multipass ctx path", () => {
20
+ const authServer = createAuthorizationServer("/multipass", "https://stack.palantir.com");
21
+ expect(authServer).toEqual({
22
+ token_endpoint: "https://stack.palantir.com/multipass/api/oauth2/token",
23
+ authorization_endpoint: "https://stack.palantir.com/multipass/api/oauth2/authorize",
24
+ revocation_endpoint: "https://stack.palantir.com/multipass/api/oauth2/revoke_token",
25
+ issuer: "https://stack.palantir.com/multipass"
26
+ });
27
+ });
28
+ it("works with new multipass ctx path", () => {
29
+ const authServer = createAuthorizationServer("multipass", "https://stack.palantir.com");
30
+ expect(authServer).toEqual({
31
+ token_endpoint: "https://stack.palantir.com/multipass/api/oauth2/token",
32
+ authorization_endpoint: "https://stack.palantir.com/multipass/api/oauth2/authorize",
33
+ revocation_endpoint: "https://stack.palantir.com/multipass/api/oauth2/revoke_token",
34
+ issuer: "https://stack.palantir.com/multipass"
35
+ });
36
+ const authServerCustom = createAuthorizationServer("multipass", "https://stack.palantir.com/foo/first/someStuff");
37
+ expect(authServerCustom).toEqual({
38
+ token_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token",
39
+ authorization_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize",
40
+ revocation_endpoint: "https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token",
41
+ issuer: "https://stack.palantir.com/foo/first/someStuff/multipass"
42
+ });
43
+ });
44
+ });
45
+ //# sourceMappingURL=AuthorizationServer.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthorizationServer.test.js","names":["describe","expect","it","createAuthorizationServer","authServer","toEqual","token_endpoint","authorization_endpoint","revocation_endpoint","issuer","authServerCustom"],"sources":["AuthorizationServer.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 */\nimport { describe, expect, it, } from \"vitest\";\nimport { createAuthorizationServer } from \"./common.js\";\ndescribe(\"Create authorization server\", () => {\n it(\"works with old multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\"/multipass\", \"https://stack.palantir.com\");\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n });\n it(\"works with new multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\"multipass\", \"https://stack.palantir.com\");\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n const authServerCustom = createAuthorizationServer(\"multipass\", \"https://stack.palantir.com/foo/first/someStuff\");\n expect(authServerCustom).toEqual({\n token_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/foo/first/someStuff/multipass\",\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAS,QAAQ;AAC9C,SAASC,yBAAyB,QAAQ,aAAa;AACvDH,QAAQ,CAAC,6BAA6B,EAAE,MAAM;EAC1CE,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC1C,MAAME,UAAU,GAAGD,yBAAyB,CAAC,YAAY,EAAE,4BAA4B,CAAC;IACxFF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACvBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EAAE,2DAA2D;MACnFC,mBAAmB,EAAE,8DAA8D;MACnFC,MAAM,EAAE;IACZ,CAAC,CAAC;EACN,CAAC,CAAC;EACFP,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC1C,MAAME,UAAU,GAAGD,yBAAyB,CAAC,WAAW,EAAE,4BAA4B,CAAC;IACvFF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACvBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EAAE,2DAA2D;MACnFC,mBAAmB,EAAE,8DAA8D;MACnFC,MAAM,EAAE;IACZ,CAAC,CAAC;IACF,MAAMC,gBAAgB,GAAGP,yBAAyB,CAAC,WAAW,EAAE,gDAAgD,CAAC;IACjHF,MAAM,CAACS,gBAAgB,CAAC,CAACL,OAAO,CAAC;MAC7BC,cAAc,EAAE,2EAA2E;MAC3FC,sBAAsB,EAAE,+EAA+E;MACvGC,mBAAmB,EAAE,kFAAkF;MACvGC,MAAM,EAAE;IACZ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=createPublicOauthClient.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPublicOauthClient.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/createPublicOauthClient.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,56 @@
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 { createPublicOauthClient } from "@osdk/oauth";
17
+ import * as oauthModule from "@osdk/oauth";
18
+ import { describe, expect, it, vi } from "vitest";
19
+ import * as utilsModule from "../utils.js";
20
+ const originalCreatePublicOauthClient = oauthModule.createPublicOauthClient;
21
+ const FOUNDRY_CLIENT_ID = "example-foundry-client-id";
22
+ const FOUNDRY_URL = "http://example-foundry-url.com";
23
+ const REDIRECT_URI = "http://localhost:8080/auth/callback";
24
+ vi.stubGlobal("window", {
25
+ location: {
26
+ toString: vi.fn().mockReturnValue("http://example.com")
27
+ }
28
+ });
29
+ describe("createPublicOauthClient", () => {
30
+ it("should return the same processed options for both client creation methods", async () => {
31
+ const mockProcessOptionsAndAssignDefaults = vi.fn();
32
+ // Mock processOptionsAndAssignDefaults to call the mock function
33
+ vi.spyOn(utilsModule, "processOptionsAndAssignDefaults").mockImplementation((...args) => {
34
+ mockProcessOptionsAndAssignDefaults(...args);
35
+ return utilsModule.processOptionsAndAssignDefaults(...args);
36
+ });
37
+ // Mock createPublicOauthClient to call both the mock and the original function
38
+ vi.spyOn(oauthModule, "createPublicOauthClient").mockImplementation((...args) => {
39
+ const [_client_id, ...rest] = args;
40
+ mockProcessOptionsAndAssignDefaults(...rest);
41
+ return originalCreatePublicOauthClient(...args);
42
+ });
43
+ const authClient = createPublicOauthClient(FOUNDRY_CLIENT_ID, FOUNDRY_URL, REDIRECT_URI, true, undefined, undefined, undefined, fetch, undefined);
44
+ expect(authClient).toBeDefined();
45
+ expect(mockProcessOptionsAndAssignDefaults).toHaveBeenCalledTimes(1);
46
+ const authClientWithOptions = createPublicOauthClient(FOUNDRY_CLIENT_ID, FOUNDRY_URL, REDIRECT_URI, {
47
+ useHistory: true,
48
+ fetchFn: fetch
49
+ });
50
+ expect(authClientWithOptions).toBeDefined();
51
+ expect(mockProcessOptionsAndAssignDefaults).toHaveBeenCalledTimes(2);
52
+ const [result1, result2] = mockProcessOptionsAndAssignDefaults.mock.results;
53
+ expect(result1.value).toEqual(result2.value);
54
+ });
55
+ });
56
+ //# sourceMappingURL=createPublicOauthClient.test.js.map
@@ -0,0 +1 @@
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.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 { createPublicOauthClient } from \"@osdk/oauth\";\nimport * as oauthModule from \"@osdk/oauth\";\nimport { describe, expect, it, vi } from \"vitest\";\nimport * as utilsModule from \"../utils.js\";\nconst originalCreatePublicOauthClient = oauthModule.createPublicOauthClient;\nconst FOUNDRY_CLIENT_ID = \"example-foundry-client-id\";\nconst FOUNDRY_URL = \"http://example-foundry-url.com\";\nconst REDIRECT_URI = \"http://localhost:8080/auth/callback\";\nvi.stubGlobal(\"window\", {\n location: {\n toString: vi.fn().mockReturnValue(\"http://example.com\"),\n },\n});\ndescribe(\"createPublicOauthClient\", () => {\n it(\"should return the same processed options for both client creation methods\", async () => {\n const mockProcessOptionsAndAssignDefaults = vi.fn();\n // Mock processOptionsAndAssignDefaults to call the mock function\n vi.spyOn(utilsModule, \"processOptionsAndAssignDefaults\").mockImplementation((...args) => {\n mockProcessOptionsAndAssignDefaults(...args);\n return utilsModule.processOptionsAndAssignDefaults(...args);\n });\n // Mock createPublicOauthClient to call both the mock and the original function\n vi.spyOn(oauthModule, \"createPublicOauthClient\").mockImplementation((...args) => {\n const [_client_id, ...rest] = args;\n mockProcessOptionsAndAssignDefaults(...rest);\n return originalCreatePublicOauthClient(...args);\n });\n const authClient = createPublicOauthClient(FOUNDRY_CLIENT_ID, FOUNDRY_URL, REDIRECT_URI, true, undefined, undefined, undefined, fetch, undefined);\n expect(authClient).toBeDefined();\n expect(mockProcessOptionsAndAssignDefaults).toHaveBeenCalledTimes(1);\n const authClientWithOptions = createPublicOauthClient(FOUNDRY_CLIENT_ID, FOUNDRY_URL, REDIRECT_URI, {\n useHistory: true,\n fetchFn: fetch,\n });\n expect(authClientWithOptions).toBeDefined();\n expect(mockProcessOptionsAndAssignDefaults).toHaveBeenCalledTimes(2);\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;AACA,SAASA,uBAAuB,QAAQ,aAAa;AACrD,OAAO,KAAKC,WAAW,MAAM,aAAa;AAC1C,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QA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CAAC;IAChCvB,MAAM,CAACa,mCAAmC,CAAC,CAACW,qBAAqB,CAAC,CAAC,CAAC;IACpE,MAAMC,qBAAqB,GAAG5B,uBAAuB,CAACQ,iBAAiB,EAAEC,WAAW,EAAEC,YAAY,EAAE;MAChGmB,UAAU,EAAE,IAAI;MAChBC,OAAO,EAAEL;IACb,CAAC,CAAC;IACFtB,MAAM,CAACyB,qBAAqB,CAAC,CAACF,WAAW,CAAC,CAAC;IAC3CvB,MAAM,CAACa,mCAAmC,CAAC,CAACW,qBAAqB,CAAC,CAAC,CAAC;IACpE,MAAM,CAACI,OAAO,EAAEC,OAAO,CAAC,GAAGhB,mCAAmC,CAACiB,IAAI,CAACC,OAAO;IAC3E/B,MAAM,CAAC4B,OAAO,CAACI,KAAK,CAAC,CAACC,OAAO,CAACJ,OAAO,CAACG,KAAK,CAAC;EAChD,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
@@ -1,7 +1,7 @@
1
1
  import type { AuthorizationServer, Client, HttpRequestOptions, OAuth2TokenEndpointResponse } from "oauth4webapi";
2
2
  import type { BaseOauthClient, Events } from "./BaseOauthClient.js";
3
3
  import type { Token } from "./Token.js";
4
- type LocalStorageState = {
4
+ export type LocalStorageState = {
5
5
  refresh_token?: never;
6
6
  codeVerifier?: never;
7
7
  state?: never;
@@ -32,5 +32,4 @@ export declare function common<R extends undefined | (() => Promise<Token | unde
32
32
  makeTokenAndSaveRefresh: (resp: OAuth2TokenEndpointResponse, type: "signIn" | "refresh") => Token;
33
33
  };
34
34
  export declare function createAuthorizationServer(ctxPath: string, url: string): Required<Pick<AuthorizationServer, "issuer" | "token_endpoint" | "authorization_endpoint" | "revocation_endpoint">>;
35
- export {};
36
35
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,mBAAmB,EACnB,MAAM,EACN,kBAAkB,EAClB,2B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IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB,CAAC;AAEJ,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,iBAAiB,QAM7D;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,QAKzC;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAQ3D;AAED,wBAAgB,MAAM,CACpB,CAAC,SAAS,SAAS,GAAG,CAAC,MAAM,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,EAExD,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,mBAAmB,EACvB,OAAO,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,EAC7B,gBAAgB,EAAE,kBAAkB,EACpC,OAAO,EAAE,CAAC,GACT;IACD,QAAQ,EAAE,eAAe,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC,CAAA;KAAE,CAAC;IAClE,uBAAuB,EAAE,CACvB,IAAI,EAAE,2BAA2B,EACjC,IAAI,EAAE,QAAQ,GAAG,SAAS,KACvB,KAAK,CAAC;CACZ,CA0GA;AAED,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,GACV,QAAQ,CACT,IAAI,CACF,mBAAmB,EACjB,QAAQ,GACR,gBAAgB,GAChB,wBAAwB,GACxB,qBAAqB,CACxB,CACF,CAQA"}
@@ -29,19 +29,18 @@ const CustomEvent = globalThis.CustomEvent ?? class extends Event {
29
29
  return this.#detail;
30
30
  }
31
31
  };
32
- const localStorage = globalThis.localStorage;
33
32
  export function saveLocal(client, x) {
34
33
  // MUST `localStorage?` as nodejs does not have localStorage
35
- localStorage?.setItem(`@osdk/oauth : refresh : ${client.client_id}`, JSON.stringify(x));
34
+ globalThis.localStorage?.setItem(`@osdk/oauth : refresh : ${client.client_id}`, JSON.stringify(x));
36
35
  }
37
36
  export function removeLocal(client) {
38
37
  // MUST `localStorage?` as nodejs does not have localStorage
39
- localStorage?.removeItem(`@osdk/oauth : refresh : ${client.client_id}`);
38
+ globalThis.localStorage?.removeItem(`@osdk/oauth : refresh : ${client.client_id}`);
40
39
  }
41
40
  export function readLocal(client) {
42
41
  return JSON.parse(
43
42
  // MUST `localStorage?` as nodejs does not have localStorage
44
- localStorage?.getItem(`@osdk/oauth : refresh : ${client.client_id}`) ?? "{}");
43
+ globalThis.localStorage?.getItem(`@osdk/oauth : refresh : ${client.client_id}`) ?? "{}");
45
44
  }
46
45
  export function common(client, as, _signIn, oauthHttpOptions, refresh) {
47
46
  let token;
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","names":["processRevocationResponse","revocationRequest","invariant","TypedEventTarget","throwIfError","CustomEvent","globalThis","Event","detail","constructor","type","options","localStorage","saveLocal","client","x","setItem","client_id","JSON","stringify","removeLocal","removeItem","readLocal","parse","getItem","common","as","_signIn","oauthHttpOptions","refresh","token","eventTarget","makeTokenAndSaveRefresh","resp","refresh_token","expires_in","access_token","process","env","NODE_ENV","expires_at","Date","now","dispatchTypedEvent","refreshTimeout","rmTimeout","clearTimeout","restartRefreshTimer","evt","setTimeout","pendingSignIn","signIn","undefined","addEventListener","getTokenOrUndefined","getToken","Object","assign","signOut","result","bind","removeEventListener","createAuthorizationServer","ctxPath","url","issuer","URL","token_endpoint","authorization_endpoint","revocation_endpoint"],"sources":["common.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 { processRevocationResponse, revocationRequest } from \"oauth4webapi\";\nimport invariant from \"tiny-invariant\";\nimport { TypedEventTarget } from \"typescript-event-target\";\nimport { throwIfError } from \"./throwIfError.js\";\n// Node 18 is supposed to have a `CustomEvent` but it is not exposed on `globalThis`\n// which creates a problem for making a single codebase for node and browser. This polyfill works around it\nconst CustomEvent = process.env.TARGET === \"browser\"\n ? globalThis.CustomEvent\n : globalThis.CustomEvent\n ?? class CustomEvent extends Event {\n #detail;\n constructor(type, options) {\n super(type, options);\n this.#detail = options?.detail ?? null;\n }\n get detail() {\n return this.#detail;\n }\n };\nconst localStorage = globalThis.localStorage;\nexport function saveLocal(client, x) {\n // MUST `localStorage?` as nodejs does not have localStorage\n localStorage?.setItem(`@osdk/oauth : refresh : ${client.client_id}`, JSON.stringify(x));\n}\nexport function removeLocal(client) {\n // MUST `localStorage?` as nodejs does not have localStorage\n localStorage?.removeItem(`@osdk/oauth : refresh : ${client.client_id}`);\n}\nexport function readLocal(client) {\n return JSON.parse(\n // MUST `localStorage?` as nodejs does not have localStorage\n localStorage?.getItem(`@osdk/oauth : refresh : ${client.client_id}`)\n ?? \"{}\");\n}\nexport function common(client, as, _signIn, oauthHttpOptions, refresh) {\n let token;\n const eventTarget = new TypedEventTarget();\n function makeTokenAndSaveRefresh(resp, type) {\n const { refresh_token, expires_in, access_token } = resp;\n invariant(expires_in != null);\n saveLocal(client, { refresh_token });\n token = {\n refresh_token,\n expires_in,\n access_token,\n expires_at: Date.now() + expires_in * 1000,\n };\n eventTarget.dispatchTypedEvent(type, new CustomEvent(type, { detail: token }));\n return token;\n }\n let refreshTimeout;\n function rmTimeout() {\n if (refreshTimeout)\n clearTimeout(refreshTimeout);\n }\n function restartRefreshTimer(evt) {\n if (refresh) {\n rmTimeout();\n refreshTimeout = setTimeout(refresh, evt.detail.expires_in * 1000 - 60 * 1000);\n }\n }\n async function signOut() {\n invariant(token, \"not signed in\");\n const result = await processRevocationResponse(await revocationRequest(as, client, token.access_token, oauthHttpOptions));\n rmTimeout();\n // Clean up\n removeLocal(client);\n token = undefined;\n throwIfError(result);\n eventTarget.dispatchTypedEvent(\"signOut\", new Event(\"signOut\"));\n }\n let pendingSignIn;\n async function signIn() {\n if (pendingSignIn) {\n return pendingSignIn;\n }\n try {\n pendingSignIn = _signIn();\n return await pendingSignIn;\n }\n finally {\n pendingSignIn = undefined;\n }\n }\n eventTarget.addEventListener(\"signIn\", restartRefreshTimer);\n eventTarget.addEventListener(\"refresh\", restartRefreshTimer);\n function getTokenOrUndefined() {\n if (!token || Date.now() >= token.expires_at) {\n return undefined;\n }\n return token?.access_token;\n }\n const getToken = Object.assign(async function getToken() {\n if (!token || Date.now() >= token.expires_at) {\n token = await signIn();\n }\n return token?.access_token;\n }, {\n signIn,\n refresh,\n signOut,\n rmTimeout,\n getTokenOrUndefined,\n addEventListener: eventTarget.addEventListener.bind(eventTarget),\n removeEventListener: eventTarget.removeEventListener.bind(eventTarget),\n });\n return { getToken, makeTokenAndSaveRefresh };\n}\nexport function createAuthorizationServer(ctxPath, url) {\n const issuer = `${new URL(ctxPath, url)}`;\n return {\n token_endpoint: `${issuer}/api/oauth2/token`,\n authorization_endpoint: `${issuer}/api/oauth2/authorize`,\n revocation_endpoint: `${issuer}/api/oauth2/revoke_token`,\n issuer,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,yBAAyB,EAAEC,iBAAiB,QAAQ,cAAc;AAC3E,OAAOC,SAAS,MAAM,gBAAgB;AACtC,SAASC,gBAAgB,QAAQ,yBAAyB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAChD;AACA;AACA,MAAMC,WAAW,GAEXC,UAAU,CAACD,WAAW,IACjB,cAA0BE,KAAK,CAAC;EAC/B,CAACC,MAAM;EACPC,WAAWA,CAACC,IAAI,EAAEC,OAAO,EAAE;IACvB,KAAK,CAACD,IAAI,EAAEC,OAAO,CAAC;IACpB,IAAI,C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[]}
1
+ {"version":3,"file":"common.js","names":["processRevocationResponse","revocationRequest","invariant","TypedEventTarget","throwIfError","CustomEvent","globalThis","Event","detail","constructor","type","options","saveLocal","client","x","localStorage","setItem","client_id","JSON","stringify","removeLocal","removeItem","readLocal","parse","getItem","common","as","_signIn","oauthHttpOptions","refresh","token","eventTarget","makeTokenAndSaveRefresh","resp","refresh_token","expires_in","access_token","process","env","NODE_ENV","expires_at","Date","now","dispatchTypedEvent","refreshTimeout","rmTimeout","clearTimeout","restartRefreshTimer","evt","setTimeout","pendingSignIn","signIn","undefined","addEventListener","getTokenOrUndefined","getToken","Object","assign","signOut","result","bind","removeEventListener","createAuthorizationServer","ctxPath","url","issuer","URL","token_endpoint","authorization_endpoint","revocation_endpoint"],"sources":["common.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 { processRevocationResponse, revocationRequest } from \"oauth4webapi\";\nimport invariant from \"tiny-invariant\";\nimport { TypedEventTarget } from \"typescript-event-target\";\nimport { throwIfError } from \"./throwIfError.js\";\n// Node 18 is supposed to have a `CustomEvent` but it is not exposed on `globalThis`\n// which creates a problem for making a single codebase for node and browser. This polyfill works around it\nconst CustomEvent = process.env.TARGET === \"browser\"\n ? globalThis.CustomEvent\n : globalThis.CustomEvent\n ?? class CustomEvent extends Event {\n #detail;\n constructor(type, options) {\n super(type, options);\n this.#detail = options?.detail ?? null;\n }\n get detail() {\n return this.#detail;\n }\n };\nexport function saveLocal(client, x) {\n // MUST `localStorage?` as nodejs does not have localStorage\n globalThis.localStorage?.setItem(`@osdk/oauth : refresh : ${client.client_id}`, JSON.stringify(x));\n}\nexport function removeLocal(client) {\n // MUST `localStorage?` as nodejs does not have localStorage\n globalThis.localStorage?.removeItem(`@osdk/oauth : refresh : ${client.client_id}`);\n}\nexport function readLocal(client) {\n return JSON.parse(\n // MUST `localStorage?` as nodejs does not have localStorage\n globalThis.localStorage?.getItem(`@osdk/oauth : refresh : ${client.client_id}`)\n ?? \"{}\");\n}\nexport function common(client, as, _signIn, oauthHttpOptions, refresh) {\n let token;\n const eventTarget = new TypedEventTarget();\n function makeTokenAndSaveRefresh(resp, type) {\n const { refresh_token, expires_in, access_token } = resp;\n invariant(expires_in != null);\n saveLocal(client, { refresh_token });\n token = {\n refresh_token,\n expires_in,\n access_token,\n expires_at: Date.now() + expires_in * 1000,\n };\n eventTarget.dispatchTypedEvent(type, new CustomEvent(type, { detail: token }));\n return token;\n }\n let refreshTimeout;\n function rmTimeout() {\n if (refreshTimeout)\n clearTimeout(refreshTimeout);\n }\n function restartRefreshTimer(evt) {\n if (refresh) {\n rmTimeout();\n refreshTimeout = setTimeout(refresh, evt.detail.expires_in * 1000 - 60 * 1000);\n }\n }\n async function signOut() {\n invariant(token, \"not signed in\");\n const result = await processRevocationResponse(await revocationRequest(as, client, token.access_token, oauthHttpOptions));\n rmTimeout();\n // Clean up\n removeLocal(client);\n token = undefined;\n throwIfError(result);\n eventTarget.dispatchTypedEvent(\"signOut\", new Event(\"signOut\"));\n }\n let pendingSignIn;\n async function signIn() {\n if (pendingSignIn) {\n return pendingSignIn;\n }\n try {\n pendingSignIn = _signIn();\n return await pendingSignIn;\n }\n finally {\n pendingSignIn = undefined;\n }\n }\n eventTarget.addEventListener(\"signIn\", restartRefreshTimer);\n eventTarget.addEventListener(\"refresh\", restartRefreshTimer);\n function getTokenOrUndefined() {\n if (!token || Date.now() >= token.expires_at) {\n return undefined;\n }\n return token?.access_token;\n }\n const getToken = Object.assign(async function getToken() {\n if (!token || Date.now() >= token.expires_at) {\n token = await signIn();\n }\n return token?.access_token;\n }, {\n signIn,\n refresh,\n signOut,\n rmTimeout,\n getTokenOrUndefined,\n addEventListener: eventTarget.addEventListener.bind(eventTarget),\n removeEventListener: eventTarget.removeEventListener.bind(eventTarget),\n });\n return { getToken, makeTokenAndSaveRefresh };\n}\nexport function createAuthorizationServer(ctxPath, url) {\n const issuer = `${new URL(ctxPath, url)}`;\n return {\n token_endpoint: `${issuer}/api/oauth2/token`,\n authorization_endpoint: `${issuer}/api/oauth2/authorize`,\n revocation_endpoint: `${issuer}/api/oauth2/revoke_token`,\n issuer,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,yBAAyB,EAAEC,iBAAiB,QAAQ,cAAc;AAC3E,OAAOC,SAAS,MAAM,gBAAgB;AACtC,SAASC,gBAAgB,QAAQ,yBAAyB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAChD;AACA;AACA,MAAMC,WAAW,GAEXC,UAAU,CAACD,WAAW,IACjB,cAA0BE,KAAK,CAAC;EAC/B,CAACC,MAAM;EACPC,WAAWA,CAACC,IAAI,EAAEC,OAAO,EAAE;IACvB,KAAK,CAACD,IAAI,EAAEC,OAAO,CAAC;IACpB,IAAI,CAAC,CAACH,MAAM,GAAGG,OAAO,EAAEH,MAAM,IAAI,IAAI;EAC1C;EACA,IAAIA,MAAMA,CAAA,EAAG;IACT,OAAO,IAAI,CAAC,CAACA,MAAM;EACvB;AACJ,CAAC;AACT,OAAO,SAASI,SAASA,CAACC,MAAM,EAAEC,CAAC,EAAE;EACjC;EACAR,UAAU,CAACS,YAAY,EAAEC,OAAO,CAAC,2BAA2BH,MAAM,CAACI,SAAS,EAAE,EAAEC,IAAI,CAACC,SAAS,CAACL,CAAC,CAAC,CAAC;AACtG;AACA,OAAO,SAASM,WAAWA,CAACP,MAAM,EAAE;EAChC;EACAP,UAAU,CAACS,YAAY,EAAEM,UAAU,CAAC,2BA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B,SAAS,CAAC,CAAC;MACX;MACAzB,WAAW,CAACP,MAAM,CAAC;MACnBiB,KAAK,GAAGsB,SAAS;MACjBhD,YAAY,CAACuD,MAAM,CAAC;MACpB5B,WAAW,CAACY,kBAAkB,CAAC,SAAS,EAAE,IAAIpC,KAAK,CAAC,SAAS,CAAC,CAAC;IACnE,CA8BW;IACPsC,SAAS;IACTS,mBAAmB;IACnBD,gBAAgB,EAAEtB,WAAW,CAACsB,gBAAgB,CAACO,IAAI,CAAC7B,WAAW,CAAC;IAChE8B,mBAAmB,EAAE9B,WAAW,CAAC8B,mBAAmB,CAACD,IAAI,CAAC7B,WAAW;EACzE,CAAC,CAAC;EACF,OAAO;IAAEwB,QAAQ;IAAEvB;EAAwB,CAAC;AAChD;AACA,OAAO,SAAS8B,yBAAyBA,CAACC,OAAO,EAAEC,GAAG,EAAE;EACpD,MAAMC,MAAM,GAAG,GAAG,IAAIC,GAAG,CAACH,OAAO,EAAEC,GAAG,CAAC,EAAE;EACzC,OAAO;IACHG,cAAc,EAAE,GAAGF,MAAM,mBAAmB;IAC5CG,sBAAsB,EAAE,GAAGH,MAAM,uBAAuB;IACxDI,mBAAmB,EAAE,GAAGJ,MAAM,0BAA0B;IACxDA;EACJ,CAAC;AACL","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"createConfidentialOauthClient.d.ts","sourceRoot":"","sources":["../../src/createConfidentialOauthClient.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAG5E;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,MAAM,EAAwC,EACtD,OAAO,GAAE,OAAO,UAAU,CAAC,KAAwB,EACnD,OAAO,GAAE,MAAqB,GAC7B,uBAAuB,CAgCzB"}
1
+ {"version":3,"file":"createConfidentialOauthClient.d.ts","sourceRoot":"","sources":["../../src/createConfidentialOauthClient.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAG5E;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,MAAM,EAAwC,EACtD,OAAO,GAAE,OAAO,UAAU,CAAC,KAAwB,EACnD,OAAO,GAAE,MAAoB,GAC5B,uBAAuB,CAgCzB"}
@@ -25,7 +25,7 @@ import { throwIfError } from "./throwIfError.js";
25
25
  * @param ctxPath
26
26
  * @returns which can be used as a token provider
27
27
  */
28
- export function createConfidentialOauthClient(client_id, client_secret, url, scopes = ["api:read-data", "api:write-data"], fetchFn = globalThis.fetch, ctxPath = "/multipass") {
28
+ export function createConfidentialOauthClient(client_id, client_secret, url, scopes = ["api:read-data", "api:write-data"], fetchFn = globalThis.fetch, ctxPath = "multipass") {
29
29
  const client = {
30
30
  client_id,
31
31
  client_secret