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