@inrupt/solid-client-authn-browser 1.17.5 → 2.1.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.
- package/dist/ClientAuthentication.d.ts +1 -0
- package/dist/Session.d.ts +4 -67
- package/dist/defaultSession.d.ts +0 -28
- package/dist/dependencies.d.ts +1 -2
- package/dist/index.d.ts +2 -3
- package/dist/index.js +40 -153
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -143
- package/dist/index.mjs.map +1 -1
- package/dist/login/oidc/__mocks__/IOidcOptions.d.ts +2 -0
- package/dist/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.d.ts +4 -0
- package/dist/solid-client-authn.bundle.js +19 -19
- package/dist/solid-client-authn.bundle.js.map +1 -1
- package/package.json +7 -8
- package/rollup.config.mjs +28 -14
- package/src/ClientAuthentication.spec.ts +1 -13
- package/src/Session.spec.ts +11 -178
- package/src/Session.ts +6 -98
- package/src/defaultSession.spec.ts +0 -18
- package/src/defaultSession.ts +0 -40
- package/src/dependencies.ts +1 -2
- package/src/index.spec.ts +1 -2
- package/src/index.ts +9 -3
- package/src/login/oidc/ClientRegistrar.spec.ts +9 -9
- package/src/login/oidc/ClientRegistrar.ts +15 -8
- package/src/login/oidc/IssuerConfigFetcher.spec.ts +17 -32
- package/src/login/oidc/IssuerConfigFetcher.ts +1 -5
- package/src/login/oidc/OidcLoginHandler.spec.ts +6 -3
- package/src/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.spec.ts +28 -42
- package/src/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.ts +18 -34
- package/src/login/oidc/incomingRedirectHandler/ErrorOidcHandler.spec.ts +0 -11
- package/src/login/oidc/incomingRedirectHandler/FallbackRedirectHandler.spec.ts +1 -12
- package/src/login/oidc/oidcHandlers/AuthorizationCodeWithPkceOidcHandler.spec.ts +1 -0
- package/src/login/oidc/oidcHandlers/AuthorizationCodeWithPkceOidcHandler.ts +1 -2
- package/.prettierignore +0 -3
- package/sampleFlows/SolidAuthClientArchitecture.png +0 -0
- package/sampleFlows/authorization-code-with-pkce.png +0 -0
- package/sampleFlows/authorization-code-with-pkce.seqdiag +0 -46
- package/sampleFlows/authorization-code.png +0 -0
- package/sampleFlows/authorization-code.seqdiag +0 -50
- package/sampleFlows/client-credentials.png +0 -0
- package/sampleFlows/client-credentials.seqdiag +0 -38
- package/sampleFlows/legacy-implicit-flow.png +0 -0
- package/sampleFlows/legacy-implicit-flow.seqdiag +0 -43
- package/sampleFlows/self-signed.png +0 -0
- package/sampleFlows/self-signed.seqdiag +0 -49
- package/sampleFlows/signatory-access-control.seqdiag +0 -36
- package/sampleFlows/signatory-access-control.svg +0 -1
- package/sonar-project.properties +0 -15
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { StorageUtility, ClientAuthentication as ClientAuthentication$1, isValidRedirectUrl, EVENTS, removeOpenIdParams, ConfigurationError, handleRegistration, AuthorizationCodeWithPkceOidcHandlerBase, DEFAULT_SCOPES, SessionInfoManagerBase, isSupportedTokenType, clear as clear$1, getUnauthenticatedSession, loadOidcContextFromStorage, buildAuthenticatedFetch, maybeBuildRpInitiatedLogout, AggregateHandler, InMemoryStorage, IWaterfallLogoutHandler, SOLID_CLIENT_AUTHN_KEY_PREFIX
|
|
1
|
+
import { StorageUtility, ClientAuthentication as ClientAuthentication$1, isValidRedirectUrl, EVENTS, removeOpenIdParams, ConfigurationError, handleRegistration, AuthorizationCodeWithPkceOidcHandlerBase, DEFAULT_SCOPES, SessionInfoManagerBase, isSupportedTokenType, clear as clear$1, getUnauthenticatedSession, loadOidcContextFromStorage, buildAuthenticatedFetch, maybeBuildRpInitiatedLogout, AggregateHandler, isKnownClientType, InMemoryStorage, IWaterfallLogoutHandler, SOLID_CLIENT_AUTHN_KEY_PREFIX } from '@inrupt/solid-client-authn-core';
|
|
2
2
|
export { ConfigurationError, EVENTS, InMemoryStorage, NotImplementedError } from '@inrupt/solid-client-authn-core';
|
|
3
3
|
import { v4 } from 'uuid';
|
|
4
4
|
import EventEmitter from 'events';
|
|
5
|
-
import { normalizeCallbackUrl, OidcClient, clearOidcPersistentStorage,
|
|
6
|
-
import { fetch as fetch$1 } from '@inrupt/universal-fetch';
|
|
5
|
+
import { normalizeCallbackUrl, OidcClient, clearOidcPersistentStorage, getTokens, registerClient, refresh } from '@inrupt/oidc-client-ext';
|
|
7
6
|
|
|
8
7
|
//
|
|
9
8
|
// Copyright Inrupt Inc.
|
|
@@ -264,8 +263,7 @@ class AuthorizationCodeWithPkceOidcHandler extends AuthorizationCodeWithPkceOidc
|
|
|
264
263
|
authority: oidcLoginOptions.issuer.toString(),
|
|
265
264
|
client_id: oidcLoginOptions.client.clientId,
|
|
266
265
|
client_secret: oidcLoginOptions.client.clientSecret,
|
|
267
|
-
redirect_uri: oidcLoginOptions.redirectUrl
|
|
268
|
-
post_logout_redirect_uri: oidcLoginOptions.redirectUrl.toString(),
|
|
266
|
+
redirect_uri: oidcLoginOptions.redirectUrl,
|
|
269
267
|
response_type: "code",
|
|
270
268
|
scope: DEFAULT_SCOPES,
|
|
271
269
|
filterProtocolClaims: true,
|
|
@@ -444,7 +442,7 @@ class IssuerConfigFetcher {
|
|
|
444
442
|
// Make sure to append a slash at issuer URL, so that the .well-known URL
|
|
445
443
|
// includes the full issuer path. See https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig.
|
|
446
444
|
issuer.endsWith("/") ? issuer : `${issuer}/`).href;
|
|
447
|
-
const issuerConfigRequestBody = await fetch
|
|
445
|
+
const issuerConfigRequestBody = await fetch(openIdConfigUrl);
|
|
448
446
|
// Check the validity of the fetched config
|
|
449
447
|
try {
|
|
450
448
|
issuerConfig = processConfig(await issuerConfigRequestBody.json());
|
|
@@ -626,14 +624,6 @@ class FallbackRedirectHandler {
|
|
|
626
624
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
627
625
|
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
628
626
|
//
|
|
629
|
-
/**
|
|
630
|
-
* @hidden
|
|
631
|
-
* @packageDocumentation
|
|
632
|
-
*/
|
|
633
|
-
// FIXME: The following doesn't work in the browser, it results in all the fetches
|
|
634
|
-
// being unauthenticated. This should be looked into when migrating to universal-fetch.
|
|
635
|
-
// import { fetch } from "cross-fetch";
|
|
636
|
-
const globalFetch = (...args) => fetch$1.call(globalThis, ...args);
|
|
637
627
|
/**
|
|
638
628
|
* @hidden
|
|
639
629
|
*/
|
|
@@ -681,25 +671,18 @@ class AuthCodeRedirectHandler {
|
|
|
681
671
|
throw new Error(`The redirect URL for session ${storedSessionId} is missing from storage.`);
|
|
682
672
|
}
|
|
683
673
|
const client = await this.clientRegistrar.getClient({ sessionId: storedSessionId }, issuerConfig);
|
|
684
|
-
let tokens;
|
|
685
674
|
const tokenCreatedAt = Date.now();
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
// binding uses our custom code, this needs to be done manually.
|
|
698
|
-
window.localStorage.removeItem(`oidc.${oauthState}`);
|
|
699
|
-
}
|
|
700
|
-
else {
|
|
701
|
-
tokens = await getBearerToken(url.toString());
|
|
702
|
-
}
|
|
675
|
+
const tokens = await getTokens(issuerConfig, client, {
|
|
676
|
+
grantType: "authorization_code",
|
|
677
|
+
// We rely on our 'canHandle' function checking that the OAuth 'code'
|
|
678
|
+
// parameter is present in our query string.
|
|
679
|
+
code: url.searchParams.get("code"),
|
|
680
|
+
codeVerifier,
|
|
681
|
+
redirectUrl: storedRedirectIri,
|
|
682
|
+
}, isDpop);
|
|
683
|
+
// Delete oidc-client-specific session information from storage. oidc-client
|
|
684
|
+
// is no longer used for the token exchange, so it doesn't perform this automatically.
|
|
685
|
+
window.localStorage.removeItem(`oidc.${oauthState}`);
|
|
703
686
|
let refreshOptions;
|
|
704
687
|
if (tokens.refreshToken !== undefined) {
|
|
705
688
|
refreshOptions = {
|
|
@@ -708,7 +691,7 @@ class AuthCodeRedirectHandler {
|
|
|
708
691
|
tokenRefresher: this.tokerRefresher,
|
|
709
692
|
};
|
|
710
693
|
}
|
|
711
|
-
const authFetch = await buildAuthenticatedFetch(
|
|
694
|
+
const authFetch = await buildAuthenticatedFetch(tokens.accessToken, {
|
|
712
695
|
dpopKey: tokens.dpopKey,
|
|
713
696
|
refreshOptions,
|
|
714
697
|
eventEmitter,
|
|
@@ -869,25 +852,27 @@ class ClientRegistrar {
|
|
|
869
852
|
}
|
|
870
853
|
async getClient(options, issuerConfig) {
|
|
871
854
|
// If client secret and/or client id are stored in storage, use those.
|
|
872
|
-
const [storedClientId, storedClientSecret,
|
|
873
|
-
// storedClientName,
|
|
874
|
-
] = await Promise.all([
|
|
855
|
+
const [storedClientId, storedClientSecret, storedClientName, storedClientType,] = await Promise.all([
|
|
875
856
|
this.storageUtility.getForUser(options.sessionId, "clientId", {
|
|
876
857
|
secure: false,
|
|
877
858
|
}),
|
|
878
859
|
this.storageUtility.getForUser(options.sessionId, "clientSecret", {
|
|
879
860
|
secure: false,
|
|
880
861
|
}),
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
862
|
+
this.storageUtility.getForUser(options.sessionId, "clientName", {
|
|
863
|
+
secure: false,
|
|
864
|
+
}),
|
|
865
|
+
this.storageUtility.getForUser(options.sessionId, "clientType", {
|
|
866
|
+
secure: false,
|
|
867
|
+
}),
|
|
885
868
|
]);
|
|
886
|
-
if (storedClientId) {
|
|
869
|
+
if (storedClientId && isKnownClientType(storedClientType)) {
|
|
887
870
|
return {
|
|
888
871
|
clientId: storedClientId,
|
|
889
872
|
clientSecret: storedClientSecret,
|
|
890
|
-
|
|
873
|
+
clientName: storedClientName,
|
|
874
|
+
// Note: static clients are not applicable in a browser context.
|
|
875
|
+
clientType: storedClientType,
|
|
891
876
|
};
|
|
892
877
|
}
|
|
893
878
|
try {
|
|
@@ -895,6 +880,7 @@ class ClientRegistrar {
|
|
|
895
880
|
// Save info
|
|
896
881
|
const infoToSave = {
|
|
897
882
|
clientId: registeredClient.clientId,
|
|
883
|
+
clientType: "dynamic",
|
|
898
884
|
};
|
|
899
885
|
if (registeredClient.clientSecret) {
|
|
900
886
|
infoToSave.clientSecret = registeredClient.clientSecret;
|
|
@@ -1042,9 +1028,8 @@ class TokenRefresher {
|
|
|
1042
1028
|
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1043
1029
|
//
|
|
1044
1030
|
/**
|
|
1045
|
-
*
|
|
1046
1031
|
* @param dependencies
|
|
1047
|
-
* @
|
|
1032
|
+
* @hidden
|
|
1048
1033
|
*/
|
|
1049
1034
|
function getClientAuthenticationWithDependencies(dependencies) {
|
|
1050
1035
|
const inMemoryStorage = new InMemoryStorage();
|
|
@@ -1139,7 +1124,7 @@ function isLoggedIn(sessionInfo) {
|
|
|
1139
1124
|
/**
|
|
1140
1125
|
* A {@link Session} object represents a user's session on an application. The session holds state, as it stores information enabling acces to private resources after login for instance.
|
|
1141
1126
|
*/
|
|
1142
|
-
class Session
|
|
1127
|
+
class Session {
|
|
1143
1128
|
/**
|
|
1144
1129
|
* Session object constructor. Typically called as follows:
|
|
1145
1130
|
*
|
|
@@ -1156,7 +1141,6 @@ class Session extends EventEmitter {
|
|
|
1156
1141
|
*
|
|
1157
1142
|
*/
|
|
1158
1143
|
constructor(sessionOptions = {}, sessionId = undefined) {
|
|
1159
|
-
super();
|
|
1160
1144
|
this.tokenRequestInProgress = false;
|
|
1161
1145
|
/**
|
|
1162
1146
|
* Triggers the login process. Note that this method will redirect the user away from your app.
|
|
@@ -1247,7 +1231,7 @@ class Session extends EventEmitter {
|
|
|
1247
1231
|
* Completes the login process by processing the information provided by the
|
|
1248
1232
|
* Solid identity provider through redirect.
|
|
1249
1233
|
*
|
|
1250
|
-
* @param options See {@
|
|
1234
|
+
* @param options See {@link IHandleIncomingRedirectOptions}.
|
|
1251
1235
|
*/
|
|
1252
1236
|
this.handleIncomingRedirect = async (inputOptions = {}) => {
|
|
1253
1237
|
var _a;
|
|
@@ -1300,11 +1284,7 @@ class Session extends EventEmitter {
|
|
|
1300
1284
|
this.tokenRequestInProgress = false;
|
|
1301
1285
|
return sessionInfo;
|
|
1302
1286
|
};
|
|
1303
|
-
|
|
1304
|
-
// to this (with some interface filtering). When we make the breaking change,
|
|
1305
|
-
// this.events will be a regular EventEmitter (implementing ISessionEventEmitter):
|
|
1306
|
-
// this.events = new EventEmitter();
|
|
1307
|
-
this.events = new Proxy(this, buildProxyHandler(Session.prototype, "events only implements ISessionEventListener"));
|
|
1287
|
+
this.events = new EventEmitter();
|
|
1308
1288
|
if (sessionOptions.clientAuthentication) {
|
|
1309
1289
|
this.clientAuthentication = sessionOptions.clientAuthentication;
|
|
1310
1290
|
}
|
|
@@ -1338,58 +1318,6 @@ class Session extends EventEmitter {
|
|
|
1338
1318
|
this.events.on(EVENTS.SESSION_EXPIRED, () => this.internalLogout(false));
|
|
1339
1319
|
this.events.on(EVENTS.ERROR, () => this.internalLogout(false));
|
|
1340
1320
|
}
|
|
1341
|
-
/**
|
|
1342
|
-
* Register a callback function to be called when a user completes login.
|
|
1343
|
-
*
|
|
1344
|
-
* The callback is called when {@link handleIncomingRedirect} completes successfully.
|
|
1345
|
-
*
|
|
1346
|
-
* @param callback The function called when a user completes login.
|
|
1347
|
-
* @deprecated Prefer session.events.on(EVENTS.LOGIN, callback)
|
|
1348
|
-
*/
|
|
1349
|
-
onLogin(callback) {
|
|
1350
|
-
this.events.on(EVENTS.LOGIN, callback);
|
|
1351
|
-
}
|
|
1352
|
-
/**
|
|
1353
|
-
* Register a callback function to be called when a user logs out:
|
|
1354
|
-
*
|
|
1355
|
-
* @param callback The function called when a user completes logout.
|
|
1356
|
-
* @deprecated Prefer session.events.on(EVENTS.LOGOUT, callback)
|
|
1357
|
-
*/
|
|
1358
|
-
onLogout(callback) {
|
|
1359
|
-
this.events.on(EVENTS.LOGOUT, callback);
|
|
1360
|
-
}
|
|
1361
|
-
/**
|
|
1362
|
-
* Register a callback function to be called when a user logs out:
|
|
1363
|
-
*
|
|
1364
|
-
* @param callback The function called when an error occurs.
|
|
1365
|
-
* @since 1.11.0
|
|
1366
|
-
* @deprecated Prefer session.events.on(EVENTS.ERROR, callback)
|
|
1367
|
-
*/
|
|
1368
|
-
onError(callback) {
|
|
1369
|
-
this.events.on(EVENTS.ERROR, callback);
|
|
1370
|
-
}
|
|
1371
|
-
/**
|
|
1372
|
-
* Register a callback function to be called when a session is restored.
|
|
1373
|
-
*
|
|
1374
|
-
* Note: the callback will be called with the saved value of the 'current URL'
|
|
1375
|
-
* at the time the session was restored.
|
|
1376
|
-
*
|
|
1377
|
-
* @param callback The function called when a user's already logged-in session is restored, e.g., after a silent authentication is completed after a page refresh.
|
|
1378
|
-
* @deprecated Prefer session.events.on(EVENTS.SESSION_RESTORED, callback)
|
|
1379
|
-
*/
|
|
1380
|
-
onSessionRestore(callback) {
|
|
1381
|
-
this.events.on(EVENTS.SESSION_RESTORED, callback);
|
|
1382
|
-
}
|
|
1383
|
-
/**
|
|
1384
|
-
* Register a callback that runs when the session expires and can no longer
|
|
1385
|
-
* make authenticated requests, but following a user logout.
|
|
1386
|
-
* @param callback The function that runs on session expiration.
|
|
1387
|
-
* @since 1.11.0
|
|
1388
|
-
* @deprecated Prefer session.events.on(EVENTS.SESSION_EXPIRED, callback)
|
|
1389
|
-
*/
|
|
1390
|
-
onSessionExpiration(callback) {
|
|
1391
|
-
this.events.on(EVENTS.SESSION_EXPIRED, callback);
|
|
1392
|
-
}
|
|
1393
1321
|
setSessionInfo(sessionInfo) {
|
|
1394
1322
|
this.info.isLoggedIn = sessionInfo.isLoggedIn;
|
|
1395
1323
|
this.info.webId = sessionInfo.webId;
|
|
@@ -1447,7 +1375,7 @@ function getDefaultSession() {
|
|
|
1447
1375
|
* @since 1.3.0
|
|
1448
1376
|
*/
|
|
1449
1377
|
/* eslint-disable-next-line no-shadow */
|
|
1450
|
-
const fetch = (...args) => {
|
|
1378
|
+
const fetch$1 = (...args) => {
|
|
1451
1379
|
const session = getDefaultSession();
|
|
1452
1380
|
return session.fetch(...args);
|
|
1453
1381
|
};
|
|
@@ -1485,43 +1413,6 @@ const handleIncomingRedirect = (...args) => {
|
|
|
1485
1413
|
const session = getDefaultSession();
|
|
1486
1414
|
return session.handleIncomingRedirect(...args);
|
|
1487
1415
|
};
|
|
1488
|
-
/**
|
|
1489
|
-
* Register a callback function to be called when a user completes login.
|
|
1490
|
-
*
|
|
1491
|
-
* The callback is called when {@link handleIncomingRedirect} completes successfully.
|
|
1492
|
-
* @since 1.3.0
|
|
1493
|
-
*
|
|
1494
|
-
* @param callback The function called when a user completes login.
|
|
1495
|
-
* @deprecated Prefer events.on(EVENTS.LOGIN, callback)
|
|
1496
|
-
|
|
1497
|
-
*/
|
|
1498
|
-
const onLogin = (...args) => {
|
|
1499
|
-
const session = getDefaultSession();
|
|
1500
|
-
return session.onLogin(...args);
|
|
1501
|
-
};
|
|
1502
|
-
/**
|
|
1503
|
-
* Register a callback function to be called when a user logs out:
|
|
1504
|
-
*
|
|
1505
|
-
* @param callback The function called when a user completes logout.
|
|
1506
|
-
* @since 1.3.0
|
|
1507
|
-
* @deprecated Prefer events.on(EVENTS.LOGOUT, callback)
|
|
1508
|
-
*
|
|
1509
|
-
*/
|
|
1510
|
-
const onLogout = (...args) => {
|
|
1511
|
-
const session = getDefaultSession();
|
|
1512
|
-
return session.onLogout(...args);
|
|
1513
|
-
};
|
|
1514
|
-
/**
|
|
1515
|
-
* Register a callback function to be called when a session is restored:
|
|
1516
|
-
*
|
|
1517
|
-
* @param callback The function called when a session is restored.
|
|
1518
|
-
* @since 1.3.0
|
|
1519
|
-
* @deprecated Prefer events.on(EVENTS.SESSION_RESTORED, callback)
|
|
1520
|
-
*/
|
|
1521
|
-
const onSessionRestore = (...args) => {
|
|
1522
|
-
const session = getDefaultSession();
|
|
1523
|
-
return session.onSessionRestore(...args);
|
|
1524
|
-
};
|
|
1525
1416
|
/**
|
|
1526
1417
|
* {@link SessionEventEmitter} instance to subscribe to events by the default session.
|
|
1527
1418
|
*
|
|
@@ -1531,5 +1422,5 @@ const events = () => {
|
|
|
1531
1422
|
return getDefaultSession().events;
|
|
1532
1423
|
};
|
|
1533
1424
|
|
|
1534
|
-
export { Session, events, fetch
|
|
1425
|
+
export { Session, events, fetch$1 as fetch, getDefaultSession, handleIncomingRedirect, login, logout };
|
|
1535
1426
|
//# sourceMappingURL=index.mjs.map
|