@osdk/oauth 1.2.0-beta.1 → 1.2.0-beta.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.
- package/CHANGELOG.md +6 -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 +3 -2
- package/build/browser/createConfidentialOauthClient.js.map +1 -1
- package/build/browser/createPublicOauthClient.js +8 -5
- 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 +15 -10
- package/build/cjs/index.cjs.map +1 -1
- 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 +3 -2
- package/build/esm/createConfidentialOauthClient.js.map +1 -1
- package/build/esm/createPublicOauthClient.js +8 -5
- 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/utils.d.ts +2 -1
- package/build/types/utils.d.ts.map +1 -1
- package/package.json +3 -3
package/build/cjs/index.cjs
CHANGED
|
@@ -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,
|
|
@@ -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:
|
|
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
|
-
|
|
1175
|
+
joinedScopes: [...options.scopes ?? ["api:read-data", "api:write-data"]].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");
|