@inrupt/solid-client-authn-browser 1.16.0 → 1.17.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/dist/ClientAuthentication.d.ts +4 -13
- package/dist/Session.d.ts +4 -4
- package/dist/dependencies.d.ts +1 -1
- package/dist/index.js +773 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +746 -0
- package/dist/index.mjs.map +1 -0
- package/dist/login/oidc/AggregateOidcHandler.d.ts +2 -1
- package/dist/login/oidc/AggregateRedirectHandler.d.ts +2 -1
- package/dist/login/oidc/ClientRegistrar.d.ts +1 -1
- package/dist/login/oidc/IssuerConfigFetcher.d.ts +1 -1
- package/dist/login/oidc/OidcLoginHandler.d.ts +1 -1
- package/dist/login/oidc/Redirector.d.ts +1 -1
- package/dist/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.d.ts +3 -6
- package/dist/login/oidc/incomingRedirectHandler/ErrorOidcHandler.d.ts +1 -1
- package/dist/login/oidc/incomingRedirectHandler/FallbackRedirectHandler.d.ts +1 -1
- package/dist/login/oidc/oidcHandlers/AuthorizationCodeWithPkceOidcHandler.d.ts +3 -6
- package/dist/login/oidc/oidcHandlers/OidcHandlerCanHandleTest.d.ts +1 -1
- package/dist/login/oidc/refresh/TokenRefresher.d.ts +2 -2
- package/dist/logout/buildRpInitiatedLogout.d.ts +2 -0
- package/dist/sessionInfo/SessionInfoManager.d.ts +4 -13
- package/dist/solid-client-authn.bundle.js +32 -2
- package/dist/solid-client-authn.bundle.js.map +1 -0
- package/dist/storage/BrowserStorage.d.ts +1 -1
- package/dist/storage/StorageUtility.d.ts +2 -1
- package/package.json +17 -17
- package/rollup.config.mjs +46 -0
- package/src/ClientAuthentication.spec.ts +4 -4
- package/src/ClientAuthentication.ts +8 -45
- package/src/Session.spec.ts +4 -4
- package/src/Session.ts +44 -13
- package/src/__mocks__/ClientAuthentication.ts +3 -3
- package/src/constant.ts +1 -1
- package/src/defaultSession.spec.ts +1 -1
- package/src/defaultSession.ts +5 -3
- package/src/dependencies.node.spec.ts +1 -1
- package/src/dependencies.spec.ts +1 -1
- package/src/dependencies.ts +10 -5
- package/src/index.browser.spec.ts +1 -1
- package/src/index.browser.ts +1 -1
- package/src/index.spec.ts +1 -1
- package/src/index.ts +1 -1
- package/src/login/__mocks__/LoginHandler.ts +2 -2
- package/src/login/oidc/AggregateOidcHandler.spec.ts +3 -5
- package/src/login/oidc/AggregateOidcHandler.ts +3 -3
- package/src/login/oidc/AggregateRedirectHandler.ts +3 -3
- package/src/login/oidc/ClientRegistrar.spec.ts +1 -1
- package/src/login/oidc/ClientRegistrar.ts +2 -2
- package/src/login/oidc/IssuerConfigFetcher.spec.ts +8 -4
- package/src/login/oidc/IssuerConfigFetcher.ts +12 -5
- package/src/login/oidc/OidcLoginHandler.spec.ts +3 -5
- package/src/login/oidc/OidcLoginHandler.ts +5 -3
- package/src/login/oidc/Redirector.spec.ts +1 -1
- package/src/login/oidc/Redirector.ts +2 -2
- package/src/login/oidc/__mocks__/ClientRegistrar.ts +2 -2
- package/src/login/oidc/__mocks__/IOidcHandler.ts +2 -2
- package/src/login/oidc/__mocks__/IOidcOptions.ts +2 -2
- package/src/login/oidc/__mocks__/IssuerConfigFetcher.ts +2 -2
- package/src/login/oidc/__mocks__/Redirector.ts +2 -2
- package/src/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.spec.ts +37 -39
- package/src/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.ts +31 -20
- package/src/login/oidc/incomingRedirectHandler/ErrorOidcHandler.spec.ts +3 -4
- package/src/login/oidc/incomingRedirectHandler/ErrorOidcHandler.ts +3 -3
- package/src/login/oidc/incomingRedirectHandler/FallbackRedirectHandler.spec.ts +3 -4
- package/src/login/oidc/incomingRedirectHandler/FallbackRedirectHandler.ts +2 -2
- package/src/login/oidc/oidcHandlers/AuthorizationCodeWithPkceOidcHandler.spec.ts +3 -3
- package/src/login/oidc/oidcHandlers/AuthorizationCodeWithPkceOidcHandler.ts +13 -51
- package/src/login/oidc/oidcHandlers/OidcHandlerCanHandleTest.ts +2 -2
- package/src/login/oidc/refresh/TokenRefresher.spec.ts +7 -6
- package/src/login/oidc/refresh/TokenRefresher.ts +6 -4
- package/src/login/oidc/refresh/__mocks__/TokenRefresher.ts +2 -2
- package/src/logout/{GeneralLogoutHandler.ts → buildRpInitiatedLogout.ts} +21 -20
- package/src/sessionInfo/SessionInfoManager.spec.ts +2 -2
- package/src/sessionInfo/SessionInfoManager.ts +13 -91
- package/src/sessionInfo/__mocks__/SessionInfoManager.ts +2 -2
- package/src/storage/BrowserStorage.spec.ts +1 -1
- package/src/storage/BrowserStorage.ts +2 -2
- package/src/storage/StorageUtility.ts +3 -2
- package/src/storage/__mocks__/LocalStorage.ts +1 -1
- package/src/util/UUIDGenerator.spec.ts +1 -1
- package/src/util/UuidGenerator.ts +1 -1
- package/src/util/__mocks__/UuidGenerator.ts +2 -2
- package/dist/ClientAuthentication.js +0 -80
- package/dist/ClientAuthentication.js.map +0 -1
- package/dist/Session.js +0 -150
- package/dist/Session.js.map +0 -1
- package/dist/constant.js +0 -7
- package/dist/constant.js.map +0 -1
- package/dist/defaultSession.js +0 -52
- package/dist/defaultSession.js.map +0 -1
- package/dist/dependencies.js +0 -41
- package/dist/dependencies.js.map +0 -1
- package/dist/index.browser.js +0 -28
- package/dist/index.browser.js.map +0 -1
- package/dist/login/oidc/AggregateOidcHandler.js +0 -10
- package/dist/login/oidc/AggregateOidcHandler.js.map +0 -1
- package/dist/login/oidc/AggregateRedirectHandler.js +0 -10
- package/dist/login/oidc/AggregateRedirectHandler.js.map +0 -1
- package/dist/login/oidc/ClientRegistrar.js +0 -47
- package/dist/login/oidc/ClientRegistrar.js.map +0 -1
- package/dist/login/oidc/IssuerConfigFetcher.js +0 -124
- package/dist/login/oidc/IssuerConfigFetcher.js.map +0 -1
- package/dist/login/oidc/OidcLoginHandler.js +0 -40
- package/dist/login/oidc/OidcLoginHandler.js.map +0 -1
- package/dist/login/oidc/Redirector.js +0 -17
- package/dist/login/oidc/Redirector.js.map +0 -1
- package/dist/login/oidc/__mocks__/IOidcOptions.d.ts +0 -2
- package/dist/login/oidc/__mocks__/IOidcOptions.js +0 -25
- package/dist/login/oidc/__mocks__/IOidcOptions.js.map +0 -1
- package/dist/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.js +0 -91
- package/dist/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.js.map +0 -1
- package/dist/login/oidc/incomingRedirectHandler/ErrorOidcHandler.js +0 -26
- package/dist/login/oidc/incomingRedirectHandler/ErrorOidcHandler.js.map +0 -1
- package/dist/login/oidc/incomingRedirectHandler/FallbackRedirectHandler.js +0 -20
- package/dist/login/oidc/incomingRedirectHandler/FallbackRedirectHandler.js.map +0 -1
- package/dist/login/oidc/oidcHandlers/AuthorizationCodeWithPkceOidcHandler.js +0 -56
- package/dist/login/oidc/oidcHandlers/AuthorizationCodeWithPkceOidcHandler.js.map +0 -1
- package/dist/login/oidc/oidcHandlers/OidcHandlerCanHandleTest.js +0 -47
- package/dist/login/oidc/oidcHandlers/OidcHandlerCanHandleTest.js.map +0 -1
- package/dist/login/oidc/refresh/TokenRefresher.js +0 -31
- package/dist/login/oidc/refresh/TokenRefresher.js.map +0 -1
- package/dist/logout/GeneralLogoutHandler.d.ts +0 -7
- package/dist/logout/GeneralLogoutHandler.js +0 -15
- package/dist/logout/GeneralLogoutHandler.js.map +0 -1
- package/dist/sessionInfo/SessionInfoManager.js +0 -96
- package/dist/sessionInfo/SessionInfoManager.js.map +0 -1
- package/dist/solid-client-authn.bundle.js.LICENSE.txt +0 -17
- package/dist/storage/BrowserStorage.js +0 -18
- package/dist/storage/BrowserStorage.js.map +0 -1
- package/dist/storage/StorageUtility.js +0 -10
- package/dist/storage/StorageUtility.js.map +0 -1
- package/dist/util/UuidGenerator.js +0 -10
- package/dist/util/UuidGenerator.js.map +0 -1
- package/licenses.csv +0 -147
- package/src/logout/GeneralLogoutHandler.spec.ts +0 -72
- package/src/logout/__mocks__/LogoutHandler.ts +0 -38
- package/webpack.browser.js +0 -39
- package/webpack.common.js +0 -42
- package/webpack.config.js +0 -28
- package/webpack.dev.js +0 -37
- package/webpack.prod.js +0 -23
package/dist/index.js
CHANGED
|
@@ -1,28 +1,773 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var solidClientAuthnCore = require('@inrupt/solid-client-authn-core');
|
|
4
|
+
var uuid = require('uuid');
|
|
5
|
+
var EventEmitter = require('events');
|
|
6
|
+
var oidcClientExt = require('@inrupt/oidc-client-ext');
|
|
7
|
+
var universalFetch = require('@inrupt/universal-fetch');
|
|
8
|
+
|
|
9
|
+
class StorageUtilityBrowser extends solidClientAuthnCore.StorageUtility {
|
|
10
|
+
constructor(secureStorage, insecureStorage) {
|
|
11
|
+
super(secureStorage, insecureStorage);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class ClientAuthentication extends solidClientAuthnCore.ClientAuthentication {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
this.login = async (options, eventEmitter) => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
await this.sessionInfoManager.clear(options.sessionId);
|
|
21
|
+
const redirectUrl = (_a = options.redirectUrl) !== null && _a !== void 0 ? _a : oidcClientExt.removeOidcQueryParam(window.location.href);
|
|
22
|
+
if (!solidClientAuthnCore.isValidRedirectUrl(redirectUrl)) {
|
|
23
|
+
throw new Error(`${redirectUrl} is not a valid redirect URL, it is either a malformed IRI or it includes a hash fragment.`);
|
|
24
|
+
}
|
|
25
|
+
await this.loginHandler.handle({
|
|
26
|
+
...options,
|
|
27
|
+
redirectUrl,
|
|
28
|
+
clientName: (_b = options.clientName) !== null && _b !== void 0 ? _b : options.clientId,
|
|
29
|
+
eventEmitter,
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
this.validateCurrentSession = async (currentSessionId) => {
|
|
33
|
+
const sessionInfo = await this.sessionInfoManager.get(currentSessionId);
|
|
34
|
+
if (sessionInfo === undefined ||
|
|
35
|
+
sessionInfo.clientAppId === undefined ||
|
|
36
|
+
sessionInfo.issuer === undefined) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return sessionInfo;
|
|
40
|
+
};
|
|
41
|
+
this.handleIncomingRedirect = async (url, eventEmitter) => {
|
|
42
|
+
try {
|
|
43
|
+
const redirectInfo = await this.redirectHandler.handle(url, eventEmitter);
|
|
44
|
+
this.fetch = redirectInfo.fetch.bind(window);
|
|
45
|
+
this.boundLogout = redirectInfo.getLogoutUrl;
|
|
46
|
+
this.cleanUrlAfterRedirect(url);
|
|
47
|
+
return {
|
|
48
|
+
isLoggedIn: redirectInfo.isLoggedIn,
|
|
49
|
+
webId: redirectInfo.webId,
|
|
50
|
+
sessionId: redirectInfo.sessionId,
|
|
51
|
+
expirationDate: redirectInfo.expirationDate,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
this.cleanUrlAfterRedirect(url);
|
|
56
|
+
eventEmitter.emit(solidClientAuthnCore.EVENTS.ERROR, "redirect", err);
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
cleanUrlAfterRedirect(url) {
|
|
62
|
+
const cleanedUpUrl = new URL(url);
|
|
63
|
+
cleanedUpUrl.searchParams.delete("state");
|
|
64
|
+
cleanedUpUrl.searchParams.delete("code");
|
|
65
|
+
cleanedUpUrl.searchParams.delete("id_token");
|
|
66
|
+
cleanedUpUrl.searchParams.delete("access_token");
|
|
67
|
+
cleanedUpUrl.searchParams.delete("error");
|
|
68
|
+
cleanedUpUrl.searchParams.delete("error_description");
|
|
69
|
+
cleanedUpUrl.searchParams.delete("iss");
|
|
70
|
+
window.history.replaceState(null, "", cleanedUpUrl.toString());
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function hasIssuer(options) {
|
|
75
|
+
return typeof options.oidcIssuer === "string";
|
|
76
|
+
}
|
|
77
|
+
function hasRedirectUrl(options) {
|
|
78
|
+
return typeof options.redirectUrl === "string";
|
|
79
|
+
}
|
|
80
|
+
class OidcLoginHandler {
|
|
81
|
+
constructor(storageUtility, oidcHandler, issuerConfigFetcher, clientRegistrar) {
|
|
82
|
+
this.storageUtility = storageUtility;
|
|
83
|
+
this.oidcHandler = oidcHandler;
|
|
84
|
+
this.issuerConfigFetcher = issuerConfigFetcher;
|
|
85
|
+
this.clientRegistrar = clientRegistrar;
|
|
86
|
+
}
|
|
87
|
+
async canHandle(options) {
|
|
88
|
+
return hasIssuer(options) && hasRedirectUrl(options);
|
|
89
|
+
}
|
|
90
|
+
async handle(options) {
|
|
91
|
+
if (!hasIssuer(options)) {
|
|
92
|
+
throw new solidClientAuthnCore.ConfigurationError(`OidcLoginHandler requires an OIDC issuer: missing property 'oidcIssuer' in ${JSON.stringify(options)}`);
|
|
93
|
+
}
|
|
94
|
+
if (!hasRedirectUrl(options)) {
|
|
95
|
+
throw new solidClientAuthnCore.ConfigurationError(`OidcLoginHandler requires a redirect URL: missing property 'redirectUrl' in ${JSON.stringify(options)}`);
|
|
96
|
+
}
|
|
97
|
+
const issuerConfig = await this.issuerConfigFetcher.fetchConfig(options.oidcIssuer);
|
|
98
|
+
const clientRegistration = await solidClientAuthnCore.handleRegistration(options, issuerConfig, this.storageUtility, this.clientRegistrar);
|
|
99
|
+
const OidcOptions = {
|
|
100
|
+
issuer: issuerConfig.issuer,
|
|
101
|
+
dpop: options.tokenType.toLowerCase() === "dpop",
|
|
102
|
+
...options,
|
|
103
|
+
issuerConfiguration: issuerConfig,
|
|
104
|
+
client: clientRegistration,
|
|
105
|
+
};
|
|
106
|
+
return this.oidcHandler.handle(OidcOptions);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
class AuthorizationCodeWithPkceOidcHandler extends solidClientAuthnCore.AuthorizationCodeWithPkceOidcHandlerBase {
|
|
111
|
+
async handle(oidcLoginOptions) {
|
|
112
|
+
var _a;
|
|
113
|
+
const oidcOptions = {
|
|
114
|
+
authority: oidcLoginOptions.issuer.toString(),
|
|
115
|
+
client_id: oidcLoginOptions.client.clientId,
|
|
116
|
+
client_secret: oidcLoginOptions.client.clientSecret,
|
|
117
|
+
redirect_uri: oidcLoginOptions.redirectUrl.toString(),
|
|
118
|
+
post_logout_redirect_uri: oidcLoginOptions.redirectUrl.toString(),
|
|
119
|
+
response_type: "code",
|
|
120
|
+
scope: solidClientAuthnCore.DEFAULT_SCOPES,
|
|
121
|
+
filterProtocolClaims: true,
|
|
122
|
+
loadUserInfo: false,
|
|
123
|
+
code_verifier: true,
|
|
124
|
+
prompt: (_a = oidcLoginOptions.prompt) !== null && _a !== void 0 ? _a : "consent",
|
|
125
|
+
};
|
|
126
|
+
const oidcClientLibrary = new oidcClientExt.OidcClient(oidcOptions);
|
|
127
|
+
try {
|
|
128
|
+
const signingRequest = await oidcClientLibrary.createSigninRequest();
|
|
129
|
+
return await this.handleRedirect({
|
|
130
|
+
oidcLoginOptions,
|
|
131
|
+
state: signingRequest.state._id,
|
|
132
|
+
codeVerifier: signingRequest.state._code_verifier,
|
|
133
|
+
targetUrl: signingRequest.url.toString(),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
console.error(err);
|
|
138
|
+
}
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const WELL_KNOWN_OPENID_CONFIG = ".well-known/openid-configuration";
|
|
144
|
+
const issuerConfigKeyMap = {
|
|
145
|
+
issuer: {
|
|
146
|
+
toKey: "issuer",
|
|
147
|
+
convertToUrl: true,
|
|
148
|
+
},
|
|
149
|
+
authorization_endpoint: {
|
|
150
|
+
toKey: "authorizationEndpoint",
|
|
151
|
+
convertToUrl: true,
|
|
152
|
+
},
|
|
153
|
+
token_endpoint: {
|
|
154
|
+
toKey: "tokenEndpoint",
|
|
155
|
+
convertToUrl: true,
|
|
156
|
+
},
|
|
157
|
+
userinfo_endpoint: {
|
|
158
|
+
toKey: "userinfoEndpoint",
|
|
159
|
+
convertToUrl: true,
|
|
160
|
+
},
|
|
161
|
+
jwks_uri: {
|
|
162
|
+
toKey: "jwksUri",
|
|
163
|
+
convertToUrl: true,
|
|
164
|
+
},
|
|
165
|
+
registration_endpoint: {
|
|
166
|
+
toKey: "registrationEndpoint",
|
|
167
|
+
convertToUrl: true,
|
|
168
|
+
},
|
|
169
|
+
end_session_endpoint: {
|
|
170
|
+
toKey: "endSessionEndpoint",
|
|
171
|
+
convertToUrl: true,
|
|
172
|
+
},
|
|
173
|
+
scopes_supported: { toKey: "scopesSupported" },
|
|
174
|
+
response_types_supported: { toKey: "responseTypesSupported" },
|
|
175
|
+
response_modes_supported: { toKey: "responseModesSupported" },
|
|
176
|
+
grant_types_supported: { toKey: "grantTypesSupported" },
|
|
177
|
+
acr_values_supported: { toKey: "acrValuesSupported" },
|
|
178
|
+
subject_types_supported: { toKey: "subjectTypesSupported" },
|
|
179
|
+
id_token_signing_alg_values_supported: {
|
|
180
|
+
toKey: "idTokenSigningAlgValuesSupported",
|
|
181
|
+
},
|
|
182
|
+
id_token_encryption_alg_values_supported: {
|
|
183
|
+
toKey: "idTokenEncryptionAlgValuesSupported",
|
|
184
|
+
},
|
|
185
|
+
id_token_encryption_enc_values_supported: {
|
|
186
|
+
toKey: "idTokenEncryptionEncValuesSupported",
|
|
187
|
+
},
|
|
188
|
+
userinfo_signing_alg_values_supported: {
|
|
189
|
+
toKey: "userinfoSigningAlgValuesSupported",
|
|
190
|
+
},
|
|
191
|
+
userinfo_encryption_alg_values_supported: {
|
|
192
|
+
toKey: "userinfoEncryptionAlgValuesSupported",
|
|
193
|
+
},
|
|
194
|
+
userinfo_encryption_enc_values_supported: {
|
|
195
|
+
toKey: "userinfoEncryptionEncValuesSupported",
|
|
196
|
+
},
|
|
197
|
+
request_object_signing_alg_values_supported: {
|
|
198
|
+
toKey: "requestObjectSigningAlgValuesSupported",
|
|
199
|
+
},
|
|
200
|
+
request_object_encryption_alg_values_supported: {
|
|
201
|
+
toKey: "requestObjectEncryptionAlgValuesSupported",
|
|
202
|
+
},
|
|
203
|
+
request_object_encryption_enc_values_supported: {
|
|
204
|
+
toKey: "requestObjectEncryptionEncValuesSupported",
|
|
205
|
+
},
|
|
206
|
+
token_endpoint_auth_methods_supported: {
|
|
207
|
+
toKey: "tokenEndpointAuthMethodsSupported",
|
|
208
|
+
},
|
|
209
|
+
token_endpoint_auth_signing_alg_values_supported: {
|
|
210
|
+
toKey: "tokenEndpointAuthSigningAlgValuesSupported",
|
|
211
|
+
},
|
|
212
|
+
display_values_supported: { toKey: "displayValuesSupported" },
|
|
213
|
+
claim_types_supported: { toKey: "claimTypesSupported" },
|
|
214
|
+
claims_supported: { toKey: "claimsSupported" },
|
|
215
|
+
service_documentation: { toKey: "serviceDocumentation" },
|
|
216
|
+
claims_locales_supported: { toKey: "claimsLocalesSupported" },
|
|
217
|
+
ui_locales_supported: { toKey: "uiLocalesSupported" },
|
|
218
|
+
claims_parameter_supported: { toKey: "claimsParameterSupported" },
|
|
219
|
+
request_parameter_supported: { toKey: "requestParameterSupported" },
|
|
220
|
+
request_uri_parameter_supported: { toKey: "requestUriParameterSupported" },
|
|
221
|
+
require_request_uri_registration: { toKey: "requireRequestUriRegistration" },
|
|
222
|
+
op_policy_uri: {
|
|
223
|
+
toKey: "opPolicyUri",
|
|
224
|
+
convertToUrl: true,
|
|
225
|
+
},
|
|
226
|
+
op_tos_uri: {
|
|
227
|
+
toKey: "opTosUri",
|
|
228
|
+
convertToUrl: true,
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
function processConfig(config) {
|
|
232
|
+
const parsedConfig = {};
|
|
233
|
+
Object.keys(config).forEach((key) => {
|
|
234
|
+
if (issuerConfigKeyMap[key]) {
|
|
235
|
+
parsedConfig[issuerConfigKeyMap[key].toKey] = config[key];
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
if (!Array.isArray(parsedConfig.scopesSupported)) {
|
|
239
|
+
parsedConfig.scopesSupported = ["openid"];
|
|
240
|
+
}
|
|
241
|
+
return parsedConfig;
|
|
242
|
+
}
|
|
243
|
+
class IssuerConfigFetcher {
|
|
244
|
+
constructor(storageUtility) {
|
|
245
|
+
this.storageUtility = storageUtility;
|
|
246
|
+
}
|
|
247
|
+
static getLocalStorageKey(issuer) {
|
|
248
|
+
return `issuerConfig:${issuer}`;
|
|
249
|
+
}
|
|
250
|
+
async fetchConfig(issuer) {
|
|
251
|
+
let issuerConfig;
|
|
252
|
+
const openIdConfigUrl = new URL(WELL_KNOWN_OPENID_CONFIG, issuer.endsWith("/") ? issuer : `${issuer}/`).href;
|
|
253
|
+
const issuerConfigRequestBody = await universalFetch.fetch.call(globalThis, openIdConfigUrl);
|
|
254
|
+
try {
|
|
255
|
+
issuerConfig = processConfig(await issuerConfigRequestBody.json());
|
|
256
|
+
}
|
|
257
|
+
catch (err) {
|
|
258
|
+
throw new solidClientAuthnCore.ConfigurationError(`[${issuer.toString()}] has an invalid configuration: ${err.message}`);
|
|
259
|
+
}
|
|
260
|
+
await this.storageUtility.set(IssuerConfigFetcher.getLocalStorageKey(issuer), JSON.stringify(issuerConfig));
|
|
261
|
+
return issuerConfig;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function clear(sessionId, storage) {
|
|
266
|
+
await solidClientAuthnCore.clear(sessionId, storage);
|
|
267
|
+
await oidcClientExt.clearOidcPersistentStorage();
|
|
268
|
+
}
|
|
269
|
+
class SessionInfoManager extends solidClientAuthnCore.SessionInfoManagerBase {
|
|
270
|
+
async get(sessionId) {
|
|
271
|
+
var _a;
|
|
272
|
+
const isLoggedIn = await this.storageUtility.getForUser(sessionId, "isLoggedIn", {
|
|
273
|
+
secure: true,
|
|
274
|
+
});
|
|
275
|
+
const webId = await this.storageUtility.getForUser(sessionId, "webId", {
|
|
276
|
+
secure: true,
|
|
277
|
+
});
|
|
278
|
+
const clientId = await this.storageUtility.getForUser(sessionId, "clientId", {
|
|
279
|
+
secure: false,
|
|
280
|
+
});
|
|
281
|
+
const clientSecret = await this.storageUtility.getForUser(sessionId, "clientSecret", {
|
|
282
|
+
secure: false,
|
|
283
|
+
});
|
|
284
|
+
const redirectUrl = await this.storageUtility.getForUser(sessionId, "redirectUrl", {
|
|
285
|
+
secure: false,
|
|
286
|
+
});
|
|
287
|
+
const refreshToken = await this.storageUtility.getForUser(sessionId, "refreshToken", {
|
|
288
|
+
secure: true,
|
|
289
|
+
});
|
|
290
|
+
const issuer = await this.storageUtility.getForUser(sessionId, "issuer", {
|
|
291
|
+
secure: false,
|
|
292
|
+
});
|
|
293
|
+
const tokenType = (_a = (await this.storageUtility.getForUser(sessionId, "tokenType", {
|
|
294
|
+
secure: false,
|
|
295
|
+
}))) !== null && _a !== void 0 ? _a : "DPoP";
|
|
296
|
+
if (!solidClientAuthnCore.isSupportedTokenType(tokenType)) {
|
|
297
|
+
throw new Error(`Tokens of type [${tokenType}] are not supported.`);
|
|
298
|
+
}
|
|
299
|
+
if (clientId === undefined &&
|
|
300
|
+
isLoggedIn === undefined &&
|
|
301
|
+
webId === undefined &&
|
|
302
|
+
refreshToken === undefined) {
|
|
303
|
+
return undefined;
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
sessionId,
|
|
307
|
+
webId,
|
|
308
|
+
isLoggedIn: isLoggedIn === "true",
|
|
309
|
+
redirectUrl,
|
|
310
|
+
refreshToken,
|
|
311
|
+
issuer,
|
|
312
|
+
clientAppId: clientId,
|
|
313
|
+
clientAppSecret: clientSecret,
|
|
314
|
+
tokenType,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
async clear(sessionId) {
|
|
318
|
+
return clear(sessionId, this.storageUtility);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
class FallbackRedirectHandler {
|
|
323
|
+
async canHandle(redirectUrl) {
|
|
324
|
+
try {
|
|
325
|
+
new URL(redirectUrl);
|
|
326
|
+
return true;
|
|
327
|
+
}
|
|
328
|
+
catch (e) {
|
|
329
|
+
throw new Error(`[${redirectUrl}] is not a valid URL, and cannot be used as a redirect URL: ${e}`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
async handle(_redirectUrl) {
|
|
333
|
+
return solidClientAuthnCore.getUnauthenticatedSession();
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const globalFetch = (...args) => universalFetch.fetch.call(globalThis, ...args);
|
|
338
|
+
class AuthCodeRedirectHandler {
|
|
339
|
+
constructor(storageUtility, sessionInfoManager, issuerConfigFetcher, clientRegistrar, tokerRefresher) {
|
|
340
|
+
this.storageUtility = storageUtility;
|
|
341
|
+
this.sessionInfoManager = sessionInfoManager;
|
|
342
|
+
this.issuerConfigFetcher = issuerConfigFetcher;
|
|
343
|
+
this.clientRegistrar = clientRegistrar;
|
|
344
|
+
this.tokerRefresher = tokerRefresher;
|
|
345
|
+
}
|
|
346
|
+
async canHandle(redirectUrl) {
|
|
347
|
+
try {
|
|
348
|
+
const myUrl = new URL(redirectUrl);
|
|
349
|
+
return (myUrl.searchParams.get("code") !== null &&
|
|
350
|
+
myUrl.searchParams.get("state") !== null);
|
|
351
|
+
}
|
|
352
|
+
catch (e) {
|
|
353
|
+
throw new Error(`[${redirectUrl}] is not a valid URL, and cannot be used as a redirect URL: ${e}`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
async handle(redirectUrl, eventEmitter) {
|
|
357
|
+
if (!(await this.canHandle(redirectUrl))) {
|
|
358
|
+
throw new Error(`AuthCodeRedirectHandler cannot handle [${redirectUrl}]: it is missing one of [code, state].`);
|
|
359
|
+
}
|
|
360
|
+
const url = new URL(redirectUrl);
|
|
361
|
+
const oauthState = url.searchParams.get("state");
|
|
362
|
+
const storedSessionId = (await this.storageUtility.getForUser(oauthState, "sessionId", {
|
|
363
|
+
errorIfNull: true,
|
|
364
|
+
}));
|
|
365
|
+
const { issuerConfig, codeVerifier, redirectUrl: storedRedirectIri, dpop: isDpop, } = await solidClientAuthnCore.loadOidcContextFromStorage(storedSessionId, this.storageUtility, this.issuerConfigFetcher);
|
|
366
|
+
const iss = url.searchParams.get("iss");
|
|
367
|
+
if (typeof iss === "string" && iss !== issuerConfig.issuer) {
|
|
368
|
+
throw new Error(`The value of the iss parameter (${iss}) does not match the issuer identifier of the authorization server (${issuerConfig.issuer}). See [rfc9207](https://www.rfc-editor.org/rfc/rfc9207.html#section-2.3-3.1.1)`);
|
|
369
|
+
}
|
|
370
|
+
if (codeVerifier === undefined) {
|
|
371
|
+
throw new Error(`The code verifier for session ${storedSessionId} is missing from storage.`);
|
|
372
|
+
}
|
|
373
|
+
if (storedRedirectIri === undefined) {
|
|
374
|
+
throw new Error(`The redirect URL for session ${storedSessionId} is missing from storage.`);
|
|
375
|
+
}
|
|
376
|
+
const client = await this.clientRegistrar.getClient({ sessionId: storedSessionId }, issuerConfig);
|
|
377
|
+
let tokens;
|
|
378
|
+
const tokenCreatedAt = Date.now();
|
|
379
|
+
if (isDpop) {
|
|
380
|
+
tokens = await oidcClientExt.getDpopToken(issuerConfig, client, {
|
|
381
|
+
grantType: "authorization_code",
|
|
382
|
+
code: url.searchParams.get("code"),
|
|
383
|
+
codeVerifier,
|
|
384
|
+
redirectUrl: storedRedirectIri,
|
|
385
|
+
});
|
|
386
|
+
window.localStorage.removeItem(`oidc.${oauthState}`);
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
tokens = await oidcClientExt.getBearerToken(url.toString());
|
|
390
|
+
}
|
|
391
|
+
let refreshOptions;
|
|
392
|
+
if (tokens.refreshToken !== undefined) {
|
|
393
|
+
refreshOptions = {
|
|
394
|
+
sessionId: storedSessionId,
|
|
395
|
+
refreshToken: tokens.refreshToken,
|
|
396
|
+
tokenRefresher: this.tokerRefresher,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
const authFetch = await solidClientAuthnCore.buildAuthenticatedFetch(globalFetch, tokens.accessToken, {
|
|
400
|
+
dpopKey: tokens.dpopKey,
|
|
401
|
+
refreshOptions,
|
|
402
|
+
eventEmitter,
|
|
403
|
+
expiresIn: tokens.expiresIn,
|
|
404
|
+
});
|
|
405
|
+
await this.storageUtility.setForUser(storedSessionId, {
|
|
406
|
+
webId: tokens.webId,
|
|
407
|
+
isLoggedIn: "true",
|
|
408
|
+
}, { secure: true });
|
|
409
|
+
const sessionInfo = await this.sessionInfoManager.get(storedSessionId);
|
|
410
|
+
if (!sessionInfo) {
|
|
411
|
+
throw new Error(`Could not retrieve session: [${storedSessionId}].`);
|
|
412
|
+
}
|
|
413
|
+
return Object.assign(sessionInfo, {
|
|
414
|
+
fetch: authFetch,
|
|
415
|
+
getLogoutUrl: solidClientAuthnCore.maybeBuildRpInitiatedLogout({
|
|
416
|
+
idTokenHint: tokens.idToken,
|
|
417
|
+
endSessionEndpoint: issuerConfig.endSessionEndpoint,
|
|
418
|
+
}),
|
|
419
|
+
expirationDate: typeof tokens.expiresIn === "number"
|
|
420
|
+
? tokenCreatedAt + tokens.expiresIn * 1000
|
|
421
|
+
: undefined,
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
class AggregateRedirectHandler extends solidClientAuthnCore.AggregateHandler {
|
|
427
|
+
constructor(redirectHandlers) {
|
|
428
|
+
super(redirectHandlers);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
class BrowserStorage {
|
|
433
|
+
get storage() {
|
|
434
|
+
return window.localStorage;
|
|
435
|
+
}
|
|
436
|
+
async get(key) {
|
|
437
|
+
return this.storage.getItem(key) || undefined;
|
|
438
|
+
}
|
|
439
|
+
async set(key, value) {
|
|
440
|
+
this.storage.setItem(key, value);
|
|
441
|
+
}
|
|
442
|
+
async delete(key) {
|
|
443
|
+
this.storage.removeItem(key);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
class Redirector {
|
|
448
|
+
redirect(redirectUrl, options) {
|
|
449
|
+
if (options && options.handleRedirect) {
|
|
450
|
+
options.handleRedirect(redirectUrl);
|
|
451
|
+
}
|
|
452
|
+
else if (options && options.redirectByReplacingState) {
|
|
453
|
+
window.history.replaceState({}, "", redirectUrl);
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
window.location.href = redirectUrl;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
class ClientRegistrar {
|
|
462
|
+
constructor(storageUtility) {
|
|
463
|
+
this.storageUtility = storageUtility;
|
|
464
|
+
}
|
|
465
|
+
async getClient(options, issuerConfig) {
|
|
466
|
+
const [storedClientId, storedClientSecret,] = await Promise.all([
|
|
467
|
+
this.storageUtility.getForUser(options.sessionId, "clientId", {
|
|
468
|
+
secure: false,
|
|
469
|
+
}),
|
|
470
|
+
this.storageUtility.getForUser(options.sessionId, "clientSecret", {
|
|
471
|
+
secure: false,
|
|
472
|
+
}),
|
|
473
|
+
]);
|
|
474
|
+
if (storedClientId) {
|
|
475
|
+
return {
|
|
476
|
+
clientId: storedClientId,
|
|
477
|
+
clientSecret: storedClientSecret,
|
|
478
|
+
clientType: "dynamic",
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
try {
|
|
482
|
+
const registeredClient = await oidcClientExt.registerClient(options, issuerConfig);
|
|
483
|
+
const infoToSave = {
|
|
484
|
+
clientId: registeredClient.clientId,
|
|
485
|
+
};
|
|
486
|
+
if (registeredClient.clientSecret) {
|
|
487
|
+
infoToSave.clientSecret = registeredClient.clientSecret;
|
|
488
|
+
}
|
|
489
|
+
if (registeredClient.idTokenSignedResponseAlg) {
|
|
490
|
+
infoToSave.idTokenSignedResponseAlg =
|
|
491
|
+
registeredClient.idTokenSignedResponseAlg;
|
|
492
|
+
}
|
|
493
|
+
await this.storageUtility.setForUser(options.sessionId, infoToSave, {
|
|
494
|
+
secure: false,
|
|
495
|
+
});
|
|
496
|
+
return registeredClient;
|
|
497
|
+
}
|
|
498
|
+
catch (error) {
|
|
499
|
+
throw new Error(`Client registration failed: [${error}]`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
class ErrorOidcHandler {
|
|
505
|
+
async canHandle(redirectUrl) {
|
|
506
|
+
try {
|
|
507
|
+
return new URL(redirectUrl).searchParams.has("error");
|
|
508
|
+
}
|
|
509
|
+
catch (e) {
|
|
510
|
+
throw new Error(`[${redirectUrl}] is not a valid URL, and cannot be used as a redirect URL: ${e}`);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
async handle(redirectUrl, eventEmitter) {
|
|
514
|
+
if (eventEmitter !== undefined) {
|
|
515
|
+
const url = new URL(redirectUrl);
|
|
516
|
+
const errorUrl = url.searchParams.get("error");
|
|
517
|
+
const errorDescriptionUrl = url.searchParams.get("error_description");
|
|
518
|
+
eventEmitter.emit(solidClientAuthnCore.EVENTS.ERROR, errorUrl, errorDescriptionUrl);
|
|
519
|
+
}
|
|
520
|
+
return solidClientAuthnCore.getUnauthenticatedSession();
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
class TokenRefresher {
|
|
525
|
+
constructor(storageUtility, issuerConfigFetcher, clientRegistrar) {
|
|
526
|
+
this.storageUtility = storageUtility;
|
|
527
|
+
this.issuerConfigFetcher = issuerConfigFetcher;
|
|
528
|
+
this.clientRegistrar = clientRegistrar;
|
|
529
|
+
}
|
|
530
|
+
async refresh(sessionId, refreshToken, dpopKey, eventEmitter) {
|
|
531
|
+
const oidcContext = await solidClientAuthnCore.loadOidcContextFromStorage(sessionId, this.storageUtility, this.issuerConfigFetcher);
|
|
532
|
+
const clientInfo = await this.clientRegistrar.getClient({ sessionId }, oidcContext.issuerConfig);
|
|
533
|
+
if (refreshToken === undefined) {
|
|
534
|
+
throw new Error(`Session [${sessionId}] has no refresh token to allow it to refresh its access token.`);
|
|
535
|
+
}
|
|
536
|
+
if (oidcContext.dpop && dpopKey === undefined) {
|
|
537
|
+
throw new Error(`For session [${sessionId}], the key bound to the DPoP access token must be provided to refresh said access token.`);
|
|
538
|
+
}
|
|
539
|
+
const tokenSet = await oidcClientExt.refresh(refreshToken, oidcContext.issuerConfig, clientInfo, dpopKey);
|
|
540
|
+
if (tokenSet.refreshToken !== undefined) {
|
|
541
|
+
eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.emit(solidClientAuthnCore.EVENTS.NEW_REFRESH_TOKEN, tokenSet.refreshToken);
|
|
542
|
+
await this.storageUtility.setForUser(sessionId, {
|
|
543
|
+
refreshToken: tokenSet.refreshToken,
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
return tokenSet;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function getClientAuthenticationWithDependencies(dependencies) {
|
|
551
|
+
const inMemoryStorage = new solidClientAuthnCore.InMemoryStorage();
|
|
552
|
+
const secureStorage = dependencies.secureStorage || inMemoryStorage;
|
|
553
|
+
const insecureStorage = dependencies.insecureStorage || new BrowserStorage();
|
|
554
|
+
const storageUtility = new StorageUtilityBrowser(secureStorage, insecureStorage);
|
|
555
|
+
const issuerConfigFetcher = new IssuerConfigFetcher(storageUtility);
|
|
556
|
+
const clientRegistrar = new ClientRegistrar(storageUtility);
|
|
557
|
+
const sessionInfoManager = new SessionInfoManager(storageUtility);
|
|
558
|
+
const tokenRefresher = new TokenRefresher(storageUtility, issuerConfigFetcher, clientRegistrar);
|
|
559
|
+
const redirector = new Redirector();
|
|
560
|
+
const loginHandler = new OidcLoginHandler(storageUtility, new AuthorizationCodeWithPkceOidcHandler(storageUtility, redirector), issuerConfigFetcher, clientRegistrar);
|
|
561
|
+
const redirectHandler = new AggregateRedirectHandler([
|
|
562
|
+
new ErrorOidcHandler(),
|
|
563
|
+
new AuthCodeRedirectHandler(storageUtility, sessionInfoManager, issuerConfigFetcher, clientRegistrar, tokenRefresher),
|
|
564
|
+
new FallbackRedirectHandler(),
|
|
565
|
+
]);
|
|
566
|
+
return new ClientAuthentication(loginHandler, redirectHandler, new solidClientAuthnCore.IWaterfallLogoutHandler(sessionInfoManager, redirector), sessionInfoManager, issuerConfigFetcher);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const KEY_CURRENT_SESSION = `${solidClientAuthnCore.SOLID_CLIENT_AUTHN_KEY_PREFIX}currentSession`;
|
|
570
|
+
const KEY_CURRENT_URL = `${solidClientAuthnCore.SOLID_CLIENT_AUTHN_KEY_PREFIX}currentUrl`;
|
|
571
|
+
|
|
572
|
+
async function silentlyAuthenticate(sessionId, clientAuthn, session) {
|
|
573
|
+
var _a;
|
|
574
|
+
const storedSessionInfo = await clientAuthn.validateCurrentSession(sessionId);
|
|
575
|
+
if (storedSessionInfo !== null) {
|
|
576
|
+
window.localStorage.setItem(KEY_CURRENT_URL, window.location.href);
|
|
577
|
+
await clientAuthn.login({
|
|
578
|
+
sessionId,
|
|
579
|
+
prompt: "none",
|
|
580
|
+
oidcIssuer: storedSessionInfo.issuer,
|
|
581
|
+
redirectUrl: storedSessionInfo.redirectUrl,
|
|
582
|
+
clientId: storedSessionInfo.clientAppId,
|
|
583
|
+
clientSecret: storedSessionInfo.clientAppSecret,
|
|
584
|
+
tokenType: (_a = storedSessionInfo.tokenType) !== null && _a !== void 0 ? _a : "DPoP",
|
|
585
|
+
}, session.events);
|
|
586
|
+
return true;
|
|
587
|
+
}
|
|
588
|
+
return false;
|
|
589
|
+
}
|
|
590
|
+
function isLoggedIn(sessionInfo) {
|
|
591
|
+
return !!(sessionInfo === null || sessionInfo === void 0 ? void 0 : sessionInfo.isLoggedIn);
|
|
592
|
+
}
|
|
593
|
+
class Session extends EventEmitter {
|
|
594
|
+
constructor(sessionOptions = {}, sessionId = undefined) {
|
|
595
|
+
super();
|
|
596
|
+
this.tokenRequestInProgress = false;
|
|
597
|
+
this.login = async (options) => {
|
|
598
|
+
var _a;
|
|
599
|
+
await this.clientAuthentication.login({
|
|
600
|
+
sessionId: this.info.sessionId,
|
|
601
|
+
...options,
|
|
602
|
+
tokenType: (_a = options.tokenType) !== null && _a !== void 0 ? _a : "DPoP",
|
|
603
|
+
}, this.events);
|
|
604
|
+
return new Promise(() => { });
|
|
605
|
+
};
|
|
606
|
+
this.fetch = (url, init) => this.clientAuthentication.fetch(url, init);
|
|
607
|
+
this.internalLogout = async (emitSignal, options) => {
|
|
608
|
+
window.localStorage.removeItem(KEY_CURRENT_SESSION);
|
|
609
|
+
await this.clientAuthentication.logout(this.info.sessionId, options);
|
|
610
|
+
this.info.isLoggedIn = false;
|
|
611
|
+
if (emitSignal) {
|
|
612
|
+
this.events.emit(solidClientAuthnCore.EVENTS.LOGOUT);
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
this.logout = async (options) => this.internalLogout(true, options);
|
|
616
|
+
this.handleIncomingRedirect = async (inputOptions = {}) => {
|
|
617
|
+
var _a;
|
|
618
|
+
if (this.info.isLoggedIn) {
|
|
619
|
+
return this.info;
|
|
620
|
+
}
|
|
621
|
+
if (this.tokenRequestInProgress) {
|
|
622
|
+
return undefined;
|
|
623
|
+
}
|
|
624
|
+
const options = typeof inputOptions === "string" ? { url: inputOptions } : inputOptions;
|
|
625
|
+
const url = (_a = options.url) !== null && _a !== void 0 ? _a : window.location.href;
|
|
626
|
+
this.tokenRequestInProgress = true;
|
|
627
|
+
const sessionInfo = await this.clientAuthentication.handleIncomingRedirect(url, this.events);
|
|
628
|
+
if (isLoggedIn(sessionInfo)) {
|
|
629
|
+
this.setSessionInfo(sessionInfo);
|
|
630
|
+
const currentUrl = window.localStorage.getItem(KEY_CURRENT_URL);
|
|
631
|
+
if (currentUrl === null) {
|
|
632
|
+
this.events.emit(solidClientAuthnCore.EVENTS.LOGIN);
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
window.localStorage.removeItem(KEY_CURRENT_URL);
|
|
636
|
+
this.events.emit(solidClientAuthnCore.EVENTS.SESSION_RESTORED, currentUrl);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
else if (options.restorePreviousSession === true) {
|
|
640
|
+
const storedSessionId = window.localStorage.getItem(KEY_CURRENT_SESSION);
|
|
641
|
+
if (storedSessionId !== null) {
|
|
642
|
+
const attemptedSilentAuthentication = await silentlyAuthenticate(storedSessionId, this.clientAuthentication, this);
|
|
643
|
+
if (attemptedSilentAuthentication) {
|
|
644
|
+
return new Promise(() => { });
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
this.tokenRequestInProgress = false;
|
|
649
|
+
return sessionInfo;
|
|
650
|
+
};
|
|
651
|
+
this.events = new Proxy(this, solidClientAuthnCore.buildProxyHandler(Session.prototype, "events only implements ISessionEventListener"));
|
|
652
|
+
if (sessionOptions.clientAuthentication) {
|
|
653
|
+
this.clientAuthentication = sessionOptions.clientAuthentication;
|
|
654
|
+
}
|
|
655
|
+
else if (sessionOptions.secureStorage && sessionOptions.insecureStorage) {
|
|
656
|
+
this.clientAuthentication = getClientAuthenticationWithDependencies({
|
|
657
|
+
secureStorage: sessionOptions.secureStorage,
|
|
658
|
+
insecureStorage: sessionOptions.insecureStorage,
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
this.clientAuthentication = getClientAuthenticationWithDependencies({});
|
|
663
|
+
}
|
|
664
|
+
if (sessionOptions.sessionInfo) {
|
|
665
|
+
this.info = {
|
|
666
|
+
sessionId: sessionOptions.sessionInfo.sessionId,
|
|
667
|
+
isLoggedIn: false,
|
|
668
|
+
webId: sessionOptions.sessionInfo.webId,
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
this.info = {
|
|
673
|
+
sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : uuid.v4(),
|
|
674
|
+
isLoggedIn: false,
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
this.events.on(solidClientAuthnCore.EVENTS.LOGIN, () => window.localStorage.setItem(KEY_CURRENT_SESSION, this.info.sessionId));
|
|
678
|
+
this.events.on(solidClientAuthnCore.EVENTS.SESSION_EXPIRED, () => this.internalLogout(false));
|
|
679
|
+
this.events.on(solidClientAuthnCore.EVENTS.ERROR, () => this.internalLogout(false));
|
|
680
|
+
}
|
|
681
|
+
onLogin(callback) {
|
|
682
|
+
this.events.on(solidClientAuthnCore.EVENTS.LOGIN, callback);
|
|
683
|
+
}
|
|
684
|
+
onLogout(callback) {
|
|
685
|
+
this.events.on(solidClientAuthnCore.EVENTS.LOGOUT, callback);
|
|
686
|
+
}
|
|
687
|
+
onError(callback) {
|
|
688
|
+
this.events.on(solidClientAuthnCore.EVENTS.ERROR, callback);
|
|
689
|
+
}
|
|
690
|
+
onSessionRestore(callback) {
|
|
691
|
+
this.events.on(solidClientAuthnCore.EVENTS.SESSION_RESTORED, callback);
|
|
692
|
+
}
|
|
693
|
+
onSessionExpiration(callback) {
|
|
694
|
+
this.events.on(solidClientAuthnCore.EVENTS.SESSION_EXPIRED, callback);
|
|
695
|
+
}
|
|
696
|
+
setSessionInfo(sessionInfo) {
|
|
697
|
+
this.info.isLoggedIn = sessionInfo.isLoggedIn;
|
|
698
|
+
this.info.webId = sessionInfo.webId;
|
|
699
|
+
this.info.sessionId = sessionInfo.sessionId;
|
|
700
|
+
this.info.expirationDate = sessionInfo.expirationDate;
|
|
701
|
+
this.events.on(solidClientAuthnCore.EVENTS.SESSION_EXTENDED, (expiresIn) => {
|
|
702
|
+
this.info.expirationDate = Date.now() + expiresIn * 1000;
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
let defaultSession;
|
|
708
|
+
function getDefaultSession() {
|
|
709
|
+
if (typeof defaultSession === "undefined") {
|
|
710
|
+
defaultSession = new Session();
|
|
711
|
+
}
|
|
712
|
+
return defaultSession;
|
|
713
|
+
}
|
|
714
|
+
const fetch = (...args) => {
|
|
715
|
+
const session = getDefaultSession();
|
|
716
|
+
return session.fetch(...args);
|
|
717
|
+
};
|
|
718
|
+
const login = (...args) => {
|
|
719
|
+
const session = getDefaultSession();
|
|
720
|
+
return session.login(...args);
|
|
721
|
+
};
|
|
722
|
+
const logout = (...args) => {
|
|
723
|
+
const session = getDefaultSession();
|
|
724
|
+
return session.logout(...args);
|
|
725
|
+
};
|
|
726
|
+
const handleIncomingRedirect = (...args) => {
|
|
727
|
+
const session = getDefaultSession();
|
|
728
|
+
return session.handleIncomingRedirect(...args);
|
|
729
|
+
};
|
|
730
|
+
const onLogin = (...args) => {
|
|
731
|
+
const session = getDefaultSession();
|
|
732
|
+
return session.onLogin(...args);
|
|
733
|
+
};
|
|
734
|
+
const onLogout = (...args) => {
|
|
735
|
+
const session = getDefaultSession();
|
|
736
|
+
return session.onLogout(...args);
|
|
737
|
+
};
|
|
738
|
+
const onSessionRestore = (...args) => {
|
|
739
|
+
const session = getDefaultSession();
|
|
740
|
+
return session.onSessionRestore(...args);
|
|
741
|
+
};
|
|
742
|
+
const events = () => {
|
|
743
|
+
return getDefaultSession().events;
|
|
744
|
+
};
|
|
745
|
+
|
|
746
|
+
Object.defineProperty(exports, 'ConfigurationError', {
|
|
747
|
+
enumerable: true,
|
|
748
|
+
get: function () { return solidClientAuthnCore.ConfigurationError; }
|
|
749
|
+
});
|
|
750
|
+
Object.defineProperty(exports, 'EVENTS', {
|
|
751
|
+
enumerable: true,
|
|
752
|
+
get: function () { return solidClientAuthnCore.EVENTS; }
|
|
753
|
+
});
|
|
754
|
+
Object.defineProperty(exports, 'InMemoryStorage', {
|
|
755
|
+
enumerable: true,
|
|
756
|
+
get: function () { return solidClientAuthnCore.InMemoryStorage; }
|
|
757
|
+
});
|
|
758
|
+
Object.defineProperty(exports, 'NotImplementedError', {
|
|
759
|
+
enumerable: true,
|
|
760
|
+
get: function () { return solidClientAuthnCore.NotImplementedError; }
|
|
761
|
+
});
|
|
762
|
+
exports.Session = Session;
|
|
763
|
+
exports.events = events;
|
|
764
|
+
exports.fetch = fetch;
|
|
765
|
+
exports.getClientAuthenticationWithDependencies = getClientAuthenticationWithDependencies;
|
|
766
|
+
exports.getDefaultSession = getDefaultSession;
|
|
767
|
+
exports.handleIncomingRedirect = handleIncomingRedirect;
|
|
768
|
+
exports.login = login;
|
|
769
|
+
exports.logout = logout;
|
|
770
|
+
exports.onLogin = onLogin;
|
|
771
|
+
exports.onLogout = onLogout;
|
|
772
|
+
exports.onSessionRestore = onSessionRestore;
|
|
773
|
+
//# sourceMappingURL=index.js.map
|