UNPKG

7.22 kBTypeScriptView Raw
1import { AuthDependencies, AuthLoginOptions, AuthLoginResult, AuthModuleId, AuthOptions, AuthTypeDependencies, BasicLoginCredentials, CombinedTokenContextDependencies, IAuth, IAuthType, IBasicAuthType, IClient, ICombinedTokenContext, ICombinedTokenContextStoreOptions, IConfig, ITokenContext, InAppBrowserPluginOptions, TokenContextDependencies, UserDetails } from './definitions';
2import { DetailedError } from './errors';
3/**
4 * @hidden
5 */
6export declare class AuthTokenContext implements ITokenContext {
7 label: string;
8 /**
9 * @private
10 */
11 private storage;
12 constructor(deps: TokenContextDependencies, label: string);
13 get(): string;
14 store(token: string): void;
15 delete(): void;
16}
17/**
18 * @hidden
19 */
20export declare class CombinedAuthTokenContext implements ICombinedTokenContext {
21 label: string;
22 /**
23 * @private
24 */
25 private storage;
26 /**
27 * @private
28 */
29 private tempStorage;
30 constructor(deps: CombinedTokenContextDependencies, label: string);
31 get(): string;
32 store(token: string, options?: ICombinedTokenContextStoreOptions): void;
33 delete(): void;
34}
35/**
36 * `Auth` handles authentication of a single user, such as signing up, logging
37 * in & out, social provider authentication, etc.
38 *
39 * @featured
40 */
41export declare class Auth implements IAuth {
42 /**
43 * @hidden
44 */
45 options: AuthOptions;
46 /**
47 * @private
48 */
49 private config;
50 /**
51 * @private
52 */
53 private emitter;
54 /**
55 * @private
56 */
57 private authModules;
58 /**
59 * @private
60 */
61 private tokenContext;
62 /**
63 * @private
64 */
65 private userService;
66 /**
67 * @private
68 */
69 private storage;
70 /**
71 * @private
72 */
73 private authToken;
74 constructor(deps: AuthDependencies,
75 /**
76 * @hidden
77 */
78 options?: AuthOptions);
79 /**
80 * Link the user to this URL for password resets. Only for email/password
81 * authentication.
82 *
83 * Use this if you want to use our password reset forms instead of creating
84 * your own in your app.
85 */
86 passwordResetUrl: string;
87 /**
88 * Check whether the user is logged in or not.
89 *
90 * If an auth token exists in local storage, the user is logged in.
91 */
92 isAuthenticated(): boolean;
93 /**
94 * Sign up a user with the given data. Only for email/password
95 * authentication.
96 *
97 * `signup` does not affect local data or the current user until `login` is
98 * called. This means you'll likely want to log in your users manually after
99 * signup.
100 *
101 * If a signup fails, the promise rejects with a [`IDetailedError`
102 * object](/api/client/idetailederror) that contains an array of error codes
103 * from the cloud.
104 *
105 * @param details - The details that describe a user.
106 */
107 signup(details: UserDetails): Promise<void>;
108 /**
109 * Attempt to log the user in with the given credentials. For custom & social
110 * logins, kick-off the authentication process.
111 *
112 * After login, the full user is loaded from the cloud and saved in local
113 * storage along with their auth token.
114 *
115 * @note TODO: Better error handling docs.
116 *
117 * @param moduleId
118 * The authentication provider module ID to use with this login.
119 * @param credentials
120 * For email/password authentication, give an email and password. For social
121 * authentication, exclude this parameter. For custom authentication, send
122 * whatever you need.
123 * @param options
124 * Options for this login, such as whether to remember the login and
125 * InAppBrowser window options for authentication providers that make use of
126 * it.
127 */
128 login(moduleId: AuthModuleId, credentials?: Object, options?: AuthLoginOptions): Promise<AuthLoginResult>;
129 /**
130 * Log the user out of the app.
131 *
132 * This clears the auth token out of local storage and restores the user to
133 * an unauthenticated state.
134 */
135 logout(): void;
136 /**
137 * Kick-off the password reset process. Only for email/password
138 * authentication.
139 *
140 * An email will be sent to the user with a short password reset code, which
141 * they can copy back into your app and use the [`confirmPasswordReset()`
142 * method](#confirmPasswordReset).
143 *
144 * @param email - The email address to which to send a code.
145 */
146 requestPasswordReset(email: string): Promise<void>;
147 /**
148 * Confirm a password reset.
149 *
150 * When the user gives you their password reset code into your app and their
151 * requested changed password, call this method.
152 *
153 * @param code - The password reset code from the user.
154 * @param newPassword - The requested changed password from the user.
155 */
156 confirmPasswordReset(code: number, newPassword: string): Promise<void>;
157 /**
158 * Get the raw auth token of the active user from local storage.
159 */
160 getToken(): string;
161 /**
162 * @hidden
163 */
164 storeToken(options: AuthLoginOptions, token: string): void;
165 /**
166 * @hidden
167 */
168 static getDetailedErrorFromResponse(res: any): DetailedError<string[]>;
169}
170/**
171 * @hidden
172 */
173export declare abstract class AuthType implements IAuthType {
174 protected config: IConfig;
175 protected client: IClient;
176 constructor(deps: AuthTypeDependencies);
177 abstract authenticate(data?: Object, options?: AuthLoginOptions): Promise<AuthLoginResult>;
178 protected parseInAppBrowserOptions(opts?: InAppBrowserPluginOptions): string;
179 protected inAppBrowserFlow(moduleId: AuthModuleId, data?: Object, options?: AuthLoginOptions): Promise<AuthLoginResult>;
180}
181/**
182 * @hidden
183 */
184export declare class BasicAuth extends AuthType implements IBasicAuthType {
185 authenticate(data: BasicLoginCredentials, options?: AuthLoginOptions): Promise<AuthLoginResult>;
186 requestPasswordReset(email: string): Promise<void>;
187 confirmPasswordReset(email: string, code: number, newPassword: string): Promise<void>;
188 signup(data: UserDetails): Promise<void>;
189}
190/**
191 * @hidden
192 */
193export declare class CustomAuth extends AuthType {
194 authenticate(data?: Object, options?: AuthLoginOptions): Promise<AuthLoginResult>;
195}
196/**
197 * @hidden
198 */
199export declare class TwitterAuth extends AuthType {
200 authenticate(data?: Object, options?: AuthLoginOptions): Promise<AuthLoginResult>;
201}
202/**
203 * @hidden
204 */
205export declare class FacebookAuth extends AuthType {
206 authenticate(data?: Object, options?: AuthLoginOptions): Promise<AuthLoginResult>;
207}
208/**
209 * @hidden
210 */
211export declare class GithubAuth extends AuthType {
212 authenticate(data?: Object, options?: AuthLoginOptions): Promise<AuthLoginResult>;
213}
214/**
215 * @hidden
216 */
217export declare class GoogleAuth extends AuthType {
218 authenticate(data?: Object, options?: AuthLoginOptions): Promise<AuthLoginResult>;
219}
220/**
221 * @hidden
222 */
223export declare class InstagramAuth extends AuthType {
224 authenticate(data?: Object, options?: AuthLoginOptions): Promise<AuthLoginResult>;
225}
226/**
227 * @hidden
228 */
229export declare class LinkedInAuth extends AuthType {
230 authenticate(data?: Object, options?: AuthLoginOptions): Promise<AuthLoginResult>;
231}