@osdk/oauth 1.2.0-beta.1 → 1.2.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/build/browser/common.js +3 -2
- package/build/browser/common.js.map +1 -1
- package/build/browser/common.test.js +4 -3
- package/build/browser/common.test.js.map +1 -1
- package/build/browser/createConfidentialOauthClient.js +4 -3
- package/build/browser/createConfidentialOauthClient.js.map +1 -1
- package/build/browser/createPublicOauthClient.js +9 -6
- package/build/browser/createPublicOauthClient.js.map +1 -1
- package/build/browser/publicOauth.test.js +37 -9
- package/build/browser/publicOauth.test.js.map +1 -1
- package/build/browser/utils.js +1 -1
- package/build/browser/utils.js.map +1 -1
- package/build/cjs/index.cjs +54 -49
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +2 -2
- package/build/esm/common.js +3 -2
- package/build/esm/common.js.map +1 -1
- package/build/esm/common.test.js +4 -3
- package/build/esm/common.test.js.map +1 -1
- package/build/esm/createConfidentialOauthClient.js +4 -3
- package/build/esm/createConfidentialOauthClient.js.map +1 -1
- package/build/esm/createPublicOauthClient.js +9 -6
- package/build/esm/createPublicOauthClient.js.map +1 -1
- package/build/esm/publicOauth.test.js +37 -9
- package/build/esm/publicOauth.test.js.map +1 -1
- package/build/esm/utils.js +1 -1
- package/build/esm/utils.js.map +1 -1
- package/build/types/common.d.ts +2 -1
- package/build/types/common.d.ts.map +1 -1
- package/build/types/createConfidentialOauthClient.d.ts.map +1 -1
- package/build/types/createPublicOauthClient.d.ts +2 -2
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/utils.d.ts +2 -1
- package/build/types/utils.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -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
|
|
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":[]}
|
package/build/cjs/index.cjs
CHANGED
|
@@ -82,7 +82,7 @@ var LRU = class {
|
|
|
82
82
|
this.update(key, v);
|
|
83
83
|
return v;
|
|
84
84
|
}
|
|
85
|
-
return
|
|
85
|
+
return void 0;
|
|
86
86
|
}
|
|
87
87
|
has(key) {
|
|
88
88
|
return this.cache.has(key) || this._cache.has(key);
|
|
@@ -205,7 +205,7 @@ function getKeyAndKid(input) {
|
|
|
205
205
|
if (!(input?.key instanceof CryptoKey)) {
|
|
206
206
|
return {};
|
|
207
207
|
}
|
|
208
|
-
if (input.kid !==
|
|
208
|
+
if (input.kid !== void 0 && !validateString(input.kid)) {
|
|
209
209
|
throw new TypeError('"kid" must be a non-empty string');
|
|
210
210
|
}
|
|
211
211
|
return {
|
|
@@ -327,12 +327,12 @@ function assertClientSecret(clientSecret) {
|
|
|
327
327
|
return clientSecret;
|
|
328
328
|
}
|
|
329
329
|
function assertNoClientPrivateKey(clientAuthMethod, clientPrivateKey) {
|
|
330
|
-
if (clientPrivateKey !==
|
|
330
|
+
if (clientPrivateKey !== void 0) {
|
|
331
331
|
throw new TypeError(`"options.clientPrivateKey" property must not be provided when ${clientAuthMethod} client authentication method is used.`);
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
334
|
function assertNoClientSecret(clientAuthMethod, clientSecret) {
|
|
335
|
-
if (clientSecret !==
|
|
335
|
+
if (clientSecret !== void 0) {
|
|
336
336
|
throw new TypeError(`"client.client_secret" property must not be provided when ${clientAuthMethod} client authentication method is used.`);
|
|
337
337
|
}
|
|
338
338
|
}
|
|
@@ -341,7 +341,7 @@ async function clientAuthentication(as, client, body, headers, clientPrivateKey)
|
|
|
341
341
|
body.delete("client_assertion_type");
|
|
342
342
|
body.delete("client_assertion");
|
|
343
343
|
switch (client.token_endpoint_auth_method) {
|
|
344
|
-
case
|
|
344
|
+
case void 0:
|
|
345
345
|
case "client_secret_basic": {
|
|
346
346
|
assertNoClientPrivateKey("client_secret_basic", clientPrivateKey);
|
|
347
347
|
headers.set("authorization", clientSecretBasic(client.client_id, assertClientSecret(client.client_secret)));
|
|
@@ -355,7 +355,7 @@ async function clientAuthentication(as, client, body, headers, clientPrivateKey)
|
|
|
355
355
|
}
|
|
356
356
|
case "private_key_jwt": {
|
|
357
357
|
assertNoClientSecret("private_key_jwt", client.client_secret);
|
|
358
|
-
if (clientPrivateKey ===
|
|
358
|
+
if (clientPrivateKey === void 0) {
|
|
359
359
|
throw new TypeError('"options.clientPrivateKey" must be provided when "client.token_endpoint_auth_method" is "private_key_jwt"');
|
|
360
360
|
}
|
|
361
361
|
const {
|
|
@@ -402,7 +402,7 @@ async function dpopProofJwt(headers, options, url, htm, clockSkew2, accessToken)
|
|
|
402
402
|
if (!isPublicKey(publicKey)) {
|
|
403
403
|
throw new TypeError('"DPoP.publicKey" must be a public CryptoKey');
|
|
404
404
|
}
|
|
405
|
-
if (nonce !==
|
|
405
|
+
if (nonce !== void 0 && !validateString(nonce)) {
|
|
406
406
|
throw new TypeError('"DPoP.nonce" must be a non-empty string or undefined');
|
|
407
407
|
}
|
|
408
408
|
if (!publicKey.extractable) {
|
|
@@ -419,7 +419,7 @@ async function dpopProofJwt(headers, options, url, htm, clockSkew2, accessToken)
|
|
|
419
419
|
htm,
|
|
420
420
|
nonce,
|
|
421
421
|
htu: `${url.origin}${url.pathname}`,
|
|
422
|
-
ath:
|
|
422
|
+
ath: void 0
|
|
423
423
|
}, privateKey);
|
|
424
424
|
headers.set("dpop", proof);
|
|
425
425
|
}
|
|
@@ -468,7 +468,7 @@ function isOAuth2Error(input) {
|
|
|
468
468
|
if (typeof value !== "object" || Array.isArray(value) || value === null) {
|
|
469
469
|
return false;
|
|
470
470
|
}
|
|
471
|
-
return value.error !==
|
|
471
|
+
return value.error !== void 0;
|
|
472
472
|
}
|
|
473
473
|
async function authenticatedRequest(as, client, method, url, body, headers, options) {
|
|
474
474
|
await clientAuthentication(as, client, body, headers, options?.clientPrivateKey);
|
|
@@ -486,7 +486,7 @@ async function tokenEndpointRequest(as, client, grantType, parameters, options)
|
|
|
486
486
|
parameters.set("grant_type", grantType);
|
|
487
487
|
const headers = prepareHeaders(options?.headers);
|
|
488
488
|
headers.set("accept", "application/json");
|
|
489
|
-
if (options?.DPoP !==
|
|
489
|
+
if (options?.DPoP !== void 0) {
|
|
490
490
|
await dpopProofJwt(headers, options.DPoP, url, "POST", getClockSkew(client));
|
|
491
491
|
}
|
|
492
492
|
return authenticatedRequest(as, client, "POST", url, parameters, headers, options);
|
|
@@ -537,23 +537,23 @@ async function processGenericAccessTokenResponse(as, client, response, ignoreIdT
|
|
|
537
537
|
if (json.token_type !== "dpop" && json.token_type !== "bearer") {
|
|
538
538
|
throw new UnsupportedOperationError("unsupported `token_type` value");
|
|
539
539
|
}
|
|
540
|
-
if (json.expires_in !==
|
|
540
|
+
if (json.expires_in !== void 0 && (typeof json.expires_in !== "number" || json.expires_in <= 0)) {
|
|
541
541
|
throw new OPE('"response" body "expires_in" property must be a positive number');
|
|
542
542
|
}
|
|
543
|
-
if (!ignoreRefreshToken && json.refresh_token !==
|
|
543
|
+
if (!ignoreRefreshToken && json.refresh_token !== void 0 && !validateString(json.refresh_token)) {
|
|
544
544
|
throw new OPE('"response" body "refresh_token" property must be a non-empty string');
|
|
545
545
|
}
|
|
546
|
-
if (json.scope !==
|
|
546
|
+
if (json.scope !== void 0 && typeof json.scope !== "string") {
|
|
547
547
|
throw new OPE('"response" body "scope" property must be a string');
|
|
548
548
|
}
|
|
549
549
|
if (!ignoreIdToken) {
|
|
550
|
-
if (json.id_token !==
|
|
550
|
+
if (json.id_token !== void 0 && !validateString(json.id_token)) {
|
|
551
551
|
throw new OPE('"response" body "id_token" property must be a non-empty string');
|
|
552
552
|
}
|
|
553
553
|
if (json.id_token) {
|
|
554
554
|
const {
|
|
555
555
|
claims
|
|
556
|
-
} = await validateJwt(json.id_token, checkSigningAlgorithm.bind(
|
|
556
|
+
} = await validateJwt(json.id_token, checkSigningAlgorithm.bind(void 0, client.id_token_signed_response_alg, as.id_token_signing_alg_values_supported), noSignatureCheck, getClockSkew(client), getClockTolerance(client)).then(validatePresence.bind(void 0, ["aud", "exp", "iat", "iss", "sub"])).then(validateIssuer.bind(void 0, as.issuer)).then(validateAudience.bind(void 0, client.client_id));
|
|
557
557
|
if (Array.isArray(claims.aud) && claims.aud.length !== 1 && claims.azp !== client.client_id) {
|
|
558
558
|
throw new OPE('unexpected ID Token "azp" (authorized party) claim value');
|
|
559
559
|
}
|
|
@@ -626,7 +626,7 @@ var jwtClaimNames = {
|
|
|
626
626
|
};
|
|
627
627
|
function validatePresence(required, result) {
|
|
628
628
|
for (const claim of required) {
|
|
629
|
-
if (result.claims[claim] ===
|
|
629
|
+
if (result.claims[claim] === void 0) {
|
|
630
630
|
throw new OPE(`JWT "${claim}" (${jwtClaimNames[claim]}) claim missing`);
|
|
631
631
|
}
|
|
632
632
|
}
|
|
@@ -637,7 +637,7 @@ async function processAuthorizationCodeOAuth2Response(as, client, response) {
|
|
|
637
637
|
if (isOAuth2Error(result)) {
|
|
638
638
|
return result;
|
|
639
639
|
}
|
|
640
|
-
if (result.id_token !==
|
|
640
|
+
if (result.id_token !== void 0) {
|
|
641
641
|
if (typeof result.id_token === "string" && result.id_token.length) {
|
|
642
642
|
throw new OPE("Unexpected ID Token returned, use processAuthorizationCodeOpenIDResponse() for OpenID Connect callback processing");
|
|
643
643
|
}
|
|
@@ -681,7 +681,7 @@ async function processRevocationResponse(response) {
|
|
|
681
681
|
}
|
|
682
682
|
throw new OPE('"response" is not a conform Revocation Endpoint response');
|
|
683
683
|
}
|
|
684
|
-
return
|
|
684
|
+
return void 0;
|
|
685
685
|
}
|
|
686
686
|
function assertReadableResponse(response) {
|
|
687
687
|
if (response.bodyUsed) {
|
|
@@ -711,7 +711,7 @@ async function handleOAuthBodyError(response) {
|
|
|
711
711
|
} catch {
|
|
712
712
|
}
|
|
713
713
|
}
|
|
714
|
-
return
|
|
714
|
+
return void 0;
|
|
715
715
|
}
|
|
716
716
|
function checkRsaKeyAlgorithm(algorithm) {
|
|
717
717
|
if (typeof algorithm.modulusLength !== "number" || algorithm.modulusLength < 2048) {
|
|
@@ -786,7 +786,7 @@ async function validateJwt(jws, checkAlg, getKey, clockSkew2, clockTolerance2) {
|
|
|
786
786
|
throw new OPE("JWT Header must be a top level object");
|
|
787
787
|
}
|
|
788
788
|
checkAlg(header);
|
|
789
|
-
if (header.crit !==
|
|
789
|
+
if (header.crit !== void 0) {
|
|
790
790
|
throw new OPE('unexpected JWT "crit" header parameter');
|
|
791
791
|
}
|
|
792
792
|
const signature = b64u(encodedSignature);
|
|
@@ -811,7 +811,7 @@ async function validateJwt(jws, checkAlg, getKey, clockSkew2, clockTolerance2) {
|
|
|
811
811
|
throw new OPE("JWT Payload must be a top level object");
|
|
812
812
|
}
|
|
813
813
|
const now = epochTime() + clockSkew2;
|
|
814
|
-
if (claims.exp !==
|
|
814
|
+
if (claims.exp !== void 0) {
|
|
815
815
|
if (typeof claims.exp !== "number") {
|
|
816
816
|
throw new OPE('unexpected JWT "exp" (expiration time) claim type');
|
|
817
817
|
}
|
|
@@ -819,17 +819,17 @@ async function validateJwt(jws, checkAlg, getKey, clockSkew2, clockTolerance2) {
|
|
|
819
819
|
throw new OPE('unexpected JWT "exp" (expiration time) claim value, timestamp is <= now()');
|
|
820
820
|
}
|
|
821
821
|
}
|
|
822
|
-
if (claims.iat !==
|
|
822
|
+
if (claims.iat !== void 0) {
|
|
823
823
|
if (typeof claims.iat !== "number") {
|
|
824
824
|
throw new OPE('unexpected JWT "iat" (issued at) claim type');
|
|
825
825
|
}
|
|
826
826
|
}
|
|
827
|
-
if (claims.iss !==
|
|
827
|
+
if (claims.iss !== void 0) {
|
|
828
828
|
if (typeof claims.iss !== "string") {
|
|
829
829
|
throw new OPE('unexpected JWT "iss" (issuer) claim type');
|
|
830
830
|
}
|
|
831
831
|
}
|
|
832
|
-
if (claims.nbf !==
|
|
832
|
+
if (claims.nbf !== void 0) {
|
|
833
833
|
if (typeof claims.nbf !== "number") {
|
|
834
834
|
throw new OPE('unexpected JWT "nbf" (not before) claim type');
|
|
835
835
|
}
|
|
@@ -837,7 +837,7 @@ async function validateJwt(jws, checkAlg, getKey, clockSkew2, clockTolerance2) {
|
|
|
837
837
|
throw new OPE('unexpected JWT "nbf" (not before) claim value, timestamp is > now()');
|
|
838
838
|
}
|
|
839
839
|
}
|
|
840
|
-
if (claims.aud !==
|
|
840
|
+
if (claims.aud !== void 0) {
|
|
841
841
|
if (typeof claims.aud !== "string" && !Array.isArray(claims.aud)) {
|
|
842
842
|
throw new OPE('unexpected JWT "aud" (audience) claim type');
|
|
843
843
|
}
|
|
@@ -850,7 +850,7 @@ async function validateJwt(jws, checkAlg, getKey, clockSkew2, clockTolerance2) {
|
|
|
850
850
|
};
|
|
851
851
|
}
|
|
852
852
|
function checkSigningAlgorithm(client, issuer, header) {
|
|
853
|
-
if (client !==
|
|
853
|
+
if (client !== void 0) {
|
|
854
854
|
if (header.alg !== client) {
|
|
855
855
|
throw new OPE('unexpected JWT "alg" header parameter');
|
|
856
856
|
}
|
|
@@ -899,9 +899,9 @@ function validateAuthResponse(as, client, parameters, expectedState) {
|
|
|
899
899
|
throw new OPE('unexpected "iss" (issuer) response parameter value');
|
|
900
900
|
}
|
|
901
901
|
switch (expectedState) {
|
|
902
|
-
case
|
|
902
|
+
case void 0:
|
|
903
903
|
case expectNoState:
|
|
904
|
-
if (state !==
|
|
904
|
+
if (state !== void 0) {
|
|
905
905
|
throw new OPE('unexpected "state" response parameter encountered');
|
|
906
906
|
}
|
|
907
907
|
break;
|
|
@@ -911,7 +911,7 @@ function validateAuthResponse(as, client, parameters, expectedState) {
|
|
|
911
911
|
if (!validateString(expectedState)) {
|
|
912
912
|
throw new OPE('"expectedState" must be a non-empty string');
|
|
913
913
|
}
|
|
914
|
-
if (state ===
|
|
914
|
+
if (state === void 0) {
|
|
915
915
|
throw new OPE('response parameter "state" missing');
|
|
916
916
|
}
|
|
917
917
|
if (state !== expectedState) {
|
|
@@ -928,7 +928,7 @@ function validateAuthResponse(as, client, parameters, expectedState) {
|
|
|
928
928
|
}
|
|
929
929
|
const id_token = getURLSearchParameter(parameters, "id_token");
|
|
930
930
|
const token = getURLSearchParameter(parameters, "token");
|
|
931
|
-
if (id_token !==
|
|
931
|
+
if (id_token !== void 0 || token !== void 0) {
|
|
932
932
|
throw new UnsupportedOperationError("implicit and hybrid flows are not supported");
|
|
933
933
|
}
|
|
934
934
|
return brand(new URLSearchParams(parameters));
|
|
@@ -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) {
|
|
@@ -989,10 +989,11 @@ function common(client, as, _signIn, oauthHttpOptions, refresh, refreshTokenMark
|
|
|
989
989
|
expires_in,
|
|
990
990
|
access_token
|
|
991
991
|
} = resp;
|
|
992
|
-
!(expires_in != null) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false) : invariant2__default.default(false) :
|
|
992
|
+
!(expires_in != null) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false) : invariant2__default.default(false) : void 0;
|
|
993
993
|
saveLocal(client, {
|
|
994
994
|
refresh_token,
|
|
995
|
-
refreshTokenMarker
|
|
995
|
+
refreshTokenMarker,
|
|
996
|
+
requestedScopes: scopes
|
|
996
997
|
});
|
|
997
998
|
token = {
|
|
998
999
|
refresh_token,
|
|
@@ -1016,11 +1017,11 @@ function common(client, as, _signIn, oauthHttpOptions, refresh, refreshTokenMark
|
|
|
1016
1017
|
}
|
|
1017
1018
|
}
|
|
1018
1019
|
async function signOut() {
|
|
1019
|
-
!token ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "not signed in") : invariant2__default.default(false) :
|
|
1020
|
+
!token ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "not signed in") : invariant2__default.default(false) : void 0;
|
|
1020
1021
|
const result = await processRevocationResponse(await revocationRequest(as, client, token.access_token, oauthHttpOptions));
|
|
1021
1022
|
rmTimeout();
|
|
1022
1023
|
removeLocal(client);
|
|
1023
|
-
token =
|
|
1024
|
+
token = void 0;
|
|
1024
1025
|
throwIfError(result);
|
|
1025
1026
|
eventTarget.dispatchTypedEvent("signOut", new Event("signOut"));
|
|
1026
1027
|
}
|
|
@@ -1033,14 +1034,14 @@ function common(client, as, _signIn, oauthHttpOptions, refresh, refreshTokenMark
|
|
|
1033
1034
|
pendingSignIn = _signIn();
|
|
1034
1035
|
return await pendingSignIn;
|
|
1035
1036
|
} finally {
|
|
1036
|
-
pendingSignIn =
|
|
1037
|
+
pendingSignIn = void 0;
|
|
1037
1038
|
}
|
|
1038
1039
|
}
|
|
1039
1040
|
eventTarget.addEventListener("signIn", restartRefreshTimer);
|
|
1040
1041
|
eventTarget.addEventListener("refresh", restartRefreshTimer);
|
|
1041
1042
|
function getTokenOrUndefined() {
|
|
1042
1043
|
if (!token || Date.now() >= token.expires_at) {
|
|
1043
|
-
return
|
|
1044
|
+
return void 0;
|
|
1044
1045
|
}
|
|
1045
1046
|
return token?.access_token;
|
|
1046
1047
|
}
|
|
@@ -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,
|
|
1091
|
+
} = common(client, authServer, _signIn, oauthHttpOptions, void 0, void 0, joinedScopes);
|
|
1090
1092
|
async function _signIn() {
|
|
1091
1093
|
return makeTokenAndSaveRefresh(throwIfError(await processClientCredentialsResponse(authServer, client, await clientCredentialsGrantRequest(authServer, client, new URLSearchParams({
|
|
1092
|
-
scope:
|
|
1094
|
+
scope: joinedScopes
|
|
1093
1095
|
}), oauthHttpOptions))), "signIn");
|
|
1094
1096
|
}
|
|
1095
1097
|
return getToken;
|
|
@@ -1152,7 +1154,7 @@ var delay_default = delay;
|
|
|
1152
1154
|
function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {
|
|
1153
1155
|
let options = {};
|
|
1154
1156
|
if (typeof useHistory === "object") {
|
|
1155
|
-
!(!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) :
|
|
1157
|
+
!(!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;
|
|
1156
1158
|
options = useHistory;
|
|
1157
1159
|
} else {
|
|
1158
1160
|
options = {
|
|
@@ -1164,13 +1166,13 @@ function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPag
|
|
|
1164
1166
|
ctxPath
|
|
1165
1167
|
};
|
|
1166
1168
|
}
|
|
1167
|
-
!url ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "url is required") : invariant2__default.default(false) :
|
|
1168
|
-
!redirect_uri ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "redirectUrl is required") : invariant2__default.default(false) :
|
|
1169
|
+
!url ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "url is required") : invariant2__default.default(false) : void 0;
|
|
1170
|
+
!redirect_uri ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "redirectUrl is required") : invariant2__default.default(false) : void 0;
|
|
1169
1171
|
return {
|
|
1170
1172
|
useHistory: options.useHistory ?? true,
|
|
1171
1173
|
loginPage: options.loginPage,
|
|
1172
1174
|
postLoginPage: options.postLoginPage || window.location.toString(),
|
|
1173
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
1290
|
+
scope: `offline_access ${joinedScopes}`
|
|
1286
1291
|
})}`);
|
|
1287
1292
|
await delay_default(1e3);
|
|
1288
1293
|
throw new Error("Unable to redirect");
|