@osdk/oauth 1.2.0-beta.2 → 1.3.0-beta.1
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 +28 -0
- package/build/browser/createConfidentialOauthClient.js +1 -1
- package/build/browser/createConfidentialOauthClient.js.map +1 -1
- package/build/browser/createPublicOauthClient.js +1 -1
- package/build/browser/createPublicOauthClient.js.map +1 -1
- package/build/browser/publicOauth.test.js +3 -3
- 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 +41 -41
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +2 -2
- package/build/esm/createConfidentialOauthClient.js +1 -1
- package/build/esm/createConfidentialOauthClient.js.map +1 -1
- package/build/esm/createPublicOauthClient.js +1 -1
- package/build/esm/createPublicOauthClient.js.map +1 -1
- package/build/esm/publicOauth.test.js +3 -3
- 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/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/package.json +3 -3
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));
|
|
@@ -989,7 +989,7 @@ 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
995
|
refreshTokenMarker,
|
|
@@ -1017,11 +1017,11 @@ function common(client, as, _signIn, oauthHttpOptions, refresh, refreshTokenMark
|
|
|
1017
1017
|
}
|
|
1018
1018
|
}
|
|
1019
1019
|
async function signOut() {
|
|
1020
|
-
!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;
|
|
1021
1021
|
const result = await processRevocationResponse(await revocationRequest(as, client, token.access_token, oauthHttpOptions));
|
|
1022
1022
|
rmTimeout();
|
|
1023
1023
|
removeLocal(client);
|
|
1024
|
-
token =
|
|
1024
|
+
token = void 0;
|
|
1025
1025
|
throwIfError(result);
|
|
1026
1026
|
eventTarget.dispatchTypedEvent("signOut", new Event("signOut"));
|
|
1027
1027
|
}
|
|
@@ -1034,14 +1034,14 @@ function common(client, as, _signIn, oauthHttpOptions, refresh, refreshTokenMark
|
|
|
1034
1034
|
pendingSignIn = _signIn();
|
|
1035
1035
|
return await pendingSignIn;
|
|
1036
1036
|
} finally {
|
|
1037
|
-
pendingSignIn =
|
|
1037
|
+
pendingSignIn = void 0;
|
|
1038
1038
|
}
|
|
1039
1039
|
}
|
|
1040
1040
|
eventTarget.addEventListener("signIn", restartRefreshTimer);
|
|
1041
1041
|
eventTarget.addEventListener("refresh", restartRefreshTimer);
|
|
1042
1042
|
function getTokenOrUndefined() {
|
|
1043
1043
|
if (!token || Date.now() >= token.expires_at) {
|
|
1044
|
-
return
|
|
1044
|
+
return void 0;
|
|
1045
1045
|
}
|
|
1046
1046
|
return token?.access_token;
|
|
1047
1047
|
}
|
|
@@ -1075,7 +1075,7 @@ function createAuthorizationServer(ctxPath, url) {
|
|
|
1075
1075
|
}
|
|
1076
1076
|
|
|
1077
1077
|
// src/createConfidentialOauthClient.ts
|
|
1078
|
-
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") {
|
|
1079
1079
|
const client = {
|
|
1080
1080
|
client_id,
|
|
1081
1081
|
client_secret
|
|
@@ -1088,7 +1088,7 @@ function createConfidentialOauthClient(client_id, client_secret, url, scopes = [
|
|
|
1088
1088
|
const {
|
|
1089
1089
|
getToken,
|
|
1090
1090
|
makeTokenAndSaveRefresh
|
|
1091
|
-
} = common(client, authServer, _signIn, oauthHttpOptions,
|
|
1091
|
+
} = common(client, authServer, _signIn, oauthHttpOptions, void 0, void 0, joinedScopes);
|
|
1092
1092
|
async function _signIn() {
|
|
1093
1093
|
return makeTokenAndSaveRefresh(throwIfError(await processClientCredentialsResponse(authServer, client, await clientCredentialsGrantRequest(authServer, client, new URLSearchParams({
|
|
1094
1094
|
scope: joinedScopes
|
|
@@ -1154,7 +1154,7 @@ var delay_default = delay;
|
|
|
1154
1154
|
function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {
|
|
1155
1155
|
let options = {};
|
|
1156
1156
|
if (typeof useHistory === "object") {
|
|
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) :
|
|
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;
|
|
1158
1158
|
options = useHistory;
|
|
1159
1159
|
} else {
|
|
1160
1160
|
options = {
|
|
@@ -1166,13 +1166,13 @@ function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPag
|
|
|
1166
1166
|
ctxPath
|
|
1167
1167
|
};
|
|
1168
1168
|
}
|
|
1169
|
-
!url ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "url is required") : invariant2__default.default(false) :
|
|
1170
|
-
!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;
|
|
1171
1171
|
return {
|
|
1172
1172
|
useHistory: options.useHistory ?? true,
|
|
1173
1173
|
loginPage: options.loginPage,
|
|
1174
1174
|
postLoginPage: options.postLoginPage || window.location.toString(),
|
|
1175
|
-
joinedScopes: [...options.scopes ?? ["api:read-data", "api:write-data"]].sort().join(" "),
|
|
1175
|
+
joinedScopes: [...options.scopes ?? ["api:read-data", "api:write-data", "api:use-ontologies-read", "api:use-ontologies-write"]].sort().join(" "),
|
|
1176
1176
|
fetchFn: options.fetchFn ?? globalThis.fetch,
|
|
1177
1177
|
ctxPath: options.ctxPath ?? "multipass",
|
|
1178
1178
|
refreshTokenMarker: options.refreshTokenMarker
|