@osdk/oauth 1.1.0 → 1.1.2

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 (35) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/browser/common.js +3 -2
  3. package/build/browser/common.js.map +1 -1
  4. package/build/browser/common.test.js +4 -3
  5. package/build/browser/common.test.js.map +1 -1
  6. package/build/browser/createConfidentialOauthClient.js +4 -3
  7. package/build/browser/createConfidentialOauthClient.js.map +1 -1
  8. package/build/browser/createPublicOauthClient.js +9 -6
  9. package/build/browser/createPublicOauthClient.js.map +1 -1
  10. package/build/browser/publicOauth.test.js +37 -9
  11. package/build/browser/publicOauth.test.js.map +1 -1
  12. package/build/browser/utils.js +1 -1
  13. package/build/browser/utils.js.map +1 -1
  14. package/build/cjs/index.cjs +16 -11
  15. package/build/cjs/index.cjs.map +1 -1
  16. package/build/cjs/index.d.cts +2 -2
  17. package/build/esm/common.js +3 -2
  18. package/build/esm/common.js.map +1 -1
  19. package/build/esm/common.test.js +4 -3
  20. package/build/esm/common.test.js.map +1 -1
  21. package/build/esm/createConfidentialOauthClient.js +4 -3
  22. package/build/esm/createConfidentialOauthClient.js.map +1 -1
  23. package/build/esm/createPublicOauthClient.js +9 -6
  24. package/build/esm/createPublicOauthClient.js.map +1 -1
  25. package/build/esm/publicOauth.test.js +37 -9
  26. package/build/esm/publicOauth.test.js.map +1 -1
  27. package/build/esm/utils.js +1 -1
  28. package/build/esm/utils.js.map +1 -1
  29. package/build/types/common.d.ts +2 -1
  30. package/build/types/common.d.ts.map +1 -1
  31. package/build/types/createConfidentialOauthClient.d.ts.map +1 -1
  32. package/build/types/createPublicOauthClient.d.ts +2 -2
  33. package/build/types/utils.d.ts +2 -1
  34. package/build/types/utils.d.ts.map +1 -1
  35. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["invariant","processOptionsAndAssignDefaults","url","redirect_uri","useHistory","loginPage","postLoginPage","scopes","fetchFn","ctxPath","options","process","env","NODE_ENV","window","location","toString","globalThis","fetch","refreshTokenMarker"],"sources":["utils.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 invariant from \"tiny-invariant\";\nimport type { PublicOauthClientOptions } from \"./createPublicOauthClient.js\";\n\ninterface ProcessedPublicOauthClientOptions\n extends\n Omit<Required<PublicOauthClientOptions>, \"loginPage\" | \"refreshTokenMarker\">\n{\n loginPage?: string;\n refreshTokenMarker?: string;\n}\n\nexport function processOptionsAndAssignDefaults(\n url: string,\n redirect_uri: string,\n useHistory?: boolean | PublicOauthClientOptions,\n loginPage?: string,\n postLoginPage?: string,\n scopes?: string[],\n fetchFn?: typeof globalThis.fetch,\n ctxPath?: string,\n): ProcessedPublicOauthClientOptions {\n let options: PublicOauthClientOptions = {};\n\n if (typeof useHistory === \"object\") {\n invariant(\n !loginPage && !postLoginPage && !scopes && !fetchFn && !ctxPath,\n \"If useHistory is an object, other options should not be provided\",\n );\n options = useHistory;\n } else {\n options = {\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n };\n }\n\n invariant(url, \"url is required\");\n invariant(redirect_uri, \"redirectUrl is required\");\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.refresh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AK;IAC5CT,OAAO,EAAEC,OAAO,CAACD,OAAO,IAAI,WAAW;IACvCU,kBAAkB,EAAET,OAAO,CAACS;EAC9B,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"utils.js","names":["invariant","processOptionsAndAssignDefaults","url","redirect_uri","useHistory","loginPage","postLoginPage","scopes","fetchFn","ctxPath","options","process","env","NODE_ENV","window","location","toString","joinedScopes","sort","join","globalThis","fetch","refreshTokenMarker"],"sources":["utils.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 invariant from \"tiny-invariant\";\nimport type { PublicOauthClientOptions } from \"./createPublicOauthClient.js\";\n\ninterface ProcessedPublicOauthClientOptions extends\n Omit<\n Required<PublicOauthClientOptions>,\n \"loginPage\" | \"refreshTokenMarker\" | \"scopes\"\n >\n{\n loginPage?: string;\n refreshTokenMarker?: string;\n joinedScopes: string;\n}\n\nexport function processOptionsAndAssignDefaults(\n url: string,\n redirect_uri: string,\n useHistory?: boolean | PublicOauthClientOptions,\n loginPage?: string,\n postLoginPage?: string,\n scopes?: string[],\n fetchFn?: typeof globalThis.fetch,\n ctxPath?: string,\n): ProcessedPublicOauthClientOptions {\n let options: PublicOauthClientOptions = {};\n\n if (typeof useHistory === \"object\") {\n invariant(\n !loginPage && !postLoginPage && !scopes && !fetchFn && !ctxPath,\n \"If useHistory is an object, other options should not be provided\",\n );\n options = useHistory;\n } else {\n options = {\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n };\n }\n\n invariant(url, \"url is required\");\n invariant(redirect_uri, \"redirectUrl is required\");\n\n // Assign defaults\n return {\n useHistory: options.useHistory ?? true,\n loginPage: options.loginPage,\n postLoginPage: options.postLoginPage || window.location.toString(),\n joinedScopes: [\n ...options.scopes\n ?? [\n \"api:read-data\",\n \"api:write-data\",\n \"api:use-ontologies-read\",\n \"api:use-ontologies-write\",\n ],\n ]\n .sort().join(\" \"),\n fetchFn: options.fetchFn ?? globalThis.fetch,\n ctxPath: options.ctxPath ?? \"multipass\",\n refreshTokenMarker: options.refreshTokenMarker,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AActC,OAAO,SAASC,+BAA+BA,CAC7CC,GAAW,EACXC,YAAoB,EACpBC,UAA+C,EAC/CC,SAAkB,EAClBC,aAAsB,EACtBC,MAAiB,EACjBC,OAAiC,EACjCC,OAAgB,EACmB;EACnC,IAAIC,OAAiC,GAAG,CAAC,CAAC;EAE1C,IAAI,OAAON,UAAU,KAAK,QAAQ,EAAE;IAClC,EACE,CAACC,SAAS,IAAI,CAACC,aAAa,IAAI,CAACC,MAAM,IAAI,CAACC,OAAO,IAAI,CAACC,OAAO,IAAAE,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBADjEb,SAAS,QAEP,kEAAkE,IAFpEA,SAAS;IAITU,OAAO,GAAGN,UAAU;EACtB,CAAC,MAAM;IACLM,OAAO,GAAG;MACRN,UAAU;MACVC,SAAS;MACTC,aAAa;MACbC,MAAM;MACNC,OAAO;MACPC;IACF,CAAC;EACH;EAEA,CAAUP,GAAG,GAAAS,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAbb,SAAS,QAAM,iBAAiB,IAAhCA,SAAS;EACT,CAAUG,YAAY,GAAAQ,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAtBb,SAAS,QAAe,yBAAyB,IAAjDA,SAAS;;EAET;EACA,OAAO;IACLI,UAAU,EAAEM,OAAO,CAACN,UAAU,IAAI,IAAI;IACtCC,SAAS,EAAEK,OAAO,CAACL,SAAS;IAC5BC,aAAa,EAAEI,OAAO,CAACJ,aAAa,IAAIQ,MAAM,CAACC,QAAQ,CAACC,QAAQ,CAAC,CAAC;IAClEC,YAAY,EAAE,CACZ,IAAGP,OAAO,CAACH,MAAM,IACZ,CACD,eAAe,EACf,gBAAgB,EAChB,yBAAyB,EACzB,0BAA0B,CAC3B,EACJ,CACEW,IAAI,CAAC,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;IACnBX,OAAO,EAAEE,OAAO,CAACF,OAAO,IAAIY,UAAU,CAACC,KAAK;IAC5CZ,OAAO,EAAEC,OAAO,CAACD,OAAO,IAAI,WAAW;IACvCa,kBAAkB,EAAEZ,OAAO,CAACY;EAC9B,CAAC;AACH","ignoreList":[]}
@@ -980,7 +980,7 @@ function readSession(client) {
980
980
  globalThis.sessionStorage?.getItem(localStorageKey(client)) ?? "{}"
981
981
  );
982
982
  }
983
- function common(client, as, _signIn, oauthHttpOptions, refresh, refreshTokenMarker) {
983
+ function common(client, as, _signIn, oauthHttpOptions, refresh, refreshTokenMarker, scopes) {
984
984
  let token;
985
985
  const eventTarget = new typescriptEventTarget.TypedEventTarget();
986
986
  function makeTokenAndSaveRefresh(resp, type) {
@@ -992,7 +992,8 @@ function common(client, as, _signIn, oauthHttpOptions, refresh, refreshTokenMark
992
992
  !(expires_in != null) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false) : invariant2__default.default(false) : undefined;
993
993
  saveLocal(client, {
994
994
  refresh_token,
995
- refreshTokenMarker
995
+ refreshTokenMarker,
996
+ requestedScopes: scopes
996
997
  });
997
998
  token = {
998
999
  refresh_token,
@@ -1074,7 +1075,7 @@ function createAuthorizationServer(ctxPath, url) {
1074
1075
  }
1075
1076
 
1076
1077
  // src/createConfidentialOauthClient.ts
1077
- function createConfidentialOauthClient(client_id, client_secret, url, scopes = ["api:read-data", "api:write-data"], fetchFn = globalThis.fetch, ctxPath = "multipass") {
1078
+ function createConfidentialOauthClient(client_id, client_secret, url, scopes = ["api:read-data", "api:write-data", "api:use-ontologies-read", "api:use-ontologies-write"], fetchFn = globalThis.fetch, ctxPath = "multipass") {
1078
1079
  const client = {
1079
1080
  client_id,
1080
1081
  client_secret
@@ -1083,13 +1084,14 @@ function createConfidentialOauthClient(client_id, client_secret, url, scopes = [
1083
1084
  const oauthHttpOptions = {
1084
1085
  [customFetch]: fetchFn
1085
1086
  };
1087
+ const joinedScopes = scopes.join(" ");
1086
1088
  const {
1087
1089
  getToken,
1088
1090
  makeTokenAndSaveRefresh
1089
- } = common(client, authServer, _signIn, oauthHttpOptions, undefined, undefined);
1091
+ } = common(client, authServer, _signIn, oauthHttpOptions, undefined, undefined, joinedScopes);
1090
1092
  async function _signIn() {
1091
1093
  return makeTokenAndSaveRefresh(throwIfError(await processClientCredentialsResponse(authServer, client, await clientCredentialsGrantRequest(authServer, client, new URLSearchParams({
1092
- scope: scopes.join(" ")
1094
+ scope: joinedScopes
1093
1095
  }), oauthHttpOptions))), "signIn");
1094
1096
  }
1095
1097
  return getToken;
@@ -1170,7 +1172,7 @@ function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPag
1170
1172
  useHistory: options.useHistory ?? true,
1171
1173
  loginPage: options.loginPage,
1172
1174
  postLoginPage: options.postLoginPage || window.location.toString(),
1173
- scopes: options.scopes ?? ["api:read-data", "api:write-data"],
1175
+ joinedScopes: [...options.scopes ?? ["api:read-data", "api:write-data", "api:use-ontologies-read", "api:use-ontologies-write"]].sort().join(" "),
1174
1176
  fetchFn: options.fetchFn ?? globalThis.fetch,
1175
1177
  ctxPath: options.ctxPath ?? "multipass",
1176
1178
  refreshTokenMarker: options.refreshTokenMarker
@@ -1180,11 +1182,12 @@ function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPag
1180
1182
  // src/createPublicOauthClient.ts
1181
1183
  function createPublicOauthClient(client_id, url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {
1182
1184
  let refreshTokenMarker;
1185
+ let joinedScopes;
1183
1186
  ({
1184
1187
  useHistory,
1185
1188
  loginPage,
1186
1189
  postLoginPage,
1187
- scopes,
1190
+ joinedScopes,
1188
1191
  fetchFn,
1189
1192
  ctxPath,
1190
1193
  refreshTokenMarker
@@ -1200,7 +1203,7 @@ function createPublicOauthClient(client_id, url, redirect_uri, useHistory, login
1200
1203
  const {
1201
1204
  makeTokenAndSaveRefresh,
1202
1205
  getToken
1203
- } = common(client, authServer, _signIn, oauthHttpOptions, maybeRefresh.bind(globalThis, true), refreshTokenMarker);
1206
+ } = common(client, authServer, _signIn, oauthHttpOptions, maybeRefresh.bind(globalThis, true), refreshTokenMarker, joinedScopes);
1204
1207
  const go = async (x) => {
1205
1208
  if (useHistory) {
1206
1209
  window.history.replaceState({}, "", x);
@@ -1212,9 +1215,11 @@ function createPublicOauthClient(client_id, url, redirect_uri, useHistory, login
1212
1215
  async function maybeRefresh(expectRefreshToken) {
1213
1216
  const {
1214
1217
  refresh_token,
1215
- refreshTokenMarker: lastRefreshTokenMarker
1218
+ refreshTokenMarker: lastRefreshTokenMarker,
1219
+ requestedScopes: initialRequestedScopes
1216
1220
  } = readLocal(client);
1217
- if (!refresh_token || lastRefreshTokenMarker !== refreshTokenMarker) {
1221
+ const areScopesEqual = initialRequestedScopes != null && joinedScopes === initialRequestedScopes;
1222
+ if (!refresh_token || lastRefreshTokenMarker !== refreshTokenMarker || !areScopesEqual) {
1218
1223
  if (expectRefreshToken) throw new Error("No refresh token found");
1219
1224
  return;
1220
1225
  }
@@ -1282,7 +1287,7 @@ function createPublicOauthClient(client_id, url, redirect_uri, useHistory, login
1282
1287
  redirect_uri,
1283
1288
  code_challenge: await calculatePKCECodeChallenge(codeVerifier),
1284
1289
  code_challenge_method: "S256",
1285
- scope: ["offline_access", ...scopes].join(" ")
1290
+ scope: `offline_access ${joinedScopes}`
1286
1291
  })}`);
1287
1292
  await delay_default(1e3);
1288
1293
  throw new Error("Unable to redirect");