@faable/auth-js 1.3.0 → 1.3.2
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/dts/Base.d.ts +7 -0
- package/dist/dts/BaseLog.d.ts +10 -0
- package/dist/dts/FaableAuthApi.d.ts +13 -0
- package/dist/dts/FaableAuthClient.d.ts +231 -0
- package/dist/dts/entrypoints/faableauth.d.ts +6 -0
- package/dist/dts/lib/constants.d.ts +10 -0
- package/dist/dts/lib/errors.d.ts +82 -0
- package/dist/dts/lib/fetch.d.ts +11 -0
- package/dist/dts/lib/globals.d.ts +4 -0
- package/dist/dts/lib/helpers.d.ts +52 -0
- package/dist/dts/lib/jwt.d.ts +55 -0
- package/dist/dts/lib/local-storage.d.ts +12 -0
- package/dist/dts/lib/storage_helpers.d.ts +4 -0
- package/dist/dts/lib/types.d.ts +383 -0
- package/dist/dts/lib/url_helpers.d.ts +7 -0
- package/dist/dts/lib/version.d.ts +1 -0
- package/dist/dts/lock/Lock.d.ts +19 -0
- package/dist/dts/lock/locks.d.ts +63 -0
- package/dist/dts/utils.d.ts +17 -0
- package/dist/faableauth.js +1 -1
- package/dist/faableauth.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type BaseLogOptions = {
|
|
2
|
+
debug?: boolean | ((message: string, ...args: any[]) => void);
|
|
3
|
+
};
|
|
4
|
+
export declare abstract class BaseLog {
|
|
5
|
+
protected logDebugMessages: boolean;
|
|
6
|
+
protected logger: (message: string, ...args: any[]) => void;
|
|
7
|
+
constructor(config?: BaseLogOptions);
|
|
8
|
+
protected extraPrint?(): string;
|
|
9
|
+
protected _debug(...args: any[]): this;
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseLog, BaseLogOptions } from "./BaseLog";
|
|
2
|
+
import { AuthError } from "./lib/errors";
|
|
3
|
+
export default class FaableAuthApi extends BaseLog {
|
|
4
|
+
base_url: string;
|
|
5
|
+
constructor(base_url: string, config: BaseLogOptions);
|
|
6
|
+
protected extraPrint(): string;
|
|
7
|
+
signOut(params: {
|
|
8
|
+
client_id: string;
|
|
9
|
+
}): Promise<{
|
|
10
|
+
data: null;
|
|
11
|
+
error: AuthError | null;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { AuthFlowType, SupportedStorage, SignInWithOAuthConnection, OAuthResponse, Subscription, InitializeResult, CallRefreshTokenResult } from "./lib/types";
|
|
2
|
+
import { FaableAuthClientConfig, AuthResponse, AuthChangeEvent } from "./lib/types";
|
|
3
|
+
import { Session, SignOut } from "./lib/types";
|
|
4
|
+
import { Deferred } from "./lib/helpers";
|
|
5
|
+
import { AuthError } from "./lib/errors";
|
|
6
|
+
import FaableAuthApi from "./FaableAuthApi";
|
|
7
|
+
import { Base } from "./Base";
|
|
8
|
+
import { Lock } from "./lock/Lock";
|
|
9
|
+
export declare class FaableAuthClient extends Base {
|
|
10
|
+
domainUrl: string;
|
|
11
|
+
tokenIssuer: string;
|
|
12
|
+
redirect_uri: string;
|
|
13
|
+
scope?: string;
|
|
14
|
+
sessionCheckExpiryDays: number;
|
|
15
|
+
protected initializePromise: Promise<InitializeResult> | null;
|
|
16
|
+
protected detectSessionInUrl: boolean;
|
|
17
|
+
protected storageKey: string;
|
|
18
|
+
protected clientId: string;
|
|
19
|
+
protected flowType: AuthFlowType;
|
|
20
|
+
protected storage: SupportedStorage;
|
|
21
|
+
protected api: FaableAuthApi;
|
|
22
|
+
protected autoRefreshToken: boolean;
|
|
23
|
+
protected autoRefreshTicker: ReturnType<typeof setInterval> | null;
|
|
24
|
+
protected visibilityChangedCallback: (() => Promise<any>) | null;
|
|
25
|
+
protected refreshingDeferred: Deferred<CallRefreshTokenResult> | null;
|
|
26
|
+
/**
|
|
27
|
+
* Used to broadcast state change events to other tabs listening.
|
|
28
|
+
*/
|
|
29
|
+
protected broadcastChannel: BroadcastChannel | null;
|
|
30
|
+
protected stateChangeEmitters: Map<string, Subscription>;
|
|
31
|
+
protected lock: Lock;
|
|
32
|
+
constructor(config: FaableAuthClientConfig);
|
|
33
|
+
/**
|
|
34
|
+
* Initializes the client session either from the url or from storage.
|
|
35
|
+
* This method is automatically called when instantiating the client, but should also be called
|
|
36
|
+
* manually when checking for an error from an auth redirect (oauth, magiclink, password recovery, etc).
|
|
37
|
+
*/
|
|
38
|
+
initialize(): Promise<InitializeResult>;
|
|
39
|
+
/**
|
|
40
|
+
* IMPORTANT:
|
|
41
|
+
* 1. Never throw in this method, as it is called from the constructor
|
|
42
|
+
* 2. Never return a session from this method as it would be cached over
|
|
43
|
+
* the whole lifetime of the client
|
|
44
|
+
*/
|
|
45
|
+
private _initialize;
|
|
46
|
+
/**
|
|
47
|
+
* Gets the session data from a URL string
|
|
48
|
+
*/
|
|
49
|
+
private _getSessionFromURL;
|
|
50
|
+
private _exchangeCodeForSession;
|
|
51
|
+
/**
|
|
52
|
+
* Registers callbacks on the browser / platform, which in-turn run
|
|
53
|
+
* algorithms when the browser window/tab are in foreground. On non-browser
|
|
54
|
+
* platforms it assumes always foreground.
|
|
55
|
+
*/
|
|
56
|
+
private _handleVisibilityChange;
|
|
57
|
+
/**
|
|
58
|
+
* Callback registered with `window.addEventListener('visibilitychange')`.
|
|
59
|
+
*/
|
|
60
|
+
private _onVisibilityChanged;
|
|
61
|
+
/**
|
|
62
|
+
* Recovers the session from LocalStorage and refreshes
|
|
63
|
+
* Note: this method is async to accommodate for AsyncStorage e.g. in React native.
|
|
64
|
+
*/
|
|
65
|
+
private _recoverAndRefresh;
|
|
66
|
+
/**
|
|
67
|
+
* Removes any registered visibilitychange callback.
|
|
68
|
+
*
|
|
69
|
+
* {@see #startAutoRefresh}
|
|
70
|
+
* {@see #stopAutoRefresh}
|
|
71
|
+
*/
|
|
72
|
+
private _removeVisibilityChangedCallback;
|
|
73
|
+
/**
|
|
74
|
+
* Starts an auto-refresh process in the background. The session is checked
|
|
75
|
+
* every few seconds. Close to the time of expiration a process is started to
|
|
76
|
+
* refresh the session. If refreshing fails it will be retried for as long as
|
|
77
|
+
* necessary.
|
|
78
|
+
*
|
|
79
|
+
* If you set the {@link GoTrueClientOptions#autoRefreshToken} you don't need
|
|
80
|
+
* to call this function, it will be called for you.
|
|
81
|
+
*
|
|
82
|
+
* On browsers the refresh process works only when the tab/window is in the
|
|
83
|
+
* foreground to conserve resources as well as prevent race conditions and
|
|
84
|
+
* flooding auth with requests. If you call this method any managed
|
|
85
|
+
* visibility change callback will be removed and you must manage visibility
|
|
86
|
+
* changes on your own.
|
|
87
|
+
*
|
|
88
|
+
* On non-browser platforms the refresh process works *continuously* in the
|
|
89
|
+
* background, which may not be desirable. You should hook into your
|
|
90
|
+
* platform's foreground indication mechanism and call these methods
|
|
91
|
+
* appropriately to conserve resources.
|
|
92
|
+
*
|
|
93
|
+
* {@see #stopAutoRefresh}
|
|
94
|
+
*/
|
|
95
|
+
startAutoRefresh(): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* This is the private implementation of {@link #startAutoRefresh}. Use this
|
|
98
|
+
* within the library.
|
|
99
|
+
*/
|
|
100
|
+
private _startAutoRefresh;
|
|
101
|
+
/**
|
|
102
|
+
* This is the private implementation of {@link #stopAutoRefresh}. Use this
|
|
103
|
+
* within the library.
|
|
104
|
+
*/
|
|
105
|
+
private _stopAutoRefresh;
|
|
106
|
+
/**
|
|
107
|
+
* Runs the auto refresh token tick.
|
|
108
|
+
*/
|
|
109
|
+
private _autoRefreshTokenTick;
|
|
110
|
+
/**
|
|
111
|
+
* Checks if the current URL and backing storage contain parameters given by a PKCE flow
|
|
112
|
+
*/
|
|
113
|
+
private _isPKCEFlow;
|
|
114
|
+
/**
|
|
115
|
+
* Checks if the current URL contains parameters given by an implicit oauth grant flow (https://www.rfc-editor.org/rfc/rfc6749.html#section-4.2)
|
|
116
|
+
*/
|
|
117
|
+
private _isImplicitGrantFlow;
|
|
118
|
+
private _scope;
|
|
119
|
+
private _getUrlForConnection;
|
|
120
|
+
signInWithOauthConnection(credentials: SignInWithOAuthConnection): Promise<OAuthResponse>;
|
|
121
|
+
signInWithUsernamePassword(data: {
|
|
122
|
+
username: string;
|
|
123
|
+
password: string;
|
|
124
|
+
redirect_uri?: string;
|
|
125
|
+
}): Promise<void>;
|
|
126
|
+
private _handleConnectionSignIn;
|
|
127
|
+
/**
|
|
128
|
+
* Sets the session data from the current session. If the current session is expired, setSession will take care of refreshing it to obtain a new session.
|
|
129
|
+
* If the refresh token or access token in the current session is invalid, an error will be thrown.
|
|
130
|
+
* @param currentSession The current session that minimally contains an access token and refresh token.
|
|
131
|
+
*/
|
|
132
|
+
setSession(currentSession: {
|
|
133
|
+
access_token: string;
|
|
134
|
+
refresh_token: string;
|
|
135
|
+
}): Promise<AuthResponse>;
|
|
136
|
+
/**
|
|
137
|
+
* Returns the session, refreshing it if necessary.
|
|
138
|
+
*
|
|
139
|
+
* The session returned can be null if the session is not detected which can happen in the event a user is not signed-in or has logged out.
|
|
140
|
+
*
|
|
141
|
+
* **IMPORTANT:** This method loads values directly from the storage attached
|
|
142
|
+
* to the client. If that storage is based on request cookies for example,
|
|
143
|
+
* the values in it may not be authentic and therefore it's strongly advised
|
|
144
|
+
* against using this method and its results in such circumstances. A warning
|
|
145
|
+
* will be emitted if this is detected. Use {@link #getUser()} instead.
|
|
146
|
+
*/
|
|
147
|
+
getSession(): Promise<{
|
|
148
|
+
data: {
|
|
149
|
+
session: Session;
|
|
150
|
+
};
|
|
151
|
+
error: null;
|
|
152
|
+
} | {
|
|
153
|
+
data: {
|
|
154
|
+
session: null;
|
|
155
|
+
};
|
|
156
|
+
error: AuthError;
|
|
157
|
+
} | {
|
|
158
|
+
data: {
|
|
159
|
+
session: null;
|
|
160
|
+
};
|
|
161
|
+
error: null;
|
|
162
|
+
}>;
|
|
163
|
+
/**
|
|
164
|
+
* Use instead of {@link #getSession} inside the library. It is
|
|
165
|
+
* semantically usually what you want, as getting a session involves some
|
|
166
|
+
* processing afterwards that requires only one client operating on the
|
|
167
|
+
* session at once across multiple tabs or processes.
|
|
168
|
+
*/
|
|
169
|
+
private _useSession;
|
|
170
|
+
/**
|
|
171
|
+
* NEVER USE DIRECTLY!
|
|
172
|
+
*
|
|
173
|
+
* Always use {@link #_useSession}.
|
|
174
|
+
*/
|
|
175
|
+
private __loadSession;
|
|
176
|
+
private _removeSession;
|
|
177
|
+
private _isValidSession;
|
|
178
|
+
protected _setSession(currentSession: {
|
|
179
|
+
access_token: string;
|
|
180
|
+
refresh_token: string;
|
|
181
|
+
}): Promise<AuthResponse>;
|
|
182
|
+
/**
|
|
183
|
+
* set currentSession and currentUser
|
|
184
|
+
* process to _startAutoRefreshToken if possible
|
|
185
|
+
*/
|
|
186
|
+
private _saveSession;
|
|
187
|
+
private _getUser;
|
|
188
|
+
private _callRefreshToken;
|
|
189
|
+
/**
|
|
190
|
+
* Generates a new JWT.
|
|
191
|
+
* @param refreshToken A valid refresh token that was returned on login.
|
|
192
|
+
*/
|
|
193
|
+
private _refreshAccessToken;
|
|
194
|
+
private _notifyAllSubscribers;
|
|
195
|
+
/**
|
|
196
|
+
* Inside a browser context, `signOut()` will remove the logged in user from the browser session and log them out - removing all items from localstorage and then trigger a `"SIGNED_OUT"` event.
|
|
197
|
+
*
|
|
198
|
+
* For server-side management, you can revoke all refresh tokens for a user by passing a user's JWT through to `auth.api.signOut(JWT: string)`.
|
|
199
|
+
* There is no way to revoke a user's access token jwt until it expires. It is recommended to set a shorter expiry on the jwt for this reason.
|
|
200
|
+
*
|
|
201
|
+
* If using `others` scope, no `SIGNED_OUT` event is fired!
|
|
202
|
+
*/
|
|
203
|
+
signOut(options?: SignOut): Promise<{
|
|
204
|
+
error: AuthError | null;
|
|
205
|
+
}>;
|
|
206
|
+
protected _signOut({ scope }?: SignOut): Promise<{
|
|
207
|
+
error: AuthError | null;
|
|
208
|
+
}>;
|
|
209
|
+
/**
|
|
210
|
+
* Receive a notification every time an auth event happens.
|
|
211
|
+
* @param callback A callback function to be invoked when an auth event happens.
|
|
212
|
+
*/
|
|
213
|
+
onAuthStateChange(callback: (event: AuthChangeEvent, session: Session | null) => void | Promise<void>): {
|
|
214
|
+
data: {
|
|
215
|
+
subscription: Subscription;
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
private _emitInitialSession;
|
|
219
|
+
/**
|
|
220
|
+
* Returns a new session, regardless of expiry status.
|
|
221
|
+
* Takes in an optional current session. If not passed in, then refreshSession() will attempt to retrieve it from getSession().
|
|
222
|
+
* If the current session's refresh token is invalid, an error will be thrown.
|
|
223
|
+
* @param currentSession The current session. If passed in, it must contain a refresh token.
|
|
224
|
+
*/
|
|
225
|
+
refreshSession(currentSession?: {
|
|
226
|
+
refresh_token: string;
|
|
227
|
+
}): Promise<AuthResponse>;
|
|
228
|
+
protected _refreshSession(currentSession?: {
|
|
229
|
+
refresh_token: string;
|
|
230
|
+
}): Promise<AuthResponse>;
|
|
231
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FaableAuthClient } from "../FaableAuthClient";
|
|
2
|
+
import { FaableAuthClientConfig } from "../lib/types";
|
|
3
|
+
import { Session, User } from "../lib/types";
|
|
4
|
+
import { AuthError } from "../lib/errors";
|
|
5
|
+
export declare const createClient: (config: FaableAuthClientConfig) => FaableAuthClient;
|
|
6
|
+
export { Session, User, FaableAuthClient, AuthError };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const GOTRUE_URL = "http://localhost:9999";
|
|
2
|
+
export declare const STORAGE_KEY = "faable.auth.token";
|
|
3
|
+
export declare const EXPIRY_MARGIN = 10;
|
|
4
|
+
export declare const API_VERSION_HEADER_NAME = "X-Faableauth-Api-Version";
|
|
5
|
+
export declare const API_VERSIONS: {
|
|
6
|
+
"2024-01-01": {
|
|
7
|
+
timestamp: number;
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Known error codes. Note that the server may also return other error codes
|
|
3
|
+
* not included in this list (if the client library is older than the version
|
|
4
|
+
* on the server).
|
|
5
|
+
*/
|
|
6
|
+
export type ErrorCode = "unexpected_failure" | "validation_failed" | "bad_json" | "email_exists" | "phone_exists" | "bad_jwt" | "not_admin" | "no_authorization" | "user_not_found" | "session_not_found" | "flow_state_not_found" | "flow_state_expired" | "signup_disabled" | "user_banned" | "provider_email_needs_verification" | "invite_not_found" | "bad_oauth_state" | "bad_oauth_callback" | "oauth_provider_not_supported" | "unexpected_audience" | "single_identity_not_deletable" | "email_conflict_identity_not_deletable" | "identity_already_exists" | "email_provider_disabled" | "phone_provider_disabled" | "too_many_enrolled_mfa_factors" | "mfa_factor_name_conflict" | "mfa_factor_not_found" | "mfa_ip_address_mismatch" | "mfa_challenge_expired" | "mfa_verification_failed" | "mfa_verification_rejected" | "insufficient_aal" | "captcha_failed" | "saml_provider_disabled" | "manual_linking_disabled" | "sms_send_failed" | "email_not_confirmed" | "phone_not_confirmed" | "reauth_nonce_missing" | "saml_relay_state_not_found" | "saml_relay_state_expired" | "saml_idp_not_found" | "saml_assertion_no_user_id" | "saml_assertion_no_email" | "user_already_exists" | "sso_provider_not_found" | "saml_metadata_fetch_failed" | "saml_idp_already_exists" | "sso_domain_already_exists" | "saml_entity_id_mismatch" | "conflict" | "provider_disabled" | "user_sso_managed" | "reauthentication_needed" | "same_password" | "reauthentication_not_valid" | "otp_expired" | "otp_disabled" | "identity_not_found" | "weak_password" | "over_request_rate_limit" | "over_email_send_rate_limit" | "over_sms_send_rate_limit" | "bad_code_verifier";
|
|
7
|
+
export declare class AuthError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Error code associated with the error. Most errors coming from
|
|
10
|
+
* HTTP responses will have a code, though some errors that occur
|
|
11
|
+
* before a response is received will not have one present. In that
|
|
12
|
+
* case {@link #status} will also be undefined.
|
|
13
|
+
*/
|
|
14
|
+
code: ErrorCode | string | undefined;
|
|
15
|
+
/** HTTP status code that caused the error. */
|
|
16
|
+
status: number | undefined;
|
|
17
|
+
protected __isAuthError: boolean;
|
|
18
|
+
constructor(message: string, status?: number, code?: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class CustomAuthError extends AuthError {
|
|
21
|
+
name: string;
|
|
22
|
+
status: number;
|
|
23
|
+
constructor(message: string, name: string, status: number, code: string | undefined);
|
|
24
|
+
}
|
|
25
|
+
export declare class AuthSessionMissingError extends CustomAuthError {
|
|
26
|
+
constructor();
|
|
27
|
+
}
|
|
28
|
+
export declare function isAuthError(error: unknown): error is AuthError;
|
|
29
|
+
export declare class AuthApiError extends AuthError {
|
|
30
|
+
status: number;
|
|
31
|
+
constructor(message: string, status: number, code: string | undefined);
|
|
32
|
+
}
|
|
33
|
+
export declare function isAuthApiError(error: unknown): error is AuthApiError;
|
|
34
|
+
export declare class AuthImplicitGrantRedirectError extends CustomAuthError {
|
|
35
|
+
details: {
|
|
36
|
+
error: string;
|
|
37
|
+
code: string;
|
|
38
|
+
} | null;
|
|
39
|
+
constructor(message: string, details?: {
|
|
40
|
+
error: string;
|
|
41
|
+
code: string;
|
|
42
|
+
} | null);
|
|
43
|
+
toJSON(): {
|
|
44
|
+
name: string;
|
|
45
|
+
message: string;
|
|
46
|
+
status: number;
|
|
47
|
+
details: {
|
|
48
|
+
error: string;
|
|
49
|
+
code: string;
|
|
50
|
+
} | null;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export declare class AuthPKCEGrantCodeExchangeError extends CustomAuthError {
|
|
54
|
+
details: {
|
|
55
|
+
error: string;
|
|
56
|
+
code: string;
|
|
57
|
+
} | null;
|
|
58
|
+
constructor(message: string, details?: {
|
|
59
|
+
error: string;
|
|
60
|
+
code: string;
|
|
61
|
+
} | null);
|
|
62
|
+
toJSON(): {
|
|
63
|
+
name: string;
|
|
64
|
+
message: string;
|
|
65
|
+
status: number;
|
|
66
|
+
details: {
|
|
67
|
+
error: string;
|
|
68
|
+
code: string;
|
|
69
|
+
} | null;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export declare class AuthUnknownError extends AuthError {
|
|
73
|
+
originalError: unknown;
|
|
74
|
+
constructor(message: string, originalError: unknown);
|
|
75
|
+
}
|
|
76
|
+
export declare class AuthInvalidTokenResponseError extends CustomAuthError {
|
|
77
|
+
constructor();
|
|
78
|
+
}
|
|
79
|
+
export declare class AuthRetryableFetchError extends CustomAuthError {
|
|
80
|
+
constructor(message: string, status: number);
|
|
81
|
+
}
|
|
82
|
+
export declare function isAuthRetryableFetchError(error: unknown): error is AuthRetryableFetchError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type JsonResponse<T = any> = {
|
|
2
|
+
data: T | null;
|
|
3
|
+
error?: any;
|
|
4
|
+
};
|
|
5
|
+
type RequestInitWithToken = RequestInit & {
|
|
6
|
+
token: string;
|
|
7
|
+
raw: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const _post: <T>(url: string, data: object, options?: Partial<RequestInitWithToken>) => Promise<JsonResponse<T>>;
|
|
10
|
+
export declare const _get: <T>(url: string, options?: Partial<RequestInitWithToken>) => Promise<JsonResponse<T>>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AuthResponse, SupportedStorage, User } from "./types";
|
|
2
|
+
import { JsonResponse } from "./fetch";
|
|
3
|
+
export declare function decodeBase64URL(value: string): string;
|
|
4
|
+
export declare function generatePKCEVerifier(): string;
|
|
5
|
+
export declare function generatePKCEChallenge(verifier: string): Promise<string>;
|
|
6
|
+
export declare function getCodeChallengeAndMethod(storage: SupportedStorage, storageKey: string, isPasswordRecovery?: boolean): Promise<string[]>;
|
|
7
|
+
export declare const isBrowser: () => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Checks whether localStorage is supported on this browser.
|
|
10
|
+
*/
|
|
11
|
+
export declare const supportsLocalStorage: () => boolean;
|
|
12
|
+
export declare function uuid(): string;
|
|
13
|
+
export type RawAuthResponse = {
|
|
14
|
+
expires_at: number;
|
|
15
|
+
expires_in: number;
|
|
16
|
+
user: User;
|
|
17
|
+
access_token: string;
|
|
18
|
+
refresh_token: string;
|
|
19
|
+
token_type: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function expiresAt(expiresIn: number): number;
|
|
22
|
+
export declare function _sessionResponse({ data, }: JsonResponse<Partial<RawAuthResponse>>): AuthResponse;
|
|
23
|
+
/**
|
|
24
|
+
* A deferred represents some asynchronous work that is not yet finished, which
|
|
25
|
+
* may or may not culminate in a value.
|
|
26
|
+
* Taken from: https://github.com/mike-north/types/blob/master/src/async.ts
|
|
27
|
+
*/
|
|
28
|
+
export declare class Deferred<T = any> {
|
|
29
|
+
static promiseConstructor: PromiseConstructor;
|
|
30
|
+
readonly promise: PromiseLike<T>;
|
|
31
|
+
readonly resolve: (value?: T | PromiseLike<T>) => void;
|
|
32
|
+
readonly reject: (reason?: any) => any;
|
|
33
|
+
constructor();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Converts the provided async function into a retryable function. Each result
|
|
37
|
+
* or thrown error is sent to the isRetryable function which should return true
|
|
38
|
+
* if the function should run again.
|
|
39
|
+
*/
|
|
40
|
+
export declare function retryable<T>(fn: (attempt: number) => Promise<T>, isRetryable: (attempt: number, error: any | null, result?: T) => boolean): Promise<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a promise that resolves to null after some time.
|
|
43
|
+
*/
|
|
44
|
+
export declare function sleep(time: number): Promise<null>;
|
|
45
|
+
export declare const checkExpiresInTime: ({ expires_in, expires_at, refreshTick, }: {
|
|
46
|
+
expires_in: string;
|
|
47
|
+
expires_at?: string;
|
|
48
|
+
refreshTick: number;
|
|
49
|
+
}) => {
|
|
50
|
+
expiresIn: number;
|
|
51
|
+
expiresAt: number;
|
|
52
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ignore
|
|
3
|
+
*/
|
|
4
|
+
export interface JWTVerifyOptions {
|
|
5
|
+
iss: string;
|
|
6
|
+
aud: string;
|
|
7
|
+
id_token: string;
|
|
8
|
+
nonce?: string;
|
|
9
|
+
leeway?: number;
|
|
10
|
+
max_age?: number;
|
|
11
|
+
organizationId?: string;
|
|
12
|
+
now?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface IdToken {
|
|
15
|
+
__raw: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
given_name?: string;
|
|
18
|
+
family_name?: string;
|
|
19
|
+
middle_name?: string;
|
|
20
|
+
nickname?: string;
|
|
21
|
+
preferred_username?: string;
|
|
22
|
+
profile?: string;
|
|
23
|
+
picture?: string;
|
|
24
|
+
website?: string;
|
|
25
|
+
email?: string;
|
|
26
|
+
email_verified?: boolean;
|
|
27
|
+
gender?: string;
|
|
28
|
+
birthdate?: string;
|
|
29
|
+
zoneinfo?: string;
|
|
30
|
+
locale?: string;
|
|
31
|
+
phone_number?: string;
|
|
32
|
+
phone_number_verified?: boolean;
|
|
33
|
+
address?: string;
|
|
34
|
+
updated_at?: string;
|
|
35
|
+
iss?: string;
|
|
36
|
+
aud?: string;
|
|
37
|
+
exp?: number;
|
|
38
|
+
nbf?: number;
|
|
39
|
+
iat?: number;
|
|
40
|
+
jti?: string;
|
|
41
|
+
azp?: string;
|
|
42
|
+
nonce?: string;
|
|
43
|
+
auth_time?: string;
|
|
44
|
+
at_hash?: string;
|
|
45
|
+
c_hash?: string;
|
|
46
|
+
acr?: string;
|
|
47
|
+
amr?: string;
|
|
48
|
+
sub_jwk?: string;
|
|
49
|
+
cnf?: string;
|
|
50
|
+
sid?: string;
|
|
51
|
+
org_id?: string;
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
}
|
|
54
|
+
export declare function decodeJWTPayload(token: string): any;
|
|
55
|
+
export declare const verify: (options: JWTVerifyOptions) => any;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SupportedStorage } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Provides safe access to the globalThis.localStorage property.
|
|
4
|
+
*/
|
|
5
|
+
export declare const localStorageAdapter: SupportedStorage;
|
|
6
|
+
/**
|
|
7
|
+
* Returns a localStorage-like object that stores the key-value pairs in
|
|
8
|
+
* memory.
|
|
9
|
+
*/
|
|
10
|
+
export declare function memoryLocalStorageAdapter(store?: {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
}): SupportedStorage;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SupportedStorage } from "./types";
|
|
2
|
+
export declare const setItemAsync: (storage: SupportedStorage, key: string, data: any) => Promise<void>;
|
|
3
|
+
export declare const getItemAsync: (storage: SupportedStorage, key: string) => Promise<unknown>;
|
|
4
|
+
export declare const removeItemAsync: (storage: SupportedStorage, key: string) => Promise<void>;
|