@osdk/oauth 1.1.0-beta.7 → 1.1.0-beta.9

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 (119) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/build/browser/AuthorizationServer.test.js +1 -0
  3. package/build/browser/AuthorizationServer.test.js.map +1 -1
  4. package/build/browser/BaseOauthClient.js +0 -15
  5. package/build/browser/BaseOauthClient.js.map +1 -1
  6. package/build/browser/ConfidentialOauthClient.js +0 -15
  7. package/build/browser/ConfidentialOauthClient.js.map +1 -1
  8. package/build/browser/PublicOauthClient.js +0 -15
  9. package/build/browser/PublicOauthClient.js.map +1 -1
  10. package/build/browser/Token.js +0 -15
  11. package/build/browser/Token.js.map +1 -1
  12. package/build/browser/__tests__/createPublicOauthClient.test.js +3 -0
  13. package/build/browser/__tests__/createPublicOauthClient.test.js.map +1 -1
  14. package/build/browser/common.js +15 -9
  15. package/build/browser/common.js.map +1 -1
  16. package/build/browser/common.test.js +65 -0
  17. package/build/browser/common.test.js.map +1 -0
  18. package/build/browser/createConfidentialOauthClient.js +3 -1
  19. package/build/browser/createConfidentialOauthClient.js.map +1 -1
  20. package/build/browser/createPublicOauthClient.js +37 -4
  21. package/build/browser/createPublicOauthClient.js.map +1 -1
  22. package/build/browser/index.js +1 -0
  23. package/build/browser/index.js.map +1 -1
  24. package/build/browser/publicOauth.test.js +80 -21
  25. package/build/browser/publicOauth.test.js.map +1 -1
  26. package/build/browser/throwIfError.js +1 -0
  27. package/build/browser/throwIfError.js.map +1 -1
  28. package/build/browser/utils.js +4 -1
  29. package/build/browser/utils.js.map +1 -1
  30. package/build/cjs/index.cjs +320 -0
  31. package/build/cjs/index.cjs.map +1 -0
  32. package/build/{browser/createPublicOauthClient.d.ts → cjs/index.d.cts} +48 -5
  33. package/build/esm/AuthorizationServer.test.js +1 -0
  34. package/build/esm/AuthorizationServer.test.js.map +1 -1
  35. package/build/esm/BaseOauthClient.js +0 -15
  36. package/build/esm/BaseOauthClient.js.map +1 -1
  37. package/build/esm/ConfidentialOauthClient.js +0 -15
  38. package/build/esm/ConfidentialOauthClient.js.map +1 -1
  39. package/build/esm/PublicOauthClient.js +0 -15
  40. package/build/esm/PublicOauthClient.js.map +1 -1
  41. package/build/esm/Token.js +0 -15
  42. package/build/esm/Token.js.map +1 -1
  43. package/build/esm/__tests__/createPublicOauthClient.test.js +3 -0
  44. package/build/esm/__tests__/createPublicOauthClient.test.js.map +1 -1
  45. package/build/esm/common.js +15 -9
  46. package/build/esm/common.js.map +1 -1
  47. package/build/esm/common.test.js +65 -0
  48. package/build/esm/common.test.js.map +1 -0
  49. package/build/esm/createConfidentialOauthClient.js +3 -1
  50. package/build/esm/createConfidentialOauthClient.js.map +1 -1
  51. package/build/esm/createPublicOauthClient.js +37 -4
  52. package/build/esm/createPublicOauthClient.js.map +1 -1
  53. package/build/esm/index.js +1 -0
  54. package/build/esm/index.js.map +1 -1
  55. package/build/esm/publicOauth.test.js +80 -21
  56. package/build/esm/publicOauth.test.js.map +1 -1
  57. package/build/esm/throwIfError.js +1 -0
  58. package/build/esm/throwIfError.js.map +1 -1
  59. package/build/esm/utils.js +4 -1
  60. package/build/esm/utils.js.map +1 -1
  61. package/build/types/AuthorizationServer.test.d.ts +1 -0
  62. package/build/types/BaseOauthClient.d.ts +14 -0
  63. package/build/{browser → types}/ConfidentialOauthClient.d.ts +1 -3
  64. package/build/{browser → types}/PublicOauthClient.d.ts +1 -2
  65. package/build/types/Token.d.ts +6 -0
  66. package/build/types/__tests__/createPublicOauthClient.test.d.ts +1 -0
  67. package/build/{browser → types}/common.d.ts +16 -18
  68. package/build/types/common.test.d.ts +1 -0
  69. package/build/{browser → types}/createConfidentialOauthClient.d.ts +8 -9
  70. package/build/types/createPublicOauthClient.d.ts +56 -0
  71. package/build/{browser → types}/index.d.ts +1 -2
  72. package/build/types/publicOauth.test.d.ts +1 -0
  73. package/build/{browser → types}/throwIfError.d.ts +0 -1
  74. package/build/{esm → types}/utils.d.ts +5 -4
  75. package/package.json +22 -8
  76. package/build/browser/AuthorizationServer.test.d.ts +0 -2
  77. package/build/browser/AuthorizationServer.test.d.ts.map +0 -1
  78. package/build/browser/BaseOauthClient.d.ts +0 -15
  79. package/build/browser/BaseOauthClient.d.ts.map +0 -1
  80. package/build/browser/ConfidentialOauthClient.d.ts.map +0 -1
  81. package/build/browser/PublicOauthClient.d.ts.map +0 -1
  82. package/build/browser/Token.d.ts +0 -7
  83. package/build/browser/Token.d.ts.map +0 -1
  84. package/build/browser/__tests__/createPublicOauthClient.test.d.ts +0 -2
  85. package/build/browser/__tests__/createPublicOauthClient.test.d.ts.map +0 -1
  86. package/build/browser/common.d.ts.map +0 -1
  87. package/build/browser/createConfidentialOauthClient.d.ts.map +0 -1
  88. package/build/browser/createPublicOauthClient.d.ts.map +0 -1
  89. package/build/browser/index.d.ts.map +0 -1
  90. package/build/browser/publicOauth.test.d.ts +0 -2
  91. package/build/browser/publicOauth.test.d.ts.map +0 -1
  92. package/build/browser/throwIfError.d.ts.map +0 -1
  93. package/build/browser/utils.d.ts +0 -6
  94. package/build/browser/utils.d.ts.map +0 -1
  95. package/build/esm/AuthorizationServer.test.d.ts +0 -2
  96. package/build/esm/AuthorizationServer.test.d.ts.map +0 -1
  97. package/build/esm/BaseOauthClient.d.ts +0 -15
  98. package/build/esm/BaseOauthClient.d.ts.map +0 -1
  99. package/build/esm/ConfidentialOauthClient.d.ts +0 -4
  100. package/build/esm/ConfidentialOauthClient.d.ts.map +0 -1
  101. package/build/esm/PublicOauthClient.d.ts +0 -6
  102. package/build/esm/PublicOauthClient.d.ts.map +0 -1
  103. package/build/esm/Token.d.ts +0 -7
  104. package/build/esm/Token.d.ts.map +0 -1
  105. package/build/esm/__tests__/createPublicOauthClient.test.d.ts +0 -2
  106. package/build/esm/__tests__/createPublicOauthClient.test.d.ts.map +0 -1
  107. package/build/esm/common.d.ts +0 -33
  108. package/build/esm/common.d.ts.map +0 -1
  109. package/build/esm/createConfidentialOauthClient.d.ts +0 -12
  110. package/build/esm/createConfidentialOauthClient.d.ts.map +0 -1
  111. package/build/esm/createPublicOauthClient.d.ts +0 -53
  112. package/build/esm/createPublicOauthClient.d.ts.map +0 -1
  113. package/build/esm/index.d.ts +0 -4
  114. package/build/esm/index.d.ts.map +0 -1
  115. package/build/esm/publicOauth.test.d.ts +0 -2
  116. package/build/esm/publicOauth.test.d.ts.map +0 -1
  117. package/build/esm/throwIfError.d.ts +0 -6
  118. package/build/esm/throwIfError.d.ts.map +0 -1
  119. package/build/esm/utils.d.ts.map +0 -1
@@ -0,0 +1,320 @@
1
+ 'use strict';
2
+
3
+ var oauth4webapi = require('oauth4webapi');
4
+ var invariant2 = require('tiny-invariant');
5
+ var typescriptEventTarget = require('typescript-event-target');
6
+ var delay = require('delay');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var invariant2__default = /*#__PURE__*/_interopDefault(invariant2);
11
+ var delay__default = /*#__PURE__*/_interopDefault(delay);
12
+
13
+ // src/createConfidentialOauthClient.ts
14
+ function throwIfError(result) {
15
+ if (oauth4webapi.isOAuth2Error(result)) {
16
+ throw new Error(`Failed to get token: ${result.error}`);
17
+ }
18
+ return result;
19
+ }
20
+
21
+ // src/common.ts
22
+ var CustomEvent = globalThis.CustomEvent ?? class CustomEvent2 extends Event {
23
+ #detail;
24
+ constructor(type, options) {
25
+ super(type, options);
26
+ this.#detail = options?.detail ?? null;
27
+ }
28
+ get detail() {
29
+ return this.#detail;
30
+ }
31
+ };
32
+ function localStorageKey(client) {
33
+ return `@osdk/oauth : refresh : ${client.client_id}`;
34
+ }
35
+ function saveLocal(client, x) {
36
+ globalThis.localStorage?.setItem(localStorageKey(client), JSON.stringify(x));
37
+ }
38
+ function removeLocal(client) {
39
+ globalThis.localStorage?.removeItem(localStorageKey(client));
40
+ }
41
+ function readLocal(client) {
42
+ return JSON.parse(
43
+ // MUST `localStorage?` as nodejs does not have localStorage
44
+ globalThis.localStorage?.getItem(localStorageKey(client)) ?? "{}"
45
+ );
46
+ }
47
+ function saveSession(client, x) {
48
+ globalThis.sessionStorage?.setItem(localStorageKey(client), JSON.stringify(x));
49
+ }
50
+ function removeSession(client) {
51
+ globalThis.sessionStorage?.removeItem(localStorageKey(client));
52
+ }
53
+ function readSession(client) {
54
+ return JSON.parse(
55
+ // MUST `sessionStorage?` as nodejs does not have sessionStorage
56
+ globalThis.sessionStorage?.getItem(localStorageKey(client)) ?? "{}"
57
+ );
58
+ }
59
+ function common(client, as, _signIn, oauthHttpOptions, refresh, refreshTokenMarker) {
60
+ let token;
61
+ const eventTarget = new typescriptEventTarget.TypedEventTarget();
62
+ function makeTokenAndSaveRefresh(resp, type) {
63
+ const {
64
+ refresh_token,
65
+ expires_in,
66
+ access_token
67
+ } = resp;
68
+ !(expires_in != null) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false) : invariant2__default.default(false) : void 0;
69
+ saveLocal(client, {
70
+ refresh_token,
71
+ refreshTokenMarker
72
+ });
73
+ token = {
74
+ refresh_token,
75
+ expires_in,
76
+ access_token,
77
+ expires_at: Date.now() + expires_in * 1e3
78
+ };
79
+ eventTarget.dispatchTypedEvent(type, new CustomEvent(type, {
80
+ detail: token
81
+ }));
82
+ return token;
83
+ }
84
+ let refreshTimeout;
85
+ function rmTimeout() {
86
+ if (refreshTimeout) clearTimeout(refreshTimeout);
87
+ }
88
+ function restartRefreshTimer(evt) {
89
+ if (refresh) {
90
+ rmTimeout();
91
+ refreshTimeout = setTimeout(refresh, evt.detail.expires_in * 1e3 - 60 * 1e3);
92
+ }
93
+ }
94
+ async function signOut() {
95
+ !token ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "not signed in") : invariant2__default.default(false) : void 0;
96
+ const result = await oauth4webapi.processRevocationResponse(await oauth4webapi.revocationRequest(as, client, token.access_token, oauthHttpOptions));
97
+ rmTimeout();
98
+ removeLocal(client);
99
+ token = void 0;
100
+ throwIfError(result);
101
+ eventTarget.dispatchTypedEvent("signOut", new Event("signOut"));
102
+ }
103
+ let pendingSignIn;
104
+ async function signIn() {
105
+ if (pendingSignIn) {
106
+ return pendingSignIn;
107
+ }
108
+ try {
109
+ pendingSignIn = _signIn();
110
+ return await pendingSignIn;
111
+ } finally {
112
+ pendingSignIn = void 0;
113
+ }
114
+ }
115
+ eventTarget.addEventListener("signIn", restartRefreshTimer);
116
+ eventTarget.addEventListener("refresh", restartRefreshTimer);
117
+ function getTokenOrUndefined() {
118
+ if (!token || Date.now() >= token.expires_at) {
119
+ return void 0;
120
+ }
121
+ return token?.access_token;
122
+ }
123
+ const getToken = Object.assign(async function getToken2() {
124
+ if (!token || Date.now() >= token.expires_at) {
125
+ token = await signIn();
126
+ }
127
+ return token?.access_token;
128
+ }, {
129
+ signIn,
130
+ refresh,
131
+ signOut,
132
+ rmTimeout,
133
+ getTokenOrUndefined,
134
+ addEventListener: eventTarget.addEventListener.bind(eventTarget),
135
+ removeEventListener: eventTarget.removeEventListener.bind(eventTarget)
136
+ });
137
+ return {
138
+ getToken,
139
+ makeTokenAndSaveRefresh
140
+ };
141
+ }
142
+ function createAuthorizationServer(ctxPath, url) {
143
+ const issuer = `${new URL(ctxPath, url + "/")}`;
144
+ return {
145
+ token_endpoint: `${issuer}/api/oauth2/token`,
146
+ authorization_endpoint: `${issuer}/api/oauth2/authorize`,
147
+ revocation_endpoint: `${issuer}/api/oauth2/revoke_token`,
148
+ issuer
149
+ };
150
+ }
151
+
152
+ // src/createConfidentialOauthClient.ts
153
+ function createConfidentialOauthClient(client_id, client_secret, url, scopes = ["api:read-data", "api:write-data"], fetchFn = globalThis.fetch, ctxPath = "multipass") {
154
+ const client = {
155
+ client_id,
156
+ client_secret
157
+ };
158
+ const authServer = createAuthorizationServer(ctxPath, url);
159
+ const oauthHttpOptions = {
160
+ [oauth4webapi.customFetch]: fetchFn
161
+ };
162
+ const {
163
+ getToken,
164
+ makeTokenAndSaveRefresh
165
+ } = common(client, authServer, _signIn, oauthHttpOptions, void 0, void 0);
166
+ async function _signIn() {
167
+ return makeTokenAndSaveRefresh(throwIfError(await oauth4webapi.processClientCredentialsResponse(authServer, client, await oauth4webapi.clientCredentialsGrantRequest(authServer, client, new URLSearchParams({
168
+ scope: scopes.join(" ")
169
+ }), oauthHttpOptions))), "signIn");
170
+ }
171
+ return getToken;
172
+ }
173
+ function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {
174
+ let options = {};
175
+ if (typeof useHistory === "object") {
176
+ !(!loginPage && !postLoginPage && !scopes && !fetchFn && !ctxPath) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "If useHistory is an object, other options should not be provided") : invariant2__default.default(false) : void 0;
177
+ options = useHistory;
178
+ } else {
179
+ options = {
180
+ useHistory,
181
+ loginPage,
182
+ postLoginPage,
183
+ scopes,
184
+ fetchFn,
185
+ ctxPath
186
+ };
187
+ }
188
+ !url ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "url is required") : invariant2__default.default(false) : void 0;
189
+ !redirect_uri ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "redirectUrl is required") : invariant2__default.default(false) : void 0;
190
+ return {
191
+ useHistory: options.useHistory ?? true,
192
+ loginPage: options.loginPage,
193
+ postLoginPage: options.postLoginPage || window.location.toString(),
194
+ scopes: options.scopes ?? ["api:read-data", "api:write-data"],
195
+ fetchFn: options.fetchFn ?? globalThis.fetch,
196
+ ctxPath: options.ctxPath ?? "multipass",
197
+ refreshTokenMarker: options.refreshTokenMarker
198
+ };
199
+ }
200
+
201
+ // src/createPublicOauthClient.ts
202
+ function createPublicOauthClient(client_id, url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {
203
+ let refreshTokenMarker;
204
+ ({
205
+ useHistory,
206
+ loginPage,
207
+ postLoginPage,
208
+ scopes,
209
+ fetchFn,
210
+ ctxPath,
211
+ refreshTokenMarker
212
+ } = processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath));
213
+ const client = {
214
+ client_id,
215
+ token_endpoint_auth_method: "none"
216
+ };
217
+ const authServer = createAuthorizationServer(ctxPath, url);
218
+ const oauthHttpOptions = {
219
+ [oauth4webapi.customFetch]: fetchFn
220
+ };
221
+ const {
222
+ makeTokenAndSaveRefresh,
223
+ getToken
224
+ } = common(client, authServer, _signIn, oauthHttpOptions, maybeRefresh.bind(globalThis, true), refreshTokenMarker);
225
+ const go = async (x) => {
226
+ if (useHistory) {
227
+ window.history.replaceState({}, "", x);
228
+ return;
229
+ } else window.location.assign(x);
230
+ await delay__default.default(1e3);
231
+ throw new Error("Unable to redirect");
232
+ };
233
+ async function maybeRefresh(expectRefreshToken) {
234
+ const {
235
+ refresh_token,
236
+ refreshTokenMarker: lastRefreshTokenMarker
237
+ } = readLocal(client);
238
+ if (!refresh_token || lastRefreshTokenMarker !== refreshTokenMarker) {
239
+ if (expectRefreshToken) throw new Error("No refresh token found");
240
+ return;
241
+ }
242
+ try {
243
+ const result = makeTokenAndSaveRefresh(throwIfError(await oauth4webapi.processAuthorizationCodeOAuth2Response(authServer, client, await oauth4webapi.refreshTokenGrantRequest(authServer, client, refresh_token, oauthHttpOptions))), "refresh");
244
+ if (result && window.location.pathname === new URL(redirect_uri).pathname) {
245
+ const {
246
+ oldUrl
247
+ } = readSession(client);
248
+ void go(oldUrl ?? "/");
249
+ }
250
+ return result;
251
+ } catch (e) {
252
+ if (process.env.NODE_ENV !== "production") {
253
+ console.warn("Failed to get OAuth2 refresh token. Removing refresh token", e);
254
+ }
255
+ removeLocal(client);
256
+ if (expectRefreshToken) {
257
+ throw new Error("Could not refresh token");
258
+ }
259
+ }
260
+ }
261
+ async function maybeHandleAuthReturn() {
262
+ const {
263
+ state,
264
+ oldUrl,
265
+ codeVerifier
266
+ } = readSession(client);
267
+ if (!codeVerifier) return;
268
+ try {
269
+ const ret = makeTokenAndSaveRefresh(throwIfError(await oauth4webapi.processAuthorizationCodeOAuth2Response(authServer, client, await oauth4webapi.authorizationCodeGrantRequest(authServer, client, throwIfError(oauth4webapi.validateAuthResponse(authServer, client, new URL(window.location.href), state)), redirect_uri, codeVerifier, oauthHttpOptions))), "signIn");
270
+ void go(oldUrl);
271
+ return ret;
272
+ } catch (e) {
273
+ if (process.env.NODE_ENV !== "production") {
274
+ console.warn("Failed to get OAuth2 token using PKCE, removing PKCE and starting a new auth flow", e);
275
+ }
276
+ removeLocal(client);
277
+ removeSession(client);
278
+ throw e;
279
+ }
280
+ }
281
+ const initiateLoginRedirect = async () => {
282
+ if (loginPage && window.location.href !== loginPage && window.location.pathname !== loginPage) {
283
+ saveLocal(client, {});
284
+ saveSession(client, {
285
+ oldUrl: postLoginPage
286
+ });
287
+ await go(loginPage);
288
+ return;
289
+ }
290
+ const state = oauth4webapi.generateRandomState();
291
+ const codeVerifier = oauth4webapi.generateRandomCodeVerifier();
292
+ const oldUrl = readSession(client).oldUrl ?? window.location.toString();
293
+ saveLocal(client, {});
294
+ saveSession(client, {
295
+ codeVerifier,
296
+ state,
297
+ oldUrl
298
+ });
299
+ window.location.assign(`${authServer.authorization_endpoint}?${new URLSearchParams({
300
+ client_id,
301
+ response_type: "code",
302
+ state,
303
+ redirect_uri,
304
+ code_challenge: await oauth4webapi.calculatePKCECodeChallenge(codeVerifier),
305
+ code_challenge_method: "S256",
306
+ scope: ["offline_access", ...scopes].join(" ")
307
+ })}`);
308
+ await delay__default.default(1e3);
309
+ throw new Error("Unable to redirect");
310
+ };
311
+ async function _signIn() {
312
+ return await maybeRefresh() ?? await maybeHandleAuthReturn() ?? await initiateLoginRedirect();
313
+ }
314
+ return getToken;
315
+ }
316
+
317
+ exports.createConfidentialOauthClient = createConfidentialOauthClient;
318
+ exports.createPublicOauthClient = createPublicOauthClient;
319
+ //# sourceMappingURL=index.cjs.map
320
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/throwIfError.ts","../../src/common.ts","../../src/createConfidentialOauthClient.ts","../../src/utils.ts","../../src/createPublicOauthClient.ts"],"names":["isOAuth2Error","CustomEvent","TypedEventTarget","invariant","processRevocationResponse","revocationRequest","getToken","customFetch","processClientCredentialsResponse","clientCredentialsGrantRequest","delay","processAuthorizationCodeOAuth2Response","refreshTokenGrantRequest","authorizationCodeGrantRequest","validateAuthResponse","generateRandomState","generateRandomCodeVerifier","calculatePKCECodeChallenge"],"mappings":";;;;;;;;;;;;;AAiBO,SAAS,aAAa,MAAQ,EAAA;AACnC,EAAI,IAAAA,0BAAA,CAAc,MAAM,CAAG,EAAA;AACzB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAwB,qBAAA,EAAA,MAAA,CAAO,KAAK,CAAE,CAAA,CAAA,CAAA;AAAA,GACxD;AACA,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;;;ACAA,IAAM,WAAA,GAA0E,WAAW,WAAe,IAAA,MAAMC,qBAAoB,KAAM,CAAA;AAAA,EACxI,OAAA,CAAA;AAAA,EACA,WAAA,CAAY,MAAM,OAAS,EAAA;AACzB,IAAA,KAAA,CAAM,MAAM,OAAO,CAAA,CAAA;AACnB,IAAK,IAAA,CAAA,OAAA,GAAU,SAAS,MAAU,IAAA,IAAA,CAAA;AAAA,GACpC;AAAA,EACA,IAAI,MAAS,GAAA;AACX,IAAA,OAAO,IAAK,CAAA,OAAA,CAAA;AAAA,GACd;AACF,CAAA,CAAA;AACA,SAAS,gBAAgB,MAAQ,EAAA;AAC/B,EAAO,OAAA,CAAA,wBAAA,EAA2B,OAAO,SAAS,CAAA,CAAA,CAAA;AACpD,CAAA;AACO,SAAS,SAAA,CAAU,QAAQ,CAAG,EAAA;AAEnC,EAAW,UAAA,CAAA,YAAA,EAAc,QAAQ,eAAgB,CAAA,MAAM,GAAG,IAAK,CAAA,SAAA,CAAU,CAAC,CAAC,CAAA,CAAA;AAC7E,CAAA;AACO,SAAS,YAAY,MAAQ,EAAA;AAElC,EAAA,UAAA,CAAW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AAC,CAAE,CAAA,CAAA,CAAA;AAGJ,IAAA,MAAMP,uBAAM,GAAI,CAAA,CAAA;AAChB,IAAM,MAAA,IAAI,MAAM,oBAAoB,CAAA,CAAA;AAAA,GACtC,CAAA;AAGA,EAAA,eAAe,OAAU,GAAA;AAEvB,IAAA,OAAQ,MAAM,YAAa,EAAA,IAErB,MAAM,qBAAsB,EAAA,IAE9B,MAAM,qBAAsB,EAAA,CAAA;AAAA,GAClC;AACA,EAAO,OAAA,QAAA,CAAA;AACT","file":"index.cjs","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 { isOAuth2Error } from \"oauth4webapi\";\nexport function throwIfError(result) {\n if (isOAuth2Error(result)) {\n throw new Error(`Failed to get token: ${result.error}`);\n }\n return result;\n}","/*\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 { 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\" ? globalThis.CustomEvent : globalThis.CustomEvent ?? 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};\nfunction localStorageKey(client) {\n return `@osdk/oauth : refresh : ${client.client_id}`;\n}\nexport function saveLocal(client, x) {\n // MUST `localStorage?` as nodejs does not have localStorage\n globalThis.localStorage?.setItem(localStorageKey(client), JSON.stringify(x));\n}\nexport function removeLocal(client) {\n // MUST `localStorage?` as nodejs does not have localStorage\n globalThis.localStorage?.removeItem(localStorageKey(client));\n}\nexport function readLocal(client) {\n return JSON.parse(\n // MUST `localStorage?` as nodejs does not have localStorage\n globalThis.localStorage?.getItem(localStorageKey(client)) ?? \"{}\");\n}\nexport function saveSession(client, x) {\n // MUST `sessionStorage?` as nodejs does not have sessionStorage\n globalThis.sessionStorage?.setItem(localStorageKey(client), JSON.stringify(x));\n}\nexport function removeSession(client) {\n // MUST `sessionStorage?` as nodejs does not have sessionStorage\n globalThis.sessionStorage?.removeItem(localStorageKey(client));\n}\nexport function readSession(client) {\n return JSON.parse(\n // MUST `sessionStorage?` as nodejs does not have sessionStorage\n globalThis.sessionStorage?.getItem(localStorageKey(client)) ?? \"{}\");\n}\nexport function common(client, as, _signIn, oauthHttpOptions, refresh, refreshTokenMarker) {\n let token;\n const eventTarget = new TypedEventTarget();\n function makeTokenAndSaveRefresh(resp, type) {\n const {\n refresh_token,\n expires_in,\n access_token\n } = resp;\n !(expires_in != null) ? process.env.NODE_ENV !== \"production\" ? invariant(false) : invariant(false) : void 0;\n saveLocal(client, {\n refresh_token,\n refreshTokenMarker\n });\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, {\n detail: token\n }));\n return token;\n }\n let refreshTimeout;\n function rmTimeout() {\n if (refreshTimeout) 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 !token ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"not signed in\") : invariant(false) : void 0;\n const result = await processRevocationResponse(await revocationRequest(as, client, token.access_token, oauthHttpOptions));\n rmTimeout();\n\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 } 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 {\n getToken,\n makeTokenAndSaveRefresh\n };\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 * 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 { clientCredentialsGrantRequest, customFetch, processClientCredentialsResponse } from \"oauth4webapi\";\nimport { common, createAuthorizationServer } from \"./common.js\";\nimport { throwIfError } from \"./throwIfError.js\";\n\n/**\n * @param client_id\n * @param client_secret\n * @param url the base url of your foundry server\n * @param scopes\n * @param fetchFn\n * @param ctxPath\n * @returns which can be used as a token provider\n */\nexport function createConfidentialOauthClient(client_id, client_secret, url, scopes = [\"api:read-data\", \"api:write-data\"], fetchFn = globalThis.fetch, ctxPath = \"multipass\") {\n const client = {\n client_id,\n client_secret\n };\n const authServer = createAuthorizationServer(ctxPath, url);\n const oauthHttpOptions = {\n [customFetch]: fetchFn\n };\n const {\n getToken,\n makeTokenAndSaveRefresh\n } = common(client, authServer, _signIn, oauthHttpOptions, undefined, undefined);\n async function _signIn() {\n return makeTokenAndSaveRefresh(throwIfError(await processClientCredentialsResponse(authServer, client, await clientCredentialsGrantRequest(authServer, client, new URLSearchParams({\n scope: scopes.join(\" \")\n }), oauthHttpOptions))), \"signIn\");\n }\n return getToken;\n}","/*\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 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 !(!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;\n options = useHistory;\n } else {\n options = {\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath\n };\n }\n !url ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"url is required\") : invariant(false) : void 0;\n !redirect_uri ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"redirectUrl is required\") : invariant(false) : void 0;\n\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 refreshTokenMarker: options.refreshTokenMarker\n };\n}","/*\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 delay from \"delay\";\nimport { authorizationCodeGrantRequest, calculatePKCECodeChallenge, customFetch, generateRandomCodeVerifier, generateRandomState, processAuthorizationCodeOAuth2Response, refreshTokenGrantRequest, validateAuthResponse } from \"oauth4webapi\";\nimport { common, createAuthorizationServer, readLocal, readSession, removeLocal, removeSession, saveLocal, saveSession } from \"./common.js\";\nimport { throwIfError } from \"./throwIfError.js\";\nimport { processOptionsAndAssignDefaults } from \"./utils.js\";\n\n/**\n * Creates a PublicOauthClient for authentication.\n *\n * @param {string} clientId - The client_id from the OAuth configuration on the server\n * @param {string} url - The base URL of your Foundry server\n * @param {string} redirectUrl - The URL configured for redirect in the OAuth configuration on the server\n * @param {PublicOauthClientOptions} options - Additional options for the client\n * @returns {PublicOauthClient} A client that can be used as a token provider\n */\n\n/**\n * Creates a PublicOauthClient for authentication.\n *\n * @param {string} clientId - The client_id from the OAuth configuration on the server\n * @param {string} url - The base URL of your Foundry server\n * @param {string} redirectUrl - The URL configured for redirect in the OAuth configuration on the server\n * @param {boolean} useHistory - If true, uses `history.replaceState()`, otherwise uses `window.location.assign()` (defaults to true)\n * @param {string} loginPage - Custom landing page URL prior to logging in\n * @param {string} postLoginPage - URL to return to after completed authentication cycle (defaults to `window.location.toString()`)\n * @param {string[]} scopes - OAuth scopes to request. If not provided, defaults to `[\"api:read-data\", \"api:write-data\"]`\n * @param {typeof globalThis.fetch} fetchFn - Custom fetch function to use for requests (defaults to `globalThis.fetch`)\n * @param {string} ctxPath - Context path for the authorization server (defaults to \"multipass\")\n * @returns {PublicOauthClient} A client that can be used as a token provider\n */\n\nexport function createPublicOauthClient(client_id, url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {\n let refreshTokenMarker;\n ({\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n refreshTokenMarker\n } = processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath));\n const client = {\n client_id,\n token_endpoint_auth_method: \"none\"\n };\n const authServer = createAuthorizationServer(ctxPath, url);\n const oauthHttpOptions = {\n [customFetch]: fetchFn\n };\n const {\n makeTokenAndSaveRefresh,\n getToken\n } = common(client, authServer, _signIn, oauthHttpOptions, maybeRefresh.bind(globalThis, true), refreshTokenMarker);\n\n // as an arrow function, `useHistory` is known to be a boolean\n const go = async x => {\n if (useHistory) {\n window.history.replaceState({}, \"\", x);\n return;\n } else window.location.assign(x);\n await delay(1000);\n throw new Error(\"Unable to redirect\");\n };\n async function maybeRefresh(expectRefreshToken) {\n const {\n refresh_token,\n refreshTokenMarker: lastRefreshTokenMarker\n } = readLocal(client);\n if (!refresh_token || lastRefreshTokenMarker !== refreshTokenMarker) {\n if (expectRefreshToken) throw new Error(\"No refresh token found\");\n return;\n }\n try {\n // note, we don't use processRefreshTokenResponse because the mp oauth implementation\n // doesn't do refresh tokens quite right and this lets us skip the id check\n const result = makeTokenAndSaveRefresh(throwIfError(await processAuthorizationCodeOAuth2Response(authServer, client, await refreshTokenGrantRequest(authServer, client, refresh_token, oauthHttpOptions))), \"refresh\");\n if (result && window.location.pathname === new URL(redirect_uri).pathname) {\n const {\n oldUrl\n } = readSession(client);\n // don't block on the redirect\n void go(oldUrl ?? \"/\");\n }\n return result;\n } catch (e) {\n if (process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line no-console\n console.warn(\"Failed to get OAuth2 refresh token. Removing refresh token\", e);\n }\n removeLocal(client);\n if (expectRefreshToken) {\n throw new Error(\"Could not refresh token\");\n }\n }\n }\n async function maybeHandleAuthReturn() {\n const {\n state,\n oldUrl,\n codeVerifier\n } = readSession(client);\n if (!codeVerifier) return;\n try {\n const ret = makeTokenAndSaveRefresh(throwIfError(await processAuthorizationCodeOAuth2Response(authServer, client, await authorizationCodeGrantRequest(authServer, client, throwIfError(validateAuthResponse(authServer, client, new URL(window.location.href), state)), redirect_uri, codeVerifier, oauthHttpOptions))), \"signIn\");\n void go(oldUrl);\n return ret;\n } catch (e) {\n if (process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line no-console\n console.warn(\"Failed to get OAuth2 token using PKCE, removing PKCE and starting a new auth flow\", e);\n }\n removeLocal(client);\n removeSession(client);\n throw e;\n }\n }\n\n // As an arrow function, `scopes` and `postLoginPage` are known at compile time\n const initiateLoginRedirect = async () => {\n if (loginPage && window.location.href !== loginPage && window.location.pathname !== loginPage) {\n saveLocal(client, {});\n saveSession(client, {\n oldUrl: postLoginPage\n });\n await go(loginPage);\n return;\n }\n const state = generateRandomState();\n const codeVerifier = generateRandomCodeVerifier();\n const oldUrl = readSession(client).oldUrl ?? window.location.toString();\n saveLocal(client, {});\n saveSession(client, {\n codeVerifier,\n state,\n oldUrl\n });\n window.location.assign(`${authServer.authorization_endpoint}?${new URLSearchParams({\n client_id,\n response_type: \"code\",\n state,\n redirect_uri,\n code_challenge: await calculatePKCECodeChallenge(codeVerifier),\n code_challenge_method: \"S256\",\n scope: [\"offline_access\", ...scopes].join(\" \")\n })}`);\n\n // Give time for redirect to happen\n await delay(1000);\n throw new Error(\"Unable to redirect\");\n };\n\n /** Will throw if there is no token! */\n async function _signIn() {\n // 1. Check if we have a refresh token in local storage\n return (await maybeRefresh()\n // 2. If there is no refresh token we are likely trying to perform the callback\n ) ?? (await maybeHandleAuthReturn())\n // 3. If we haven't been able to load the token from one of the two above ways, we need to make the initial auth request\n ?? (await initiateLoginRedirect());\n }\n return getToken;\n}"]}
@@ -1,5 +1,43 @@
1
- import type { PublicOauthClient } from "./PublicOauthClient.js";
2
- export interface PublicOauthClientOptions {
1
+ interface Token {
2
+ readonly access_token: string;
3
+ readonly expires_in: number;
4
+ readonly refresh_token?: string;
5
+ readonly expires_at: number;
6
+ }
7
+
8
+ type Events = {
9
+ signIn: CustomEvent<Token>;
10
+ signOut: Event;
11
+ refresh: CustomEvent<Token>;
12
+ };
13
+ interface BaseOauthClient<K extends keyof Events & string> {
14
+ (): Promise<string>;
15
+ getTokenOrUndefined: () => string | undefined;
16
+ signIn: () => Promise<Token>;
17
+ signOut: () => Promise<void>;
18
+ addEventListener: <T extends K>(type: T, listener: ((evt: Events[T]) => void) | null, options?: boolean | AddEventListenerOptions) => void;
19
+ removeEventListener: <T extends K>(type: T, callback: ((evt: Events[T]) => void) | null, options?: EventListenerOptions | boolean) => void;
20
+ }
21
+
22
+ interface ConfidentialOauthClient extends BaseOauthClient<"signIn" | "signOut"> {
23
+ }
24
+
25
+ /**
26
+ * @param client_id
27
+ * @param client_secret
28
+ * @param url the base url of your foundry server
29
+ * @param scopes
30
+ * @param fetchFn
31
+ * @param ctxPath
32
+ * @returns which can be used as a token provider
33
+ */
34
+ declare function createConfidentialOauthClient(client_id: string, client_secret: string, url: string, scopes?: string[], fetchFn?: typeof globalThis.fetch, ctxPath?: string): ConfidentialOauthClient;
35
+
36
+ interface PublicOauthClient extends BaseOauthClient<"signIn" | "signOut" | "refresh"> {
37
+ refresh: () => Promise<Token | undefined>;
38
+ }
39
+
40
+ interface PublicOauthClientOptions {
3
41
  /**
4
42
  * If true, uses `history.replaceState()`, otherwise uses `window.location.assign()` (defaults to true)
5
43
  */
@@ -24,6 +62,10 @@ export interface PublicOauthClientOptions {
24
62
  * Context path for the authorization server (defaults to "multipass")
25
63
  */
26
64
  ctxPath?: string;
65
+ /**
66
+ * Allows for an additional value to be appended to the local storage key for the refresh token.
67
+ */
68
+ refreshTokenMarker?: string;
27
69
  }
28
70
  /**
29
71
  * Creates a PublicOauthClient for authentication.
@@ -34,7 +76,7 @@ export interface PublicOauthClientOptions {
34
76
  * @param {PublicOauthClientOptions} options - Additional options for the client
35
77
  * @returns {PublicOauthClient} A client that can be used as a token provider
36
78
  */
37
- export declare function createPublicOauthClient(clientId: string, url: string, redirectUrl: string, options?: PublicOauthClientOptions): PublicOauthClient;
79
+ declare function createPublicOauthClient(clientId: string, url: string, redirectUrl: string, options?: PublicOauthClientOptions): PublicOauthClient;
38
80
  /**
39
81
  * Creates a PublicOauthClient for authentication.
40
82
  *
@@ -49,5 +91,6 @@ export declare function createPublicOauthClient(clientId: string, url: string, r
49
91
  * @param {string} ctxPath - Context path for the authorization server (defaults to "multipass")
50
92
  * @returns {PublicOauthClient} A client that can be used as a token provider
51
93
  */
52
- export declare function createPublicOauthClient(client_id: string, url: string, redirectUrl: string, useHistory?: boolean, loginPage?: string, postLoginPage?: string, scopes?: string[], fetchFn?: typeof globalThis.fetch, ctxPath?: string): PublicOauthClient;
53
- //# sourceMappingURL=createPublicOauthClient.d.ts.map
94
+ declare function createPublicOauthClient(client_id: string, url: string, redirectUrl: string, useHistory?: boolean, loginPage?: string, postLoginPage?: string, scopes?: string[], fetchFn?: typeof globalThis.fetch, ctxPath?: string): PublicOauthClient;
95
+
96
+ export { type PublicOauthClient, createConfidentialOauthClient, createPublicOauthClient };
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+
16
17
  import { describe, expect, it } from "vitest";
17
18
  import { createAuthorizationServer } from "./common.js";
18
19
  describe("Create authorization server", () => {
@@ -1 +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,QAAQ,QAAQ;AAC7C,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":[]}
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.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 { describe, expect, it } from \"vitest\";\n\nimport { createAuthorizationServer } from \"./common.js\";\n\ndescribe(\"Create authorization server\", () => {\n it(\"works with old multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\n \"/multipass\",\n \"https://stack.palantir.com\",\n );\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint:\n \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint:\n \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n });\n\n it(\"works with new multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\n \"multipass\",\n \"https://stack.palantir.com\",\n );\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint:\n \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint:\n \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n\n const authServerCustom = createAuthorizationServer(\n \"multipass\",\n \"https://stack.palantir.com/foo/first/someStuff\",\n );\n expect(authServerCustom).toEqual({\n token_endpoint:\n \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token\",\n authorization_endpoint:\n \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize\",\n revocation_endpoint:\n \"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;;AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAE7C,SAASC,yBAAyB,QAAQ,aAAa;AAEvDH,QAAQ,CAAC,6BAA6B,EAAE,MAAM;EAC5CE,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC5C,MAAME,UAAU,GAAGD,yBAAyB,CAC1C,YAAY,EACZ,4BACF,CAAC;IACDF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACzBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EACpB,2DAA2D;MAC7DC,mBAAmB,EACjB,8DAA8D;MAChEC,MAAM,EAAE;IACV,CAAC,CAAC;EACJ,CAAC,CAAC;EAEFP,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC5C,MAAME,UAAU,GAAGD,yBAAyB,CAC1C,WAAW,EACX,4BACF,CAAC;IACDF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACzBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EACpB,2DAA2D;MAC7DC,mBAAmB,EACjB,8DAA8D;MAChEC,MAAM,EAAE;IACV,CAAC,CAAC;IAEF,MAAMC,gBAAgB,GAAGP,yBAAyB,CAChD,WAAW,EACX,gDACF,CAAC;IACDF,MAAM,CAACS,gBAAgB,CAAC,CAACL,OAAO,CAAC;MAC/BC,cAAc,EACZ,2EAA2E;MAC7EC,sBAAsB,EACpB,+EAA+E;MACjFC,mBAAmB,EACjB,kFAAkF;MACpFC,MAAM,EAAE;IACV,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -1,17 +1,2 @@
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
1
  export {};
17
2
  //# sourceMappingURL=BaseOauthClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseOauthClient.js","names":[],"sources":["BaseOauthClient.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 */\nexport {};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"BaseOauthClient.js","names":[],"sources":["BaseOauthClient.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 type { Token } from \"./Token.js\";\n\nexport type Events = {\n signIn: CustomEvent<Token>;\n signOut: Event;\n refresh: CustomEvent<Token>;\n};\n\nexport interface BaseOauthClient<K extends keyof Events & string> {\n (): Promise<string>;\n\n getTokenOrUndefined: () => string | undefined;\n signIn: () => Promise<Token>;\n signOut: () => Promise<void>;\n\n addEventListener: <T extends K>(\n type: T,\n listener: ((evt: Events[T]) => void) | null,\n options?: boolean | AddEventListenerOptions,\n ) => void;\n\n removeEventListener: <T extends K>(\n type: T,\n callback: ((evt: Events[T]) => void) | null,\n options?: EventListenerOptions | boolean,\n ) => void;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,17 +1,2 @@
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
1
  export {};
17
2
  //# sourceMappingURL=ConfidentialOauthClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConfidentialOauthClient.js","names":[],"sources":["ConfidentialOauthClient.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 */\nexport {};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"ConfidentialOauthClient.js","names":[],"sources":["ConfidentialOauthClient.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 type { BaseOauthClient } from \"./BaseOauthClient.js\";\n\nexport interface ConfidentialOauthClient\n extends BaseOauthClient<\"signIn\" | \"signOut\">\n{\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,17 +1,2 @@
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
1
  export {};
17
2
  //# sourceMappingURL=PublicOauthClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PublicOauthClient.js","names":[],"sources":["PublicOauthClient.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 */\nexport {};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"PublicOauthClient.js","names":[],"sources":["PublicOauthClient.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 type { BaseOauthClient } from \"./BaseOauthClient.js\";\nimport type { Token } from \"./Token.js\";\n\nexport interface PublicOauthClient\n extends BaseOauthClient<\"signIn\" | \"signOut\" | \"refresh\">\n{\n refresh: () => Promise<Token | undefined>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,17 +1,2 @@
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
1
  export {};
17
2
  //# sourceMappingURL=Token.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Token.js","names":[],"sources":["Token.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 */\nexport {};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"file":"Token.js","names":[],"sources":["Token.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\nexport interface Token {\n readonly access_token: string;\n readonly expires_in: number;\n readonly refresh_token?: string;\n readonly expires_at: number;\n}\n"],"mappings":"","ignoreList":[]}
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+
16
17
  import { createPublicOauthClient } from "@osdk/oauth";
17
18
  import * as oauthModule from "@osdk/oauth";
18
19
  import { describe, expect, it, vi } from "vitest";
@@ -29,11 +30,13 @@ vi.stubGlobal("window", {
29
30
  describe("createPublicOauthClient", () => {
30
31
  it("should return the same processed options for both client creation methods", async () => {
31
32
  const mockProcessOptionsAndAssignDefaults = vi.fn();
33
+
32
34
  // Mock processOptionsAndAssignDefaults to call the mock function
33
35
  vi.spyOn(utilsModule, "processOptionsAndAssignDefaults").mockImplementation((...args) => {
34
36
  mockProcessOptionsAndAssignDefaults(...args);
35
37
  return utilsModule.processOptionsAndAssignDefaults(...args);
36
38
  });
39
+
37
40
  // Mock createPublicOauthClient to call both the mock and the original function
38
41
  vi.spyOn(oauthModule, "createPublicOauthClient").mockImplementation((...args) => {
39
42
  const [_client_id, ...rest] = args;