@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
@@ -1,6 +1,13 @@
1
+ /**
2
+ * @hidden
3
+ * @packageDocumentation
4
+ */
1
5
  import type { ISessionInfo, ISessionInternalInfo, ILoginOptions } from "@inrupt/solid-client-authn-core";
2
6
  import { ClientAuthentication as ClientAuthenticationBase } from "@inrupt/solid-client-authn-core";
3
7
  import type { EventEmitter } from "events";
8
+ /**
9
+ * @hidden
10
+ */
4
11
  export default class ClientAuthentication extends ClientAuthenticationBase {
5
12
  login: (options: ILoginOptions, eventEmitter: EventEmitter) => Promise<void>;
6
13
  validateCurrentSession: (currentSessionId: string) => Promise<(ISessionInfo & ISessionInternalInfo) | null>;
package/dist/Session.d.ts CHANGED
@@ -1,35 +1,209 @@
1
1
  /// <reference types="node" />
2
+ /**
3
+ * @hidden
4
+ */
2
5
  import type { ILoginInputOptions, ISessionInfo, IStorage, IHasSessionEventListener, ISessionEventListener, ILogoutOptions } from "@inrupt/solid-client-authn-core";
3
6
  import type { fetch } from "@inrupt/universal-fetch";
4
7
  import EventEmitter from "events";
5
8
  import type ClientAuthentication from "./ClientAuthentication";
6
9
  export interface ISessionOptions {
10
+ /**
11
+ * A private storage, unreachable to other scripts on the page. Typically in-memory.
12
+ */
7
13
  secureStorage: IStorage;
14
+ /**
15
+ * A storage where non-sensitive information may be stored, potentially longer-lived than the secure storage.
16
+ */
8
17
  insecureStorage: IStorage;
18
+ /**
19
+ * Details about the current session
20
+ */
9
21
  sessionInfo: ISessionInfo;
22
+ /**
23
+ * An instance of the library core. Typically obtained using `getClientAuthenticationWithDependencies`.
24
+ */
10
25
  clientAuthentication: ClientAuthentication;
11
26
  }
12
27
  export interface IHandleIncomingRedirectOptions {
28
+ /**
29
+ * If the user has signed in before, setting this to `true` will automatically
30
+ * redirect them to their Solid Identity Provider, which will then attempt to
31
+ * re-activate the session and send the user back to your app without
32
+ * requiring user interaction.
33
+ * If your app's access has not expired yet and re-activation completed
34
+ * successfully, a `sessionRestore` event will be fired with the URL the user
35
+ * was at before they were redirected to their Solid Identity Provider.
36
+ * {@see onSessionRestore}
37
+ */
13
38
  restorePreviousSession?: boolean;
39
+ /**
40
+ * Inrupt's Enterprise Solid Server can set a cookie to allow the browser to
41
+ * access private resources on a Pod. In order to mitigate the logout-on-refresh
42
+ * issue on the short term, the server also implemented a session endpoint
43
+ * enabling the client app to know whether the cookie is set. When a user
44
+ * logs in to a server that has that capability enabled, applications that set
45
+ * this option to `true` will be able to make use of it.
46
+ *
47
+ * If your app supports the newest session restore approach, and `restorePreviousSession`
48
+ * is set to true, this option is automatically set to false, but your app will
49
+ * not be logged out when reloaded.
50
+ *
51
+ * `useEssSession` defaults to false and will be removed in the future; to
52
+ * preserve sessions across page reloads, use of `restorePreviousSession` is
53
+ * recommended.
54
+ *
55
+ * @deprecated unreleased
56
+ */
14
57
  useEssSession?: boolean;
58
+ /**
59
+ * The URL of the page handling the redirect, including the query
60
+ * parameters — these contain the information to process the login.
61
+ * Note: as a convenience, if no URL value is specified here, we default to
62
+ * using the browser's current location.
63
+ */
15
64
  url?: string;
16
65
  }
17
66
  export declare function silentlyAuthenticate(sessionId: string, clientAuthn: ClientAuthentication, session: Session): Promise<boolean>;
67
+ /**
68
+ * 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.
69
+ */
18
70
  export declare class Session extends EventEmitter implements IHasSessionEventListener {
71
+ /**
72
+ * Information regarding the current session.
73
+ */
19
74
  readonly info: ISessionInfo;
75
+ /**
76
+ * Session attribute exposing the EventEmitter interface, to listen on session
77
+ * events such as login, logout, etc.
78
+ * @since 1.15.0
79
+ */
20
80
  readonly events: ISessionEventListener;
21
81
  private clientAuthentication;
22
82
  private tokenRequestInProgress;
83
+ /**
84
+ * Session object constructor. Typically called as follows:
85
+ *
86
+ * ```typescript
87
+ * const session = new Session();
88
+ * ```
89
+ *
90
+ * See also [getDefaultSession](https://docs.inrupt.com/developer-tools/api/javascript/solid-client-authn-browser/functions.html#getdefaultsession).
91
+ *
92
+ * @param sessionOptions The options enabling the correct instantiation of
93
+ * the session. Either both storages or clientAuthentication are required. For
94
+ * more information, see {@link ISessionOptions}.
95
+ * @param sessionId A string uniquely identifying the session.
96
+ *
97
+ */
23
98
  constructor(sessionOptions?: Partial<ISessionOptions>, sessionId?: string | undefined);
99
+ /**
100
+ * Triggers the login process. Note that this method will redirect the user away from your app.
101
+ *
102
+ * @param options Parameter to customize the login behaviour. In particular, two options are mandatory: `options.oidcIssuer`, the user's identity provider, and `options.redirectUrl`, the URL to which the user will be redirected after logging in their identity provider.
103
+ * @returns This method should redirect the user away from the app: it does not return anything. The login process is completed by {@linkcode handleIncomingRedirect}.
104
+ */
24
105
  login: (options: ILoginInputOptions) => Promise<void>;
106
+ /**
107
+ * Fetches data using available login information. If the user is not logged in, this will behave as a regular `fetch`. The signature of this method is identical to the [canonical `fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
108
+ *
109
+ * @param url The URL from which data should be fetched.
110
+ * @param init Optional parameters customizing the request, by specifying an HTTP method, headers, a body, etc. Follows the [WHATWG Fetch Standard](https://fetch.spec.whatwg.org/).
111
+ */
25
112
  fetch: typeof fetch;
113
+ /**
114
+ * An internal logout function, to control whether or not the logout signal
115
+ * should be sent, i.e. if the logout was user-initiated or is the result of
116
+ * an external event.
117
+ *
118
+ * @hidden
119
+ */
26
120
  private internalLogout;
121
+ /**
122
+ * Logs the user out of the application.
123
+ *
124
+ * There are 2 types of logout supported by this library,
125
+ * `app` logout and `idp` logout.
126
+ *
127
+ * App logout will log the user out within the application
128
+ * by clearing any session data from the browser. It does
129
+ * not log the user out of their Solid identity provider,
130
+ * and should not redirect the user away.
131
+ * App logout can be performed as follows:
132
+ * ```typescript
133
+ * await session.logout({ logoutType: 'app' });
134
+ * ```
135
+ *
136
+ * IDP logout will log the user out of their Solid identity provider,
137
+ * and will redirect the user away from the application to do so. In order
138
+ * for users to be redirected back to `postLogoutUrl` you MUST include the
139
+ * `postLogoutUrl` value in the `post_logout_redirect_uris` field in the
140
+ * [Client ID Document](https://docs.inrupt.com/ess/latest/security/authentication/#client-identifier-client-id).
141
+ * IDP logout can be performed as follows:
142
+ * ```typescript
143
+ * await session.logout({
144
+ * logoutType: 'idp',
145
+ * // An optional URL to redirect to after logout has completed;
146
+ * // this MUST match a logout URL listed in the Client ID Document
147
+ * // of the application that is logged in.
148
+ * // If the application is logged in with a Client ID that is not
149
+ * // a URI dereferencing to a Client ID Document then users will
150
+ * // not be redirected back to the `postLogoutUrl` after logout.
151
+ * postLogoutUrl: 'https://example.com/logout',
152
+ * // An optional value to be included in the query parameters
153
+ * // when the IDP provider redirects the user to the postLogoutRedirectUrl.
154
+ * state: "my-state"
155
+ * });
156
+ * ```
157
+ */
27
158
  logout: (options?: ILogoutOptions) => Promise<void>;
159
+ /**
160
+ * Completes the login process by processing the information provided by the
161
+ * Solid identity provider through redirect.
162
+ *
163
+ * @param options See {@see IHandleIncomingRedirectOptions}.
164
+ */
28
165
  handleIncomingRedirect: (inputOptions?: string | IHandleIncomingRedirectOptions) => Promise<ISessionInfo | undefined>;
166
+ /**
167
+ * Register a callback function to be called when a user completes login.
168
+ *
169
+ * The callback is called when {@link handleIncomingRedirect} completes successfully.
170
+ *
171
+ * @param callback The function called when a user completes login.
172
+ * @deprecated Prefer session.events.on(EVENTS.LOGIN, callback)
173
+ */
29
174
  onLogin(callback: () => unknown): void;
175
+ /**
176
+ * Register a callback function to be called when a user logs out:
177
+ *
178
+ * @param callback The function called when a user completes logout.
179
+ * @deprecated Prefer session.events.on(EVENTS.LOGOUT, callback)
180
+ */
30
181
  onLogout(callback: () => unknown): void;
182
+ /**
183
+ * Register a callback function to be called when a user logs out:
184
+ *
185
+ * @param callback The function called when an error occurs.
186
+ * @since 1.11.0
187
+ * @deprecated Prefer session.events.on(EVENTS.ERROR, callback)
188
+ */
31
189
  onError(callback: (error: string | null, errorDescription?: string | null) => unknown): void;
190
+ /**
191
+ * Register a callback function to be called when a session is restored.
192
+ *
193
+ * Note: the callback will be called with the saved value of the 'current URL'
194
+ * at the time the session was restored.
195
+ *
196
+ * @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.
197
+ * @deprecated Prefer session.events.on(EVENTS.SESSION_RESTORED, callback)
198
+ */
32
199
  onSessionRestore(callback: (currentUrl: string) => unknown): void;
200
+ /**
201
+ * Register a callback that runs when the session expires and can no longer
202
+ * make authenticated requests, but following a user logout.
203
+ * @param callback The function that runs on session expiration.
204
+ * @since 1.11.0
205
+ * @deprecated Prefer session.events.on(EVENTS.SESSION_EXPIRED, callback)
206
+ */
33
207
  onSessionExpiration(callback: () => unknown): void;
34
208
  private setSessionInfo;
35
209
  }
@@ -1,2 +1,2 @@
1
- export declare const KEY_CURRENT_SESSION: string;
2
- export declare const KEY_CURRENT_URL: string;
1
+ export declare const KEY_CURRENT_SESSION = "solidClientAuthn:currentSession";
2
+ export declare const KEY_CURRENT_URL = "solidClientAuthn:currentUrl";
@@ -1,10 +1,80 @@
1
1
  import { Session } from "./Session";
2
+ /**
3
+ * Obtain the {@link Session} used when not explicitly instantiating one yourself.
4
+ *
5
+ * When using the top-level exports {@link fetch}, {@link login}, {@link logout},
6
+ * {@link handleIncomingRedirect}, {@link onLogin} and {@link onLogout}, these apply to an
7
+ * implicitly-instantiated {@link Session}.
8
+ * This function returns a reference to that Session in order to obtain e.g. the current user's
9
+ * WebID.
10
+ * @since 1.3.0
11
+ */
2
12
  export declare function getDefaultSession(): Session;
13
+ /**
14
+ * This function's signature is equal to `window.fetch`, but if the current user is authenticated
15
+ * (see [[login]] and [[handleIncomingRedirect]]), requests made using it will include that user's
16
+ * credentials. If not, this will behave just like the regular `window.fetch`.
17
+ *
18
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch}
19
+ * @since 1.3.0
20
+ */
3
21
  export declare const fetch: Session["fetch"];
22
+ /**
23
+ * Triggers the login process. Note that this method will redirect the user away from your app.
24
+ *
25
+ * @param options Parameter to customize the login behaviour. In particular, two options are mandatory: `options.oidcIssuer`, the user's identity provider, and `options.redirectUrl`, the URL to which the user will be redirected after logging in their identity provider.
26
+ * @returns This method should redirect the user away from the app: it does not return anything. The login process is completed by [[handleIncomingRedirect]].
27
+ * @since 1.3.0
28
+ */
4
29
  export declare const login: Session["login"];
30
+ /**
31
+ * Logs the user out of the application.
32
+ *
33
+ * By default this does not log the user out of their Solid identity provider.
34
+ * In order to do so, you must set the logoutType to `idp`. For usage details
35
+ * see {@link Session.logout}.
36
+ *
37
+ * @since 1.3.0
38
+ */
5
39
  export declare const logout: Session["logout"];
40
+ /**
41
+ * Completes the login process by processing the information provided by the Solid identity provider through redirect.
42
+ *
43
+ * @param url The URL of the page handling the redirect, including the query parameters — these contain the information to process the login.
44
+ * @since 1.3.0
45
+ */
6
46
  export declare const handleIncomingRedirect: Session["handleIncomingRedirect"];
47
+ /**
48
+ * Register a callback function to be called when a user completes login.
49
+ *
50
+ * The callback is called when {@link handleIncomingRedirect} completes successfully.
51
+ * @since 1.3.0
52
+ *
53
+ * @param callback The function called when a user completes login.
54
+ * @deprecated Prefer events.on(EVENTS.LOGIN, callback)
55
+
56
+ */
7
57
  export declare const onLogin: Session["onLogin"];
58
+ /**
59
+ * Register a callback function to be called when a user logs out:
60
+ *
61
+ * @param callback The function called when a user completes logout.
62
+ * @since 1.3.0
63
+ * @deprecated Prefer events.on(EVENTS.LOGOUT, callback)
64
+ *
65
+ */
8
66
  export declare const onLogout: Session["onLogout"];
67
+ /**
68
+ * Register a callback function to be called when a session is restored:
69
+ *
70
+ * @param callback The function called when a session is restored.
71
+ * @since 1.3.0
72
+ * @deprecated Prefer events.on(EVENTS.SESSION_RESTORED, callback)
73
+ */
9
74
  export declare const onSessionRestore: Session["onSessionRestore"];
75
+ /**
76
+ * {@link SessionEventEmitter} instance to subscribe to events by the default session.
77
+ *
78
+ * @since 1.14.0
79
+ */
10
80
  export declare const events: () => Session["events"];
@@ -1,5 +1,17 @@
1
+ /**
2
+ * @hidden
3
+ * @packageDocumentation
4
+ */
5
+ /**
6
+ * Top Level core document. Responsible for setting up the dependency graph
7
+ */
1
8
  import type { IStorage } from "@inrupt/solid-client-authn-core";
2
9
  import ClientAuthentication from "./ClientAuthentication";
10
+ /**
11
+ *
12
+ * @param dependencies
13
+ * @deprecated This function will be removed from the external API in an upcoming release.
14
+ */
3
15
  export declare function getClientAuthenticationWithDependencies(dependencies: {
4
16
  secureStorage?: IStorage;
5
17
  insecureStorage?: IStorage;