@osdk/oauth 0.2.0 → 0.3.0

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 (33) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/build/{js/index.browser.mjs → browser/index.js} +146 -101
  3. package/build/browser/index.js.map +1 -0
  4. package/build/{js → cjs}/index.cjs +145 -99
  5. package/build/cjs/index.cjs.map +1 -0
  6. package/build/esm/BaseOauthClient.d.ts +14 -0
  7. package/build/esm/BaseOauthClient.d.ts.map +1 -0
  8. package/build/esm/ConfidentialOauthClient.d.ts +4 -0
  9. package/build/esm/ConfidentialOauthClient.d.ts.map +1 -0
  10. package/build/esm/PublicOauthClient.d.ts +6 -0
  11. package/build/esm/PublicOauthClient.d.ts.map +1 -0
  12. package/build/esm/common.d.ts +36 -0
  13. package/build/esm/common.d.ts.map +1 -0
  14. package/build/esm/createConfidentialOauthClient.d.ts +12 -0
  15. package/build/esm/createConfidentialOauthClient.d.ts.map +1 -0
  16. package/build/esm/createPublicOauthClient.d.ts.map +1 -0
  17. package/build/{types → esm}/index.d.ts +1 -0
  18. package/build/esm/index.d.ts.map +1 -0
  19. package/build/{js/index.mjs → esm/index.js} +146 -101
  20. package/build/esm/index.js.map +1 -0
  21. package/package.json +18 -18
  22. package/build/js/index.browser.mjs.map +0 -1
  23. package/build/js/index.cjs.map +0 -1
  24. package/build/js/index.mjs.map +0 -1
  25. package/build/types/PublicOauthClient.d.ts +0 -15
  26. package/build/types/PublicOauthClient.d.ts.map +0 -1
  27. package/build/types/createPublicOauthClient.d.ts.map +0 -1
  28. package/build/types/index.d.ts.map +0 -1
  29. /package/build/{types → esm}/Token.d.ts +0 -0
  30. /package/build/{types → esm}/Token.d.ts.map +0 -0
  31. /package/build/{types → esm}/createPublicOauthClient.d.ts +0 -0
  32. /package/build/{types → esm}/throwIfError.d.ts +0 -0
  33. /package/build/{types → esm}/throwIfError.d.ts.map +0 -0
@@ -1,16 +1,16 @@
1
1
  'use strict';
2
2
 
3
- var delay = require('delay');
4
3
  var oauth4webapi = require('oauth4webapi');
5
4
  var invariant = require('tiny-invariant');
6
5
  var typescriptEventTarget = require('typescript-event-target');
6
+ var delay = require('delay');
7
7
 
8
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
9
 
10
- var delay__default = /*#__PURE__*/_interopDefault(delay);
11
10
  var invariant__default = /*#__PURE__*/_interopDefault(invariant);
11
+ var delay__default = /*#__PURE__*/_interopDefault(delay);
12
12
 
13
- // src/createPublicOauthClient.ts
13
+ // src/createConfidentialOauthClient.ts
14
14
  function throwIfError(result) {
15
15
  if (oauth4webapi.isOAuth2Error(result)) {
16
16
  throw new Error(`Failed to get token: ${result.error}`);
@@ -18,41 +18,33 @@ function throwIfError(result) {
18
18
  return result;
19
19
  }
20
20
 
21
- // src/createPublicOauthClient.ts
22
- var storageKey = "asdfasdfdhjlkajhgj";
23
- function saveLocal(x) {
24
- localStorage.setItem(storageKey, JSON.stringify(x));
21
+ // src/common.ts
22
+ var CustomEvent = process.env.target === "browser" ? globalThis.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
+ var localStorage = globalThis.localStorage;
33
+ function saveLocal(client, x) {
34
+ localStorage?.setItem(`@osdk/oauth : refresh : ${client.client_id}`, JSON.stringify(x));
25
35
  }
26
- function removeLocal() {
27
- localStorage.removeItem(storageKey);
36
+ function removeLocal(client) {
37
+ localStorage?.removeItem(`@osdk/oauth : refresh : ${client.client_id}`);
28
38
  }
29
- function readLocal() {
30
- return JSON.parse(localStorage.getItem(storageKey) ?? "{}");
39
+ function readLocal(client) {
40
+ return JSON.parse(
41
+ // MUST `localStorage?` as nodejs does not have localStorage
42
+ localStorage?.getItem(`@osdk/oauth : refresh : ${client.client_id}`) ?? "{}"
43
+ );
31
44
  }
32
- function createPublicOauthClient(client_id, url, redirectUrl, useHistory, loginPage, postLoginPage = window.location.toString(), scopes = ["api:read-data", "api:write-data"], fetchFn = globalThis.fetch, ctxPath = "/multipass") {
33
- const oauthHttpOptions = {
34
- [oauth4webapi.customFetch]: fetchFn
35
- };
45
+ function common(client, as, _signIn, oauthHttpOptions, refresh) {
46
+ let token;
36
47
  const eventTarget = new typescriptEventTarget.TypedEventTarget();
37
- const issuer = `${new URL(ctxPath, url)}`;
38
- const as = {
39
- token_endpoint: `${issuer}/api/oauth2/token`,
40
- authorization_endpoint: `${issuer}/api/oauth2/authorize`,
41
- revocation_endpoint: `${issuer}/api/oauth2/revoke_token`,
42
- issuer
43
- };
44
- const client = {
45
- client_id,
46
- token_endpoint_auth_method: "none"
47
- };
48
- async function go(x) {
49
- if (useHistory)
50
- return window.history.replaceState({}, "", x);
51
- else
52
- window.location.assign(x);
53
- await delay__default.default(1e3);
54
- throw new Error("Unable to redirect");
55
- }
56
48
  function makeTokenAndSaveRefresh(resp, type) {
57
49
  const {
58
50
  refresh_token,
@@ -60,7 +52,7 @@ function createPublicOauthClient(client_id, url, redirectUrl, useHistory, loginP
60
52
  access_token
61
53
  } = resp;
62
54
  !(expires_in != null) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false) : invariant__default.default(false) : void 0;
63
- saveLocal({
55
+ saveLocal(client, {
64
56
  refresh_token
65
57
  });
66
58
  token = {
@@ -74,22 +66,122 @@ function createPublicOauthClient(client_id, url, redirectUrl, useHistory, loginP
74
66
  }));
75
67
  return token;
76
68
  }
69
+ let refreshTimeout;
70
+ function rmTimeout() {
71
+ if (refreshTimeout) clearTimeout(refreshTimeout);
72
+ }
73
+ function restartRefreshTimer(evt) {
74
+ if (refresh) {
75
+ rmTimeout();
76
+ refreshTimeout = setTimeout(refresh, evt.detail.expires_in * 1e3 - 60 * 1e3);
77
+ }
78
+ }
79
+ async function signOut() {
80
+ !token ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "not signed in") : invariant__default.default(false) : void 0;
81
+ const result = await oauth4webapi.processRevocationResponse(await oauth4webapi.revocationRequest(as, client, token.access_token, oauthHttpOptions));
82
+ rmTimeout();
83
+ removeLocal(client);
84
+ token = void 0;
85
+ throwIfError(result);
86
+ eventTarget.dispatchTypedEvent("signOut", new Event("signOut"));
87
+ }
88
+ let pendingSignIn;
89
+ async function signIn() {
90
+ if (pendingSignIn) {
91
+ return pendingSignIn;
92
+ }
93
+ try {
94
+ pendingSignIn = _signIn();
95
+ return await pendingSignIn;
96
+ } finally {
97
+ pendingSignIn = void 0;
98
+ }
99
+ }
100
+ eventTarget.addEventListener("signIn", restartRefreshTimer);
101
+ eventTarget.addEventListener("refresh", restartRefreshTimer);
102
+ const getToken = Object.assign(async function getToken2() {
103
+ if (!token || Date.now() >= token.expires_at) {
104
+ token = await signIn();
105
+ }
106
+ return token.access_token;
107
+ }, {
108
+ signIn,
109
+ refresh,
110
+ signOut,
111
+ rmTimeout,
112
+ addEventListener: eventTarget.addEventListener.bind(eventTarget),
113
+ removeEventListener: eventTarget.removeEventListener.bind(eventTarget)
114
+ });
115
+ return {
116
+ getToken,
117
+ makeTokenAndSaveRefresh
118
+ };
119
+ }
120
+ function createAuthorizationServer(ctxPath, url) {
121
+ const issuer = `${new URL(ctxPath, url)}`;
122
+ return {
123
+ token_endpoint: `${issuer}/api/oauth2/token`,
124
+ authorization_endpoint: `${issuer}/api/oauth2/authorize`,
125
+ revocation_endpoint: `${issuer}/api/oauth2/revoke_token`,
126
+ issuer
127
+ };
128
+ }
129
+
130
+ // src/createConfidentialOauthClient.ts
131
+ function createConfidentialOauthClient(client_id, client_secret, url, scopes = ["api:read-data", "api:write-data"], fetchFn = globalThis.fetch, ctxPath = "/multipass") {
132
+ const client = {
133
+ client_id,
134
+ client_secret
135
+ };
136
+ const authServer = createAuthorizationServer(ctxPath, url);
137
+ const oauthHttpOptions = {
138
+ [oauth4webapi.customFetch]: fetchFn
139
+ };
140
+ const {
141
+ getToken,
142
+ makeTokenAndSaveRefresh
143
+ } = common(client, authServer, _signIn, oauthHttpOptions, void 0);
144
+ async function _signIn() {
145
+ return makeTokenAndSaveRefresh(throwIfError(await oauth4webapi.processClientCredentialsResponse(authServer, client, await oauth4webapi.clientCredentialsGrantRequest(authServer, client, new URLSearchParams({
146
+ scope: scopes.join(" ")
147
+ }), oauthHttpOptions))), "signIn");
148
+ }
149
+ return getToken;
150
+ }
151
+ function createPublicOauthClient(client_id, url, redirectUrl, useHistory, loginPage, postLoginPage = window.location.toString(), scopes = ["api:read-data", "api:write-data"], fetchFn = globalThis.fetch, ctxPath = "/multipass") {
152
+ const client = {
153
+ client_id,
154
+ token_endpoint_auth_method: "none"
155
+ };
156
+ const authServer = createAuthorizationServer(ctxPath, url);
157
+ const oauthHttpOptions = {
158
+ [oauth4webapi.customFetch]: fetchFn
159
+ };
160
+ const {
161
+ makeTokenAndSaveRefresh,
162
+ getToken
163
+ } = common(client, authServer, _signIn, oauthHttpOptions, maybeRefresh.bind(globalThis, true));
164
+ async function go(x) {
165
+ if (useHistory) return window.history.replaceState({}, "", x);
166
+ else window.location.assign(x);
167
+ await delay__default.default(1e3);
168
+ throw new Error("Unable to redirect");
169
+ }
77
170
  async function maybeRefresh(expectRefreshToken) {
78
171
  const {
79
172
  refresh_token
80
- } = readLocal();
173
+ } = readLocal(client);
81
174
  if (!refresh_token) {
82
- if (expectRefreshToken)
83
- throw new Error("No refresh token found");
175
+ if (expectRefreshToken) throw new Error("No refresh token found");
84
176
  return;
85
177
  }
86
178
  try {
87
- return makeTokenAndSaveRefresh(throwIfError(await oauth4webapi.processAuthorizationCodeOAuth2Response(as, client, await oauth4webapi.refreshTokenGrantRequest(as, client, refresh_token, oauthHttpOptions))), "refresh");
179
+ return makeTokenAndSaveRefresh(throwIfError(await oauth4webapi.processAuthorizationCodeOAuth2Response(authServer, client, await oauth4webapi.refreshTokenGrantRequest(authServer, client, refresh_token, oauthHttpOptions))), "refresh");
88
180
  } catch (e) {
89
181
  if (process?.env?.NODE_ENV !== "production") {
90
182
  console.warn("Failed to get OAuth2 refresh token. Removing refresh token", e);
91
183
  }
92
- removeLocal();
184
+ removeLocal(client);
93
185
  if (expectRefreshToken) {
94
186
  throw new Error("Could not refresh token");
95
187
  }
@@ -100,36 +192,35 @@ function createPublicOauthClient(client_id, url, redirectUrl, useHistory, loginP
100
192
  codeVerifier,
101
193
  state,
102
194
  oldUrl
103
- } = readLocal();
104
- if (!codeVerifier)
105
- return;
195
+ } = readLocal(client);
196
+ if (!codeVerifier) return;
106
197
  try {
107
- const ret2 = makeTokenAndSaveRefresh(throwIfError(await oauth4webapi.processAuthorizationCodeOAuth2Response(as, client, await oauth4webapi.authorizationCodeGrantRequest(as, client, throwIfError(oauth4webapi.validateAuthResponse(as, client, new URL(window.location.href), state)), redirectUrl, codeVerifier, oauthHttpOptions))), "signIn");
198
+ 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)), redirectUrl, codeVerifier, oauthHttpOptions))), "signIn");
108
199
  go(oldUrl);
109
- return ret2;
200
+ return ret;
110
201
  } catch (e) {
111
202
  if (process?.env?.NODE_ENV !== "production") {
112
- console.warn("Failed to get OAuth2 token using PCKE, removing PCKE and starting a new auth flow", e);
203
+ console.warn("Failed to get OAuth2 token using PKCE, removing PKCE and starting a new auth flow", e);
113
204
  }
114
- removeLocal();
205
+ removeLocal(client);
115
206
  }
116
207
  }
117
208
  async function initiateLoginRedirect() {
118
209
  if (loginPage && window.location.href !== loginPage) {
119
- saveLocal({
210
+ saveLocal(client, {
120
211
  oldUrl: postLoginPage
121
212
  });
122
213
  return await go(loginPage);
123
214
  }
124
215
  const state = oauth4webapi.generateRandomState();
125
216
  const codeVerifier = oauth4webapi.generateRandomCodeVerifier();
126
- const oldUrl = readLocal().oldUrl ?? window.location.toString();
127
- saveLocal({
217
+ const oldUrl = readLocal(client).oldUrl ?? window.location.toString();
218
+ saveLocal(client, {
128
219
  codeVerifier,
129
220
  state,
130
221
  oldUrl
131
222
  });
132
- window.location.assign(`${as.authorization_endpoint}?${new URLSearchParams({
223
+ window.location.assign(`${authServer.authorization_endpoint}?${new URLSearchParams({
133
224
  client_id,
134
225
  response_type: "code",
135
226
  state,
@@ -141,58 +232,13 @@ function createPublicOauthClient(client_id, url, redirectUrl, useHistory, loginP
141
232
  await delay__default.default(1e3);
142
233
  throw new Error("Unable to redirect");
143
234
  }
144
- let refreshTimeout;
145
- function rmTimeout() {
146
- if (refreshTimeout)
147
- clearTimeout(refreshTimeout);
148
- }
149
- function restartRefreshTimer(evt) {
150
- rmTimeout();
151
- refreshTimeout = setTimeout(refresh, evt.detail.expires_in * 1e3 - 60 * 1e3);
152
- }
153
- const refresh = maybeRefresh.bind(globalThis, true);
154
- async function signOut() {
155
- !token ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "not signed in") : invariant__default.default(false) : void 0;
156
- const result = await oauth4webapi.processRevocationResponse(await oauth4webapi.revocationRequest(as, client, token.access_token, oauthHttpOptions));
157
- rmTimeout();
158
- removeLocal();
159
- token = void 0;
160
- throwIfError(result);
161
- eventTarget.dispatchTypedEvent("signOut", new Event("signOut"));
162
- }
163
- let pendingSignIn;
164
- async function signIn() {
165
- if (pendingSignIn) {
166
- return pendingSignIn;
167
- }
168
- try {
169
- pendingSignIn = _signIn();
170
- return await pendingSignIn;
171
- } finally {
172
- pendingSignIn = void 0;
173
- }
174
- }
175
235
  async function _signIn() {
176
- return token = await maybeRefresh() ?? await maybeHandleAuthReturn() ?? await initiateLoginRedirect();
236
+ return await maybeRefresh() ?? await maybeHandleAuthReturn() ?? await initiateLoginRedirect();
177
237
  }
178
- eventTarget.addEventListener("signIn", restartRefreshTimer);
179
- eventTarget.addEventListener("refresh", restartRefreshTimer);
180
- let token;
181
- const ret = Object.assign(async function ret2() {
182
- if (!token || Date.now() >= token.expires_at) {
183
- token = await signIn();
184
- }
185
- return token.access_token;
186
- }, {
187
- signIn,
188
- refresh,
189
- signOut,
190
- addEventListener: eventTarget.addEventListener.bind(eventTarget),
191
- removeEventListener: eventTarget.removeEventListener.bind(eventTarget)
192
- });
193
- return ret;
238
+ return getToken;
194
239
  }
195
240
 
241
+ exports.createConfidentialOauthClient = createConfidentialOauthClient;
196
242
  exports.createPublicOauthClient = createPublicOauthClient;
197
243
  //# sourceMappingURL=out.js.map
198
244
  //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/createConfidentialOauthClient.ts","../../src/common.ts","../../src/throwIfError.ts","../../src/createPublicOauthClient.ts"],"names":["CustomEvent","getToken","customFetch"],"mappings":";AAgBA,SAAS,+BAA+B,aAAa,wCAAwC;;;ACA7F,SAAS,2BAA2B,yBAAyB;AAC7D,OAAO,eAAe;AACtB,SAAS,wBAAwB;;;ACFjC,SAAS,qBAAqB;AACvB,SAAS,aAAa,QAAQ;AACnC,MAAI,cAAc,MAAM,GAAG;AACzB,UAAM,IAAI,MAAM,wBAAwB,OAAO,KAAK,EAAE;AAAA,EACxD;AACA,SAAO;AACT;;;ADAA,IAAM,cAAc,QAAQ,IAAI,WAAW,YAAY,WAAW,cAAc,WAAW,eAAe,MAAMA,qBAAoB,MAAM;AAAA,EACxI;AAAA,EACA,YAAY,MAAM,SAAS;AACzB,UAAM,MAAM,OAAO;AACnB,SAAK,UAAU,SAAS,UAAU;AAAA,EACpC;AAAA,EACA,IAAI,SAAS;AACX,WAAO,KAAK;AAAA,EACd;AACF;AACA,IAAM,eAAe,WAAW;AACzB,SAAS,UAAU,QAAQ,GAAG;AAEnC,gBAAc,QAAQ,2BAA2B,OAAO,SAAS,IAAI,KAAK,UAAU,CAAC,CAAC;AACxF;AACO,SAAS,YAAY,QAAQ;AAElC,gBAAc,WAAW,2BAA2B,OAAO,SAAS,EAAE;AACxE;AACO,SAAS,UAAU,QAAQ;A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E,KAAK,GAAG;AAAA,IAC/C,CAAC,CAAC,EAAE;AAGJ,UAAM,MAAM,GAAI;AAChB,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACtC;AAGA,iBAAe,UAAU;AAEvB,WAAQ,MAAM,aAAa,KAErB,MAAM,sBAAsB,KAE9B,MAAM,sBAAsB;AAAA,EAClC;AACA,SAAO;AACT","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 { 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);\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 { 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};\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}\nexport function common(client, as, _signIn, oauthHttpOptions, refresh) {\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 });\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 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 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 { 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 delay from \"delay\";\nimport { authorizationCodeGrantRequest, calculatePKCECodeChallenge, customFetch, generateRandomCodeVerifier, generateRandomState, processAuthorizationCodeOAuth2Response, refreshTokenGrantRequest, validateAuthResponse } from \"oauth4webapi\";\nimport { common, createAuthorizationServer, readLocal, removeLocal, saveLocal } from \"./common.js\";\nimport { throwIfError } from \"./throwIfError.js\";\n/**\n * @param client_id\n * @param url the base url of your foundry server\n * @param redirectUrl the url configured for redirect in the oauth configuration on the server\n * @param useHistory if true, when possible uses `history.replaceState()`, otherwise uses `window.location.assign()`\n * @param loginPage if you want a custom landing page prior to logging in, set this to that url\n * @param postLoginPage if you want to customize where you return to after a completed authentication cycle. defaults to the url when the page loaded\n * @param scopes\n * @param fetchFn\n * @param ctxPath\n * @returns {PublicOauthClient} which can be used as a token provider\n */\nexport function createPublicOauthClient(client_id, url, redirectUrl, useHistory, loginPage, postLoginPage = window.location.toString(), scopes = [\"api:read-data\", \"api:write-data\"], fetchFn = globalThis.fetch, ctxPath = \"/multipass\") {\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));\n async function go(x) {\n if (useHistory) return window.history.replaceState({}, \"\", x);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 } = readLocal(client);\n if (!refresh_token) {\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 return makeTokenAndSaveRefresh(throwIfError(await processAuthorizationCodeOAuth2Response(authServer, client, await refreshTokenGrantRequest(authServer, client, refresh_token, oauthHttpOptions))), \"refresh\");\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 codeVerifier,\n state,\n oldUrl\n } = readLocal(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)), redirectUrl, codeVerifier, oauthHttpOptions))), \"signIn\");\n 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 }\n }\n async function initiateLoginRedirect() {\n if (loginPage && window.location.href !== loginPage) {\n saveLocal(client, {\n oldUrl: postLoginPage\n });\n return await go(loginPage);\n }\n const state = generateRandomState();\n const codeVerifier = generateRandomCodeVerifier();\n const oldUrl = readLocal(client).oldUrl ?? window.location.toString();\n saveLocal(client, {\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: redirectUrl,\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}"]}
@@ -0,0 +1,14 @@
1
+ import type { Token } from "./Token.js";
2
+ export type Events = {
3
+ signIn: CustomEvent<Token>;
4
+ signOut: Event;
5
+ refresh: CustomEvent<Token>;
6
+ };
7
+ export interface BaseOauthClient<K extends keyof Events & string> {
8
+ (): Promise<string>;
9
+ signIn: () => Promise<Token>;
10
+ signOut: () => Promise<void>;
11
+ addEventListener: <T extends K>(type: T, listener: ((evt: Events[T]) => void) | null, options?: boolean | AddEventListenerOptions) => void;
12
+ removeEventListener: <T extends K>(type: T, callback: ((evt: Events[T]) => void) | null, options?: EventListenerOptions | boolean) => void;
13
+ }
14
+ //# sourceMappingURL=BaseOauthClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseOauthClient.d.ts","sourceRoot":"","sources":["../../src/BaseOauthClient.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,MAAM,MAAM,GAAG;IACnB,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;CAC7B,CAAC;AAEF,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM,MAAM,GAAG,MAAM;IAC9D,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAEpB,MAAM,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7B,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7B,gBAAgB,EAAE,CAAC,CAAC,SAAS,CAAC,EAC5B,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,GAAG,IAAI,EAC3C,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,KACxC,IAAI,CAAC;IAEV,mBAAmB,EAAE,CAAC,CAAC,SAAS,CAAC,EAC/B,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,GAAG,IAAI,EAC3C,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,KACrC,IAAI,CAAC;CACX"}
@@ -0,0 +1,4 @@
1
+ import type { BaseOauthClient } from "./BaseOauthClient.js";
2
+ export interface ConfidentialOauthClient extends BaseOauthClient<"signIn" | "signOut"> {
3
+ }
4
+ //# sourceMappingURL=ConfidentialOauthClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfidentialOauthClient.d.ts","sourceRoot":"","sources":["../../src/ConfidentialOauthClient.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,WAAW,uBACf,SAAQ,eAAe,CAAC,QAAQ,GAAG,SAAS,CAAC;CAE9C"}
@@ -0,0 +1,6 @@
1
+ import type { BaseOauthClient } from "./BaseOauthClient.js";
2
+ import type { Token } from "./Token.js";
3
+ export interface PublicOauthClient extends BaseOauthClient<"signIn" | "signOut" | "refresh"> {
4
+ refresh: () => Promise<Token | undefined>;
5
+ }
6
+ //# sourceMappingURL=PublicOauthClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PublicOauthClient.d.ts","sourceRoot":"","sources":["../../src/PublicOauthClient.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,WAAW,iBACf,SAAQ,eAAe,CAAC,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IAEzD,OAAO,EAAE,MAAM,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;CAC3C"}
@@ -0,0 +1,36 @@
1
+ import type { AuthorizationServer, Client, HttpRequestOptions, OAuth2TokenEndpointResponse } from "oauth4webapi";
2
+ import type { BaseOauthClient, Events } from "./BaseOauthClient.js";
3
+ import type { Token } from "./Token.js";
4
+ type LocalStorageState = {
5
+ refresh_token?: never;
6
+ codeVerifier?: never;
7
+ state?: never;
8
+ oldUrl: string;
9
+ } | {
10
+ refresh_token?: never;
11
+ codeVerifier: string;
12
+ state: string;
13
+ oldUrl: string;
14
+ } | {
15
+ refresh_token?: string;
16
+ codeVerifier?: never;
17
+ state?: never;
18
+ oldUrl?: never;
19
+ } | {
20
+ refresh_token?: never;
21
+ codeVerifier?: never;
22
+ state?: never;
23
+ oldUrl?: never;
24
+ };
25
+ export declare function saveLocal(client: Client, x: LocalStorageState): void;
26
+ export declare function removeLocal(client: Client): void;
27
+ export declare function readLocal(client: Client): LocalStorageState;
28
+ export declare function common<R extends undefined | (() => Promise<Token | undefined>)>(client: Client, as: AuthorizationServer, _signIn: () => Promise<Token>, oauthHttpOptions: HttpRequestOptions, refresh: R): {
29
+ getToken: BaseOauthClient<keyof Events & string> & {
30
+ refresh: R;
31
+ };
32
+ makeTokenAndSaveRefresh: (resp: OAuth2TokenEndpointResponse, type: "signIn" | "refresh") => Token;
33
+ };
34
+ export declare function createAuthorizationServer(ctxPath: string, url: string): Required<Pick<AuthorizationServer, "issuer" | "token_endpoint" | "authorization_endpoint" | "revocation_endpoint">>;
35
+ export {};
36
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +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,2BAA2B,EAC5B,MAAM,cAAc,CAAC;AAItB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEpE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AA0BxC,KAAK,iBAAiB,GAElB;IACA,aAAa,CAAC,EAAE,KAAK,CAAC;IACtB,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,GAEC;IACA,aAAa,CAAC,EAAE,KAAK,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,GAEC;IACA,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB,GACC;IACA,aAAa,CAAC,EAAE,KAAK,CAAC;IACtB,YAAY,CAAC,EAAE,KAAK,CAAC;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,QAGzC;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAM3D;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,CAkGA;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"}
@@ -0,0 +1,12 @@
1
+ import type { ConfidentialOauthClient } from "./ConfidentialOauthClient.js";
2
+ /**
3
+ * @param client_id
4
+ * @param client_secret
5
+ * @param url the base url of your foundry server
6
+ * @param scopes
7
+ * @param fetchFn
8
+ * @param ctxPath
9
+ * @returns which can be used as a token provider
10
+ */
11
+ export declare function createConfidentialOauthClient(client_id: string, client_secret: string, url: string, scopes?: string[], fetchFn?: typeof globalThis.fetch, ctxPath?: string): ConfidentialOauthClient;
12
+ //# sourceMappingURL=createConfidentialOauthClient.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPublicOauthClient.d.ts","sourceRoot":"","sources":["../../src/createPublicOauthClient.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAUhE;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,OAAO,EACpB,SAAS,CAAC,EAAE,MAAM,EAClB,aAAa,GAAE,MAAmC,EAClD,MAAM,GAAE,MAAM,EAAwC,EACtD,OAAO,GAAE,OAAO,UAAU,CAAC,KAAwB,EACnD,OAAO,GAAE,MAAqB,GAC7B,iBAAiB,CAiJnB"}
@@ -1,3 +1,4 @@
1
+ export { createConfidentialOauthClient } from "./createConfidentialOauthClient.js";
1
2
  export { createPublicOauthClient } from "./createPublicOauthClient.js";
2
3
  export type { PublicOauthClient } from "./PublicOauthClient.js";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC"}