@inrupt/solid-client-authn-browser 1.17.1 → 1.17.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.
Files changed (58) hide show
  1. package/dist/ClientAuthentication.d.ts +7 -0
  2. package/dist/Session.d.ts +174 -0
  3. package/dist/constant.d.ts +2 -2
  4. package/dist/defaultSession.d.ts +70 -0
  5. package/dist/dependencies.d.ts +12 -0
  6. package/dist/index.js +833 -34
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +833 -34
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/login/oidc/AggregateOidcHandler.d.ts +10 -0
  11. package/dist/login/oidc/AggregateRedirectHandler.d.ts +10 -0
  12. package/dist/login/oidc/ClientRegistrar.d.ts +7 -0
  13. package/dist/login/oidc/IssuerConfigFetcher.d.ts +10 -0
  14. package/dist/login/oidc/OidcLoginHandler.d.ts +10 -0
  15. package/dist/login/oidc/Redirector.d.ts +7 -0
  16. package/dist/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.d.ts +3 -0
  17. package/dist/login/oidc/incomingRedirectHandler/ErrorOidcHandler.d.ts +10 -0
  18. package/dist/login/oidc/incomingRedirectHandler/FallbackRedirectHandler.d.ts +10 -0
  19. package/dist/login/oidc/oidcHandlers/AuthorizationCodeWithPkceOidcHandler.d.ts +12 -0
  20. package/dist/login/oidc/refresh/TokenRefresher.d.ts +7 -0
  21. package/dist/logout/buildRpInitiatedLogout.d.ts +7 -0
  22. package/dist/sessionInfo/SessionInfoManager.d.ts +18 -0
  23. package/dist/solid-client-authn.bundle.js +7 -7
  24. package/dist/solid-client-authn.bundle.js.map +1 -1
  25. package/dist/storage/BrowserStorage.d.ts +7 -0
  26. package/dist/storage/StorageUtility.d.ts +14 -0
  27. package/dist/util/UuidGenerator.d.ts +6 -0
  28. package/package.json +8 -8
  29. package/rollup.config.mjs +1 -1
  30. package/src/ClientAuthentication.spec.ts +106 -57
  31. package/src/ClientAuthentication.ts +18 -7
  32. package/src/Session.spec.ts +51 -54
  33. package/src/Session.ts +24 -18
  34. package/src/__mocks__/ClientAuthentication.ts +2 -2
  35. package/src/defaultSession.ts +4 -3
  36. package/src/dependencies.ts +5 -5
  37. package/src/login/oidc/ClientRegistrar.spec.ts +22 -22
  38. package/src/login/oidc/ClientRegistrar.ts +4 -2
  39. package/src/login/oidc/IssuerConfigFetcher.spec.ts +25 -25
  40. package/src/login/oidc/IssuerConfigFetcher.ts +8 -6
  41. package/src/login/oidc/OidcLoginHandler.spec.ts +15 -15
  42. package/src/login/oidc/OidcLoginHandler.ts +14 -9
  43. package/src/login/oidc/Redirector.spec.ts +1 -1
  44. package/src/login/oidc/__mocks__/ClientRegistrar.ts +3 -3
  45. package/src/login/oidc/__mocks__/IssuerConfigFetcher.ts +3 -3
  46. package/src/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.spec.ts +42 -42
  47. package/src/login/oidc/incomingRedirectHandler/AuthCodeRedirectHandler.ts +19 -13
  48. package/src/login/oidc/incomingRedirectHandler/ErrorOidcHandler.spec.ts +12 -12
  49. package/src/login/oidc/incomingRedirectHandler/ErrorOidcHandler.ts +2 -2
  50. package/src/login/oidc/incomingRedirectHandler/FallbackRedirectHandler.spec.ts +7 -7
  51. package/src/login/oidc/incomingRedirectHandler/FallbackRedirectHandler.ts +2 -2
  52. package/src/login/oidc/oidcHandlers/AuthorizationCodeWithPkceOidcHandler.spec.ts +17 -17
  53. package/src/login/oidc/refresh/TokenRefresher.spec.ts +14 -14
  54. package/src/login/oidc/refresh/TokenRefresher.ts +12 -8
  55. package/src/login/oidc/refresh/__mocks__/TokenRefresher.ts +1 -1
  56. package/src/sessionInfo/SessionInfoManager.spec.ts +37 -15
  57. package/src/sessionInfo/SessionInfoManager.ts +46 -50
  58. package/src/sessionInfo/__mocks__/SessionInfoManager.ts +3 -3
@@ -51,7 +51,7 @@ const expectedSigninRedirectUrl = "https://test";
51
51
 
52
52
  const mockOidcModule = (
53
53
  url: string = expectedSigninRedirectUrl,
54
- state = "test state"
54
+ state = "test state",
55
55
  ) => {
56
56
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
57
  const oidcModule = jest.requireMock("@inrupt/oidc-client-ext") as any;
@@ -78,11 +78,11 @@ describe("AuthorizationCodeWithPkceOidcHandler", () => {
78
78
  };
79
79
 
80
80
  function getAuthorizationCodeWithPkceOidcHandler(
81
- mocks: Partial<typeof defaultMocks> = defaultMocks
81
+ mocks: Partial<typeof defaultMocks> = defaultMocks,
82
82
  ): AuthorizationCodeWithPkceOidcHandler {
83
83
  return new AuthorizationCodeWithPkceOidcHandler(
84
84
  mocks.storageUtility ?? defaultMocks.storageUtility,
85
- mocks.redirector ?? defaultMocks.redirector
85
+ mocks.redirector ?? defaultMocks.redirector,
86
86
  );
87
87
  }
88
88
 
@@ -94,11 +94,11 @@ describe("AuthorizationCodeWithPkceOidcHandler", () => {
94
94
  // eslint-disable-next-line jest/valid-title
95
95
  it(testConfig.message, async () => {
96
96
  const value = await authorizationCodeWithPkceOidcHandler.canHandle(
97
- testConfig.oidcOptions
97
+ testConfig.oidcOptions,
98
98
  );
99
99
  expect(value).toBe(testConfig.shouldPass);
100
100
  });
101
- }
101
+ },
102
102
  );
103
103
  });
104
104
 
@@ -110,9 +110,9 @@ describe("AuthorizationCodeWithPkceOidcHandler", () => {
110
110
  mockedRedirector.mockImplementationOnce(
111
111
  (redirectUrl: string, redirectOptions: IRedirectorOptions) => {
112
112
  throw new Error(
113
- `Redirecting to [${redirectUrl}] with options [${redirectOptions}] throws...`
113
+ `Redirecting to [${redirectUrl}] with options [${redirectOptions}] throws...`,
114
114
  );
115
- }
115
+ },
116
116
  );
117
117
 
118
118
  const authorizationCodeWithPkceOidcHandler =
@@ -129,7 +129,7 @@ describe("AuthorizationCodeWithPkceOidcHandler", () => {
129
129
  };
130
130
 
131
131
  await expect(
132
- authorizationCodeWithPkceOidcHandler.handle(oidcOptions)
132
+ authorizationCodeWithPkceOidcHandler.handle(oidcOptions),
133
133
  ).resolves.toBeUndefined();
134
134
 
135
135
  expect(mockedRedirector).toHaveBeenCalledTimes(1);
@@ -141,7 +141,7 @@ describe("AuthorizationCodeWithPkceOidcHandler", () => {
141
141
  // eslint-disable-next-line no-console
142
142
  expect(console.error).toHaveBeenCalledTimes(1);
143
143
  expect(
144
- (console as jest.Mocked<Console>).error.mock.calls[0][0].toString()
144
+ (console as jest.Mocked<Console>).error.mock.calls[0][0].toString(),
145
145
  ).toMatch(/Error: Redirecting to \[[^\]]+\] with options/);
146
146
  });
147
147
 
@@ -161,7 +161,7 @@ describe("AuthorizationCodeWithPkceOidcHandler", () => {
161
161
  expectedSigninRedirectUrl,
162
162
  {
163
163
  handleRedirect: standardOidcOptions.handleRedirect,
164
- }
164
+ },
165
165
  );
166
166
  });
167
167
 
@@ -169,7 +169,7 @@ describe("AuthorizationCodeWithPkceOidcHandler", () => {
169
169
  mockOidcModule();
170
170
  const mockedStorage = new StorageUtility(
171
171
  mockStorage({}),
172
- mockStorage({})
172
+ mockStorage({}),
173
173
  );
174
174
  const authorizationCodeWithPkceOidcHandler =
175
175
  getAuthorizationCodeWithPkceOidcHandler({
@@ -187,12 +187,12 @@ describe("AuthorizationCodeWithPkceOidcHandler", () => {
187
187
  await expect(
188
188
  mockedStorage.getForUser("mySession", "redirectUrl", {
189
189
  secure: false,
190
- })
190
+ }),
191
191
  ).resolves.toBe("https://app.example.com?someQuery=someValue");
192
192
  await expect(
193
193
  mockedStorage.getForUser("mySession", "codeVerifier", {
194
194
  secure: false,
195
- })
195
+ }),
196
196
  ).resolves.not.toBeNull();
197
197
  });
198
198
 
@@ -212,7 +212,7 @@ describe("AuthorizationCodeWithPkceOidcHandler", () => {
212
212
  expect(oidcModule.OidcClient).toHaveBeenCalledWith(
213
213
  expect.objectContaining({
214
214
  prompt: "none",
215
- })
215
+ }),
216
216
  );
217
217
  });
218
218
 
@@ -231,7 +231,7 @@ describe("AuthorizationCodeWithPkceOidcHandler", () => {
231
231
  expect(oidcModule.OidcClient).toHaveBeenCalledWith(
232
232
  expect.objectContaining({
233
233
  prompt: "consent",
234
- })
234
+ }),
235
235
  );
236
236
  });
237
237
 
@@ -250,7 +250,7 @@ describe("AuthorizationCodeWithPkceOidcHandler", () => {
250
250
  expect(oidcModule.OidcClient).toHaveBeenCalledWith(
251
251
  expect.objectContaining({
252
252
  scope: "openid offline_access webid",
253
- })
253
+ }),
254
254
  );
255
255
  });
256
256
 
@@ -274,7 +274,7 @@ describe("AuthorizationCodeWithPkceOidcHandler", () => {
274
274
  expectedSigninRedirectUrl,
275
275
  {
276
276
  handleRedirect: standardOidcOptions.handleRedirect,
277
- }
277
+ },
278
278
  );
279
279
  });
280
280
  });
@@ -125,7 +125,7 @@ const mockOidcModule = async (response?: TokenEndpointResponse) => {
125
125
  dpopKey: await mockKeyPair(),
126
126
  webId: mockWebId(),
127
127
  }
128
- : response
128
+ : response,
129
129
  ) as typeof refresh;
130
130
  return oidcModule;
131
131
  };
@@ -137,12 +137,12 @@ const defaultMocks = {
137
137
  };
138
138
 
139
139
  function getTokenRefresher(
140
- mocks: Partial<typeof defaultMocks> = defaultMocks
140
+ mocks: Partial<typeof defaultMocks> = defaultMocks,
141
141
  ): TokenRefresher {
142
142
  return new TokenRefresher(
143
143
  mocks.storageUtility ?? defaultMocks.storageUtility,
144
144
  mocks.issuerConfigFetcher ?? defaultMocks.issuerConfigFetcher,
145
- mocks.clientRegistrar ?? defaultMocks.clientRegistrar
145
+ mocks.clientRegistrar ?? defaultMocks.clientRegistrar,
146
146
  );
147
147
  }
148
148
 
@@ -156,9 +156,9 @@ describe("TokenRefresher", () => {
156
156
  });
157
157
 
158
158
  await expect(
159
- refresher.refresh("mySession", "some refresh token")
159
+ refresher.refresh("mySession", "some refresh token"),
160
160
  ).rejects.toThrow(
161
- "Failed to retrieve OIDC context from storage associated with session [mySession]"
161
+ "Failed to retrieve OIDC context from storage associated with session [mySession]",
162
162
  );
163
163
  });
164
164
 
@@ -174,9 +174,9 @@ describe("TokenRefresher", () => {
174
174
  });
175
175
 
176
176
  await expect(
177
- refresher.refresh("mySession", "some refresh token")
177
+ refresher.refresh("mySession", "some refresh token"),
178
178
  ).rejects.toThrow(
179
- "Failed to retrieve OIDC context from storage associated with session [mySession]"
179
+ "Failed to retrieve OIDC context from storage associated with session [mySession]",
180
180
  );
181
181
  });
182
182
 
@@ -188,7 +188,7 @@ describe("TokenRefresher", () => {
188
188
  });
189
189
 
190
190
  await expect(refresher.refresh("mySession")).rejects.toThrow(
191
- "Session [mySession] has no refresh token to allow it to refresh its access token."
191
+ "Session [mySession] has no refresh token to allow it to refresh its access token.",
192
192
  );
193
193
  });
194
194
 
@@ -200,9 +200,9 @@ describe("TokenRefresher", () => {
200
200
  });
201
201
 
202
202
  await expect(
203
- refresher.refresh("mySession", "some refresh token")
203
+ refresher.refresh("mySession", "some refresh token"),
204
204
  ).rejects.toThrow(
205
- "For session [mySession], the key bound to the DPoP access token must be provided to refresh said access token."
205
+ "For session [mySession], the key bound to the DPoP access token must be provided to refresh said access token.",
206
206
  );
207
207
  });
208
208
 
@@ -217,7 +217,7 @@ describe("TokenRefresher", () => {
217
217
  const result = await refresher.refresh(
218
218
  "mySession",
219
219
  "some refresh token",
220
- await mockKeyPair()
220
+ await mockKeyPair(),
221
221
  );
222
222
  expect(oidcModule.refresh).toHaveBeenCalled();
223
223
  expect(result).toEqual({
@@ -246,11 +246,11 @@ describe("TokenRefresher", () => {
246
246
  "mySession",
247
247
  "some old refresh token",
248
248
  await mockKeyPair(),
249
- mockEmitter
249
+ mockEmitter,
250
250
  );
251
251
  expect(mockEmit).toHaveBeenCalledWith(
252
252
  EVENTS.NEW_REFRESH_TOKEN,
253
- "Some rotated refresh token"
253
+ "Some rotated refresh token",
254
254
  );
255
255
  });
256
256
 
@@ -268,7 +268,7 @@ describe("TokenRefresher", () => {
268
268
  const result = await refresher.refresh(
269
269
  "mySession",
270
270
  "some refresh token",
271
- await mockKeyPair()
271
+ await mockKeyPair(),
272
272
  );
273
273
  expect(result.refreshToken).toBe("Some rotated refresh token");
274
274
  });
@@ -51,36 +51,40 @@ export default class TokenRefresher implements ITokenRefresher {
51
51
  constructor(
52
52
  private storageUtility: IStorageUtility,
53
53
  private issuerConfigFetcher: IIssuerConfigFetcher,
54
- private clientRegistrar: IClientRegistrar
55
- ) {}
54
+ private clientRegistrar: IClientRegistrar,
55
+ ) {
56
+ this.storageUtility = storageUtility;
57
+ this.issuerConfigFetcher = issuerConfigFetcher;
58
+ this.clientRegistrar = clientRegistrar;
59
+ }
56
60
 
57
61
  async refresh(
58
62
  sessionId: string,
59
63
  refreshToken?: string,
60
64
  dpopKey?: KeyPair,
61
- eventEmitter?: EventEmitter
65
+ eventEmitter?: EventEmitter,
62
66
  ): Promise<TokenEndpointResponse> {
63
67
  const oidcContext = await loadOidcContextFromStorage(
64
68
  sessionId,
65
69
  this.storageUtility,
66
- this.issuerConfigFetcher
70
+ this.issuerConfigFetcher,
67
71
  );
68
72
  // This should also retrieve the client from storage
69
73
  const clientInfo: IClient = await this.clientRegistrar.getClient(
70
74
  { sessionId },
71
- oidcContext.issuerConfig
75
+ oidcContext.issuerConfig,
72
76
  );
73
77
 
74
78
  if (refreshToken === undefined) {
75
79
  // TODO: in a next PR, look up storage for a refresh token
76
80
  throw new Error(
77
- `Session [${sessionId}] has no refresh token to allow it to refresh its access token.`
81
+ `Session [${sessionId}] has no refresh token to allow it to refresh its access token.`,
78
82
  );
79
83
  }
80
84
 
81
85
  if (oidcContext.dpop && dpopKey === undefined) {
82
86
  throw new Error(
83
- `For session [${sessionId}], the key bound to the DPoP access token must be provided to refresh said access token.`
87
+ `For session [${sessionId}], the key bound to the DPoP access token must be provided to refresh said access token.`,
84
88
  );
85
89
  }
86
90
 
@@ -88,7 +92,7 @@ export default class TokenRefresher implements ITokenRefresher {
88
92
  refreshToken,
89
93
  oidcContext.issuerConfig,
90
94
  clientInfo,
91
- dpopKey
95
+ dpopKey,
92
96
  );
93
97
 
94
98
  if (tokenSet.refreshToken !== undefined) {
@@ -29,7 +29,7 @@ import type {
29
29
  /* eslint-disable camelcase */
30
30
 
31
31
  export const mockTokenRefresher = (
32
- tokenSet: TokenEndpointResponse
32
+ tokenSet: TokenEndpointResponse,
33
33
  ): ITokenRefresher => {
34
34
  return {
35
35
  refresh: jest.fn<ITokenRefresher["refresh"]>().mockResolvedValue(tokenSet),
@@ -47,10 +47,10 @@ describe("SessionInfoManager", () => {
47
47
  };
48
48
 
49
49
  function getSessionInfoManager(
50
- mocks: Partial<typeof defaultMocks> = defaultMocks
50
+ mocks: Partial<typeof defaultMocks> = defaultMocks,
51
51
  ): SessionInfoManager {
52
52
  const sessionManager = new SessionInfoManager(
53
- mocks.storageUtility ?? defaultMocks.storageUtility
53
+ mocks.storageUtility ?? defaultMocks.storageUtility,
54
54
  );
55
55
  return sessionManager;
56
56
  }
@@ -59,7 +59,7 @@ describe("SessionInfoManager", () => {
59
59
  it("is not implemented yet", async () => {
60
60
  const sessionManager = getSessionInfoManager();
61
61
  await expect(async () =>
62
- sessionManager.update("commanderCool", {})
62
+ sessionManager.update("commanderCool", {}),
63
63
  ).rejects.toThrow("Not Implemented");
64
64
  });
65
65
  });
@@ -68,7 +68,7 @@ describe("SessionInfoManager", () => {
68
68
  it("is not implemented yet", async () => {
69
69
  const sessionManager = getSessionInfoManager();
70
70
  await expect(async () =>
71
- sessionManager.register("commanderCool")
71
+ sessionManager.register("commanderCool"),
72
72
  ).rejects.toThrow("Not implemented");
73
73
  });
74
74
  });
@@ -77,7 +77,7 @@ describe("SessionInfoManager", () => {
77
77
  it("is not implemented yet", async () => {
78
78
  const sessionManager = getSessionInfoManager();
79
79
  await expect(async () =>
80
- sessionManager.getRegisteredSessionIdAll()
80
+ sessionManager.getRegisteredSessionIdAll(),
81
81
  ).rejects.toThrow("Not implemented");
82
82
  });
83
83
  });
@@ -86,7 +86,7 @@ describe("SessionInfoManager", () => {
86
86
  it("is not implemented yet", async () => {
87
87
  const sessionManager = getSessionInfoManager();
88
88
  await expect(async () => sessionManager.clearAll()).rejects.toThrow(
89
- "Not implemented"
89
+ "Not implemented",
90
90
  );
91
91
  });
92
92
  });
@@ -113,7 +113,7 @@ describe("SessionInfoManager", () => {
113
113
  issuer: "https://some.issuer",
114
114
  tokenType: "DPoP",
115
115
  },
116
- })
116
+ }),
117
117
  );
118
118
 
119
119
  const sessionManager = getSessionInfoManager({
@@ -141,7 +141,7 @@ describe("SessionInfoManager", () => {
141
141
  isLoggedIn: "false",
142
142
  },
143
143
  }),
144
- mockStorage({})
144
+ mockStorage({}),
145
145
  );
146
146
 
147
147
  const sessionManager = getSessionInfoManager({
@@ -161,6 +161,28 @@ describe("SessionInfoManager", () => {
161
161
  });
162
162
  });
163
163
 
164
+ it("returns undefined and clears storage if the redirect URL is invalid", async () => {
165
+ const sessionId = "commanderCool";
166
+ const storageMock = new StorageUtility(
167
+ mockStorage({}),
168
+ mockStorage({
169
+ [`solidClientAuthenticationUser:${sessionId}`]: {
170
+ // The state query parameter is reserved in OpenID.
171
+ redirectUrl: "https://client.example.org/callback?state=1234",
172
+ },
173
+ }),
174
+ );
175
+ const spiedClear = jest.spyOn(storageMock, "deleteAllUserData");
176
+ const sessionManager = getSessionInfoManager({
177
+ storageUtility: storageMock,
178
+ });
179
+
180
+ const session = await sessionManager.get(sessionId);
181
+ expect(session).toBeUndefined();
182
+ expect(spiedClear).toHaveBeenCalledWith(sessionId, { secure: false });
183
+ expect(spiedClear).toHaveBeenCalledWith(sessionId, { secure: true });
184
+ });
185
+
164
186
  it("returns undefined if the specified storage does not contain the user", async () => {
165
187
  const sessionManager = getSessionInfoManager({
166
188
  storageUtility: mockStorageUtility({}, true),
@@ -186,14 +208,14 @@ describe("SessionInfoManager", () => {
186
208
  issuer: "https://my.idp",
187
209
  tokenType: "Some arbitrary token type",
188
210
  },
189
- })
211
+ }),
190
212
  );
191
213
 
192
214
  const sessionManager = getSessionInfoManager({
193
215
  storageUtility: storageMock,
194
216
  });
195
217
  await expect(sessionManager.get(sessionId)).rejects.toThrow(
196
- "Tokens of type [Some arbitrary token type] are not supported."
218
+ "Tokens of type [Some arbitrary token type] are not supported.",
197
219
  );
198
220
  });
199
221
 
@@ -214,7 +236,7 @@ describe("SessionInfoManager", () => {
214
236
  [`solidClientAuthenticationUser:${sessionId}`]: {
215
237
  issuer: "https://my.idp",
216
238
  },
217
- })
239
+ }),
218
240
  );
219
241
 
220
242
  const sessionManager = getSessionInfoManager({
@@ -247,14 +269,14 @@ describe("SessionInfoManager", () => {
247
269
  key: "value",
248
270
  },
249
271
  },
250
- true
272
+ true,
251
273
  );
252
274
  const sessionManager = getSessionInfoManager({
253
275
  storageUtility: mockedStorage,
254
276
  });
255
277
  await sessionManager.clear("mySession");
256
278
  expect(
257
- await mockedStorage.getForUser("mySession", "key", { secure: true })
279
+ await mockedStorage.getForUser("mySession", "key", { secure: true }),
258
280
  ).toBeUndefined();
259
281
  });
260
282
 
@@ -265,14 +287,14 @@ describe("SessionInfoManager", () => {
265
287
  key: "value",
266
288
  },
267
289
  },
268
- false
290
+ false,
269
291
  );
270
292
  const sessionManager = getSessionInfoManager({
271
293
  storageUtility: mockedStorage,
272
294
  });
273
295
  await sessionManager.clear("mySession");
274
296
  expect(
275
- await mockedStorage.getForUser("mySession", "key", { secure: false })
297
+ await mockedStorage.getForUser("mySession", "key", { secure: false }),
276
298
  ).toBeUndefined();
277
299
  });
278
300
  });
@@ -34,6 +34,7 @@ import {
34
34
  isSupportedTokenType,
35
35
  clear as clearBase,
36
36
  SessionInfoManagerBase,
37
+ isValidRedirectUrl,
37
38
  } from "@inrupt/solid-client-authn-core";
38
39
  import { clearOidcPersistentStorage } from "@inrupt/oidc-client-ext";
39
40
 
@@ -46,7 +47,7 @@ export { getUnauthenticatedSession } from "@inrupt/solid-client-authn-core";
46
47
  */
47
48
  export async function clear(
48
49
  sessionId: string,
49
- storage: IStorageUtility
50
+ storage: IStorageUtility,
50
51
  ): Promise<void> {
51
52
  await clearBase(sessionId, storage);
52
53
  await clearOidcPersistentStorage();
@@ -60,62 +61,56 @@ export class SessionInfoManager
60
61
  implements ISessionInfoManager
61
62
  {
62
63
  async get(
63
- sessionId: string
64
+ sessionId: string,
64
65
  ): Promise<(ISessionInfo & ISessionInternalInfo) | undefined> {
65
- const isLoggedIn = await this.storageUtility.getForUser(
66
- sessionId,
67
- "isLoggedIn",
68
- {
66
+ const [
67
+ isLoggedIn,
68
+ webId,
69
+ clientId,
70
+ clientSecret,
71
+ redirectUrl,
72
+ refreshToken,
73
+ issuer,
74
+ tokenType,
75
+ ] = await Promise.all([
76
+ this.storageUtility.getForUser(sessionId, "isLoggedIn", {
69
77
  secure: true,
70
- }
71
- );
72
-
73
- const webId = await this.storageUtility.getForUser(sessionId, "webId", {
74
- secure: true,
75
- });
76
-
77
- const clientId = await this.storageUtility.getForUser(
78
- sessionId,
79
- "clientId",
80
- {
78
+ }),
79
+ this.storageUtility.getForUser(sessionId, "webId", {
80
+ secure: true,
81
+ }),
82
+ this.storageUtility.getForUser(sessionId, "clientId", {
81
83
  secure: false,
82
- }
83
- );
84
-
85
- const clientSecret = await this.storageUtility.getForUser(
86
- sessionId,
87
- "clientSecret",
88
- {
84
+ }),
85
+ this.storageUtility.getForUser(sessionId, "clientSecret", {
89
86
  secure: false,
90
- }
91
- );
92
-
93
- const redirectUrl = await this.storageUtility.getForUser(
94
- sessionId,
95
- "redirectUrl",
96
- {
87
+ }),
88
+ this.storageUtility.getForUser(sessionId, "redirectUrl", {
97
89
  secure: false,
98
- }
99
- );
100
-
101
- const refreshToken = await this.storageUtility.getForUser(
102
- sessionId,
103
- "refreshToken",
104
- {
90
+ }),
91
+ this.storageUtility.getForUser(sessionId, "refreshToken", {
105
92
  secure: true,
106
- }
107
- );
108
-
109
- const issuer = await this.storageUtility.getForUser(sessionId, "issuer", {
110
- secure: false,
111
- });
112
-
113
- const tokenType =
114
- (await this.storageUtility.getForUser(sessionId, "tokenType", {
93
+ }),
94
+ this.storageUtility.getForUser(sessionId, "issuer", {
95
+ secure: false,
96
+ }),
97
+ this.storageUtility.getForUser(sessionId, "tokenType", {
115
98
  secure: false,
116
- })) ?? "DPoP";
99
+ }),
100
+ ]);
101
+
102
+ if (typeof redirectUrl === "string" && !isValidRedirectUrl(redirectUrl)) {
103
+ // This resolves the issue for people experiencing https://github.com/inrupt/solid-client-authn-js/issues/2891.
104
+ // An invalid redirect URL is present in the storage, and the session should
105
+ // be cleared to get a fresh start. This will require the user to log back in.
106
+ await Promise.all([
107
+ this.storageUtility.deleteAllUserData(sessionId, { secure: false }),
108
+ this.storageUtility.deleteAllUserData(sessionId, { secure: true }),
109
+ ]);
110
+ return undefined;
111
+ }
117
112
 
118
- if (!isSupportedTokenType(tokenType)) {
113
+ if (tokenType !== undefined && !isSupportedTokenType(tokenType)) {
119
114
  throw new Error(`Tokens of type [${tokenType}] are not supported.`);
120
115
  }
121
116
 
@@ -137,7 +132,8 @@ export class SessionInfoManager
137
132
  issuer,
138
133
  clientAppId: clientId,
139
134
  clientAppSecret: clientSecret,
140
- tokenType,
135
+ // Default the token type to DPoP if unspecified.
136
+ tokenType: tokenType ?? "DPoP",
141
137
  };
142
138
  }
143
139
 
@@ -40,10 +40,10 @@ export const SessionCreatorGetSessionResponse: ISessionInfo &
40
40
 
41
41
  export const SessionInfoManagerMock: jest.Mocked<ISessionInfoManager> = {
42
42
  update: jest.fn(
43
- async (_sessionId: string, _options: ISessionInfoManagerOptions) => {}
43
+ async (_sessionId: string, _options: ISessionInfoManagerOptions) => {},
44
44
  ),
45
45
  get: jest.fn(async (_sessionId: string) =>
46
- Promise.resolve(SessionCreatorCreateResponse)
46
+ Promise.resolve(SessionCreatorCreateResponse),
47
47
  ),
48
48
  getAll: jest.fn(async () => Promise.resolve([SessionCreatorCreateResponse])),
49
49
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -55,7 +55,7 @@ export const SessionInfoManagerMock: jest.Mocked<ISessionInfoManager> = {
55
55
  } as any;
56
56
 
57
57
  export function mockSessionInfoManager(
58
- storageUtility: IStorageUtility
58
+ storageUtility: IStorageUtility,
59
59
  ): ISessionInfoManager {
60
60
  return new SessionInfoManager(storageUtility);
61
61
  }