@crossauth/frontend 0.0.14 → 0.0.15

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.
@@ -2,7 +2,7 @@ import { CrossauthError } from '@crossauth/common';
2
2
  import { OAuthTokenProvider } from './tokenprovider.ts';
3
3
 
4
4
  /**
5
- * Used by {@link OAuthClient} and {@link OAuthBsffClient} to automatically
5
+ * Used by {@link OAuthClient} and {@link OAuthBffClient} to automatically
6
6
  * refresh access and ID tokens
7
7
  */
8
8
  export declare class OAuthAutoRefresher {
@@ -4,7 +4,10 @@ import { CrossauthError } from '@crossauth/common';
4
4
  * A browser-side OAuth client designed with work with the
5
5
  * backend-for-frontend (BFF) mode of the backend OAuth client.
6
6
  *
7
- * See {@link @crossauth/fastify!FastifyOAuthClient}.
7
+ * You may use this, or alternatively the backend OAuth clients, eg
8
+ *
9
+ * `@crossauth/fastify/FastifyOAuthClient` or
10
+ * .`@crossauth/sveltekit/SvelteKitOAuthClient`
8
11
  */
9
12
  export declare class OAuthBffClient {
10
13
  private bffPrefix;
@@ -64,7 +67,7 @@ export declare class OAuthBffClient {
64
67
  * This only returns something if the ID token was returned to the BFF
65
68
  * client in a previous OAuth call. Otherwise it returns an empty JSON.
66
69
  *
67
- * @param crfToken the CSRF token. If emtpy, one will be fetched before
70
+ * @param csrfToken the CSRF token. If emtpy, one will be fetched before
68
71
  * making the request
69
72
  * @returns the ID token payload or an empty object if there isn't one
70
73
  */
@@ -75,7 +78,7 @@ export declare class OAuthBffClient {
75
78
  * Returns whether or not there is an ID token stored in the BFF server
76
79
  * for this client.
77
80
  *
78
- * @param crfToken the CSRF token. If emtpy, one will be fetched before
81
+ * @param csrfToken the CSRF token. If emtpy, one will be fetched before
79
82
  * making the request
80
83
  * @returns true or false
81
84
  */
@@ -86,10 +89,8 @@ export declare class OAuthBffClient {
86
89
  * This only returns something if the access token was returned to the BFF
87
90
  * client in a previous OAuth call. Otherwise it returns an empty JSON.
88
91
  *
89
- * @param crfToken the CSRF token. If emtpy, one will be fetched before
92
+ * @param csrfToken the CSRF token. If emtpy, one will be fetched before
90
93
  * making the request
91
- * @param headers any additional headers to add (will be added to
92
- * the ones given with {@link OAuthBffClient.addHeader} )
93
94
  * @returns the access token payload or an empty object if there isn't one
94
95
  */
95
96
  getAccessToken(csrfToken?: string): Promise<{
@@ -99,7 +100,7 @@ export declare class OAuthBffClient {
99
100
  * Returns whether or not there is an access token stored in the BFF server
100
101
  * for this client.
101
102
  *
102
- * @param crfToken the CSRF token. If emtpy, one will be fetched before
103
+ * @param csrfToken the CSRF token. If emtpy, one will be fetched before
103
104
  * making the request
104
105
  * @returns true or false
105
106
  */
@@ -110,7 +111,7 @@ export declare class OAuthBffClient {
110
111
  * This only returns something if the refresh token was returned to the BFF
111
112
  * client in a previous OAuth call. Otherwise it returns an empty JSON.
112
113
  *
113
- * @param crfToken the CSRF token. If emtpy, one will be fetched before
114
+ * @param csrfToken the CSRF token. If emtpy, one will be fetched before
114
115
  * making the request
115
116
  * @returns the refresh token payload or an empty object if there isn't one
116
117
  */
@@ -121,7 +122,7 @@ export declare class OAuthBffClient {
121
122
  * Returns whether or not there is a refresh token stored in the BFF server
122
123
  * for this client.
123
124
  *
124
- * @param crfToken the CSRF token. If emtpy, one will be fetched before
125
+ * @param csrfToken the CSRF token. If emtpy, one will be fetched before
125
126
  * making the request
126
127
  * @returns true or false
127
128
  */
@@ -169,8 +170,8 @@ export declare class OAuthBffClient {
169
170
  stopAutoRefresh(): void;
170
171
  /**
171
172
  * Turns polling for a device code
172
- * @param tokensToFetch which tokens to fetch
173
- * @param errorFn what to call in case of error
173
+ * @param deviceCode the device code to poll for (returned when the device code flow was started)
174
+ * @param pollResultFn THis function will be called with the result of each poll
174
175
  */
175
176
  startDeviceCodePolling(deviceCode: string, pollResultFn: (status: ("complete" | "completeAndRedirect" | "authorization_pending" | "expired_token" | "error"), error?: string, location?: string) => void, interval?: number): Promise<void>;
176
177
  /**
@@ -179,7 +180,7 @@ export declare class OAuthBffClient {
179
180
  stopDeviceCodePolling(): void;
180
181
  /**
181
182
  * Fetches the expiry times for each token.
182
- * @param crfToken the CSRF token. If emtpy
183
+ * @param csrfToken the CSRF token. If emtpy
183
184
  * , one will be fetched before
184
185
  * making the request
185
186
  * @returns for each token, either the expiry, `null` if it does not
@@ -194,7 +195,7 @@ export declare class OAuthBffClient {
194
195
  * Makes a fetch, adding in the requested token
195
196
  * @param url the URL to fetch
196
197
  * @param params parameters to add to the fetch
197
- * @param token which token to add
198
+ * @param _token unused
198
199
  * @returns parsed JSON response
199
200
  */
200
201
  jsonFetchWithToken(url: string, params: {
@@ -68,7 +68,7 @@ export declare class OAuthClient extends OAuthClientBase {
68
68
  * - `deviceAuthorization` URL, relative to the authorization server base,
69
69
  * for starting the device code flow. Default `device_authorization`
70
70
  * Default is `/devicecodepoll`
71
- * For other options see {@link @crossauth/common/OAuthClientBase}.
71
+ * For other options see {@link OAuthClientBase}.
72
72
  */
73
73
  constructor(options: {
74
74
  authServerBaseUrl: string;
@@ -111,14 +111,9 @@ export declare class OAuthClient extends OAuthClientBase {
111
111
  * endpoint is called. Depending on whether that returned an error,
112
112
  * either `receiveTokenFn` or `errorFn` will be called.
113
113
  *
114
- * @param receiveTokenFn if defined, called if a token is returned.
115
- *
116
- * @param errorFn if defined, called if any OAuth endpoint returned `error`,
117
- * or if the `state` was not correct.
118
- *
119
- * @returns the result of `receiveTokenFn`, `errorFn` or `undefined`. If
120
- * `receiveTokenFn`/`errorFn` is not defined, rather than calling
121
- * it, this function just returns the OAuth response.
114
+ * @returns the result of `receiveTokenFn` or undefined if there was
115
+ * neither a code in the URL search params nor an error `undefined`. If
116
+ * @throws CrossauthError if an `error` was passed in the URL search params
122
117
  *
123
118
  */
124
119
  handleRedirectUri(): Promise<any | undefined>;
@@ -134,8 +129,8 @@ export declare class OAuthClient extends OAuthClientBase {
134
129
  stopAutoRefresh(): void;
135
130
  /**
136
131
  * Turns polling for a device code
137
- * @param tokensToFetch which tokens to fetch
138
- * @param errorFn what to call in case of error
132
+ * @param deviceCode the device code to poll for (this was returned when the device code flow was started)
133
+ * @param pollResultFn called with the result of each poll
139
134
  */
140
135
  startDeviceCodePolling(deviceCode: string, pollResultFn: (status: ("complete" | "completeAndRedirect" | "authorization_pending" | "expired_token" | "error"), error?: string, location?: string) => void, interval?: number): Promise<void>;
141
136
  /**
@@ -183,9 +178,8 @@ export declare class OAuthClient extends OAuthClientBase {
183
178
  }>;
184
179
  /**
185
180
  * Fetches the expiry times for each token.
186
- * @param crfToken the CSRF token. If emtpy
187
- * , one will be fetched before
188
- * making the request
181
+ * @param _tokensToFetch unused
182
+ * @param _csrfToken unused
189
183
  * @returns for each token, either the expiry, `null` if it does not
190
184
  * expire, or `undefined` if the token does not exist
191
185
  */
@@ -218,27 +212,29 @@ export declare class OAuthClient extends OAuthClientBase {
218
212
  refresh_token?: string | null;
219
213
  }): Promise<void>;
220
214
  /**
221
- * See {@link @crossuath/common!OAuthClientBase}. Calls the base function
215
+ * See {@link OAuthClientBase}. Calls the base function
222
216
  * then saves the tokens, as per the requested method
223
217
  * @param scope
224
218
  */
225
219
  clientCredentialsFlow(scope?: string): Promise<OAuthTokenResponse>;
226
220
  /**
227
- * See {@link @crossuath/common!OAuthClientBase}. Calls the base function
221
+ * See {@link OAuthClientBase}. Calls the base function
228
222
  * then saves the tokens, as per the requested method
229
223
  * @param scope
230
224
  */
231
225
  passwordFlow(username: string, password: string, scope?: string): Promise<OAuthTokenResponse>;
232
226
  /**
233
- * See {@link @crossuath/common!OAuthClientBase}. Calls the base function
227
+ * See {@link OAuthClientBase}. Calls the base function
234
228
  * then saves the tokens, as per the requested method
235
229
  * @param scope
236
230
  */
237
231
  deviceCodeFlow(scope?: string): Promise<OAuthDeviceAuthorizationResponse>;
238
232
  /**
239
- * See {@link @crossuath/common!OAuthClientBase}. Calls the base function
233
+ * See {@link OAuthClientBase}. Calls the base function
240
234
  * then saves the tokens, as per the requested method
241
- * @param scope
235
+ * @param mfaToken the MFA token returned when the flow was started
236
+ * @param otp the One time password entered by the user
237
+ * @return the response from the MFA OTP OAuth call
242
238
  */
243
239
  mfaOtpComplete(mfaToken: string, otp: string): Promise<{
244
240
  access_token?: string;
@@ -251,15 +247,18 @@ export declare class OAuthClient extends OAuthClientBase {
251
247
  error_description?: string;
252
248
  }>;
253
249
  /**
254
- * See {@link @crossuath/common!OAuthClientBase}. Calls the base function
250
+ * See {@link OAuthClientBase}. Calls the base function
255
251
  * then saves the tokens, as per the requested method
256
- * @param scope
252
+ * @param mfaToken the MFA token returned when the flow was started
253
+ * @param oobCode the code entered by the user
254
+ * @return the response from the MFA OOB OAuth call
257
255
  */
258
256
  mfaOobComplete(mfaToken: string, oobCode: string, bindingCode: string): Promise<OAuthTokenResponse>;
259
257
  /**
260
- * See {@link @crossuath/common!OAuthClientBase}. Calls the base function
258
+ * See {@link OAuthClientBase}. Calls the base function
261
259
  * then saves the tokens, as per the requested method
262
- * @param scope
260
+ * @param refreshToken the refresh token. Do not pass this if you have
261
+ * it stored in this object already
263
262
  */
264
263
  refreshTokenFlow(refreshToken?: string): Promise<OAuthTokenResponse>;
265
264
  /**
@@ -1,7 +1,7 @@
1
1
  import { OAuthClientBase } from '@crossauth/common';
2
2
 
3
3
  /**
4
- * Used by {@link OAuthClient} and {@link OAuthBsffClient} to poll for
4
+ * Used by {@link OAuthClient} and {@link OAuthBffClient} to poll for
5
5
  * authorization in the device code flow
6
6
  */
7
7
  export declare class OAuthDeviceCodePoller {
@@ -10,7 +10,7 @@ export declare abstract class OAuthTokenProvider {
10
10
  getCsrfToken(): Promise<string | undefined>;
11
11
  /**
12
12
  * Fetches the expiry times for each token.
13
- * @param crfToken the CSRF token. If emtpy
13
+ * @param csrfToken the CSRF token. If emtpy
14
14
  * , one will be fetched before
15
15
  * making the request
16
16
  * @returns for each token, either the expiry, `null` if it does not
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@crossauth/frontend",
3
3
  "private": false,
4
- "version": "0.0.14",
4
+ "version": "0.0.15",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@esbuild-plugins/node-modules-polyfill": "^0.2.2",
25
- "@crossauth/common": "^0.0.14"
25
+ "@crossauth/common": "^0.0.15"
26
26
  },
27
27
  "scripts": {
28
28
  "dev": "vite",