UNPKG

13.2 kBTypeScriptView Raw
1import { AuthOptions, FederatedResponse, SignUpParams, FederatedUser, ConfirmSignUpOptions, SignOutOpts, CurrentUserOpts, GetPreferredMFAOpts, SignInOpts, FederatedSignInOptionsCustom, LegacyProvider, FederatedSignInOptions, ClientMetaData } from './types';
2import { ICredentials } from '@aws-amplify/core';
3import { ISignUpResult, CognitoUser, MFAOption, CognitoUserSession, CognitoUserAttribute, NodeCallback } from 'amazon-cognito-identity-js';
4import { AuthError } from './Errors';
5import { IAuthDevice } from './types/Auth';
6/**
7 * Provide authentication steps
8 */
9export declare class AuthClass {
10 private _config;
11 private userPool;
12 private user;
13 private _oAuthHandler;
14 private _storage;
15 private _storageSync;
16 private oAuthFlowInProgress;
17 private pendingSignIn;
18 private autoSignInInitiated;
19 private inflightSessionPromise;
20 private inflightSessionPromiseCounter;
21 Credentials: import("@aws-amplify/core").CredentialsClass;
22 /**
23 * Initialize Auth with AWS configurations
24 * @param {Object} config - Configuration of the Auth
25 */
26 constructor(config: AuthOptions);
27 getModuleName(): string;
28 configure(config?: any): AuthOptions;
29 wrapRefreshSessionCallback: (callback: NodeCallback<Error, any>) => NodeCallback<Error, any>;
30 /**
31 * Sign up with username, password and other attributes like phone, email
32 * @param {String | object} params - The user attributes used for signin
33 * @param {String[]} restOfAttrs - for the backward compatability
34 * @return - A promise resolves callback data if success
35 */
36 signUp(params: string | SignUpParams, ...restOfAttrs: string[]): Promise<ISignUpResult>;
37 private handleAutoSignIn;
38 private handleCodeAutoSignIn;
39 private handleLinkAutoSignIn;
40 private signInAfterUserConfirmed;
41 /**
42 * Send the verification code to confirm sign up
43 * @param {String} username - The username to be confirmed
44 * @param {String} code - The verification code
45 * @param {ConfirmSignUpOptions} options - other options for confirm signup
46 * @return - A promise resolves callback data if success
47 */
48 confirmSignUp(username: string, code: string, options?: ConfirmSignUpOptions): Promise<any>;
49 private isTrueStorageValue;
50 /**
51 * Resend the verification code
52 * @param {String} username - The username to be confirmed
53 * @param {ClientMetadata} clientMetadata - Metadata to be passed to Cognito Lambda triggers
54 * @return - A promise resolves code delivery details if successful
55 */
56 resendSignUp(username: string, clientMetadata?: ClientMetaData): Promise<any>;
57 /**
58 * Sign in
59 * @param {String | SignInOpts} usernameOrSignInOpts - The username to be signed in or the sign in options
60 * @param {String} pw - The password of the username
61 * @param {ClientMetaData} clientMetadata - Client metadata for custom workflows
62 * @return - A promise resolves the CognitoUser
63 */
64 signIn(usernameOrSignInOpts: string | SignInOpts, pw?: string, clientMetadata?: ClientMetaData): Promise<CognitoUser | any>;
65 /**
66 * Return an object with the authentication callbacks
67 * @param {CognitoUser} user - the cognito user object
68 * @param {} resolve - function called when resolving the current step
69 * @param {} reject - function called when rejecting the current step
70 * @return - an object with the callback methods for user authentication
71 */
72 private authCallbacks;
73 /**
74 * Sign in with a password
75 * @private
76 * @param {AuthenticationDetails} authDetails - the user sign in data
77 * @return - A promise resolves the CognitoUser object if success or mfa required
78 */
79 private signInWithPassword;
80 /**
81 * Sign in without a password
82 * @private
83 * @param {AuthenticationDetails} authDetails - the user sign in data
84 * @return - A promise resolves the CognitoUser object if success or mfa required
85 */
86 private signInWithoutPassword;
87 /**
88 * This was previously used by an authenticated user to get MFAOptions,
89 * but no longer returns a meaningful response. Refer to the documentation for
90 * how to setup and use MFA: https://docs.amplify.aws/lib/auth/mfa/q/platform/js
91 * @deprecated
92 * @param {CognitoUser} user - the current user
93 * @return - A promise resolves the current preferred mfa option if success
94 */
95 getMFAOptions(user: CognitoUser | any): Promise<MFAOption[]>;
96 /**
97 * get preferred mfa method
98 * @param {CognitoUser} user - the current cognito user
99 * @param {GetPreferredMFAOpts} params - options for getting the current user preferred MFA
100 */
101 getPreferredMFA(user: CognitoUser | any, params?: GetPreferredMFAOpts): Promise<string>;
102 private _getMfaTypeFromUserData;
103 private _getUserData;
104 /**
105 * set preferred MFA method
106 * @param {CognitoUser} user - the current Cognito user
107 * @param {string} mfaMethod - preferred mfa method
108 * @return - A promise resolve if success
109 */
110 setPreferredMFA(user: CognitoUser | any, mfaMethod: 'TOTP' | 'SMS' | 'NOMFA' | 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA'): Promise<string>;
111 /**
112 * disable SMS
113 * @deprecated
114 * @param {CognitoUser} user - the current user
115 * @return - A promise resolves is success
116 */
117 disableSMS(user: CognitoUser): Promise<string>;
118 /**
119 * enable SMS
120 * @deprecated
121 * @param {CognitoUser} user - the current user
122 * @return - A promise resolves is success
123 */
124 enableSMS(user: CognitoUser): Promise<string>;
125 /**
126 * Setup TOTP
127 * @param {CognitoUser} user - the current user
128 * @return - A promise resolves with the secret code if success
129 */
130 setupTOTP(user: CognitoUser | any): Promise<string>;
131 /**
132 * verify TOTP setup
133 * @param {CognitoUser} user - the current user
134 * @param {string} challengeAnswer - challenge answer
135 * @return - A promise resolves is success
136 */
137 verifyTotpToken(user: CognitoUser | any, challengeAnswer: string): Promise<CognitoUserSession>;
138 /**
139 * Send MFA code to confirm sign in
140 * @param {Object} user - The CognitoUser object
141 * @param {String} code - The confirmation code
142 */
143 confirmSignIn(user: CognitoUser | any, code: string, mfaType?: 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA' | null, clientMetadata?: ClientMetaData): Promise<CognitoUser | any>;
144 completeNewPassword(user: CognitoUser | any, password: string, requiredAttributes?: any, clientMetadata?: ClientMetaData): Promise<CognitoUser | any>;
145 /**
146 * Send the answer to a custom challenge
147 * @param {CognitoUser} user - The CognitoUser object
148 * @param {String} challengeResponses - The confirmation code
149 */
150 sendCustomChallengeAnswer(user: CognitoUser | any, challengeResponses: string, clientMetadata?: ClientMetaData): Promise<CognitoUser | any>;
151 /**
152 * Delete an authenticated users' attributes
153 * @param {CognitoUser} - The currently logged in user object
154 * @return {Promise}
155 **/
156 deleteUserAttributes(user: CognitoUser | any, attributeNames: string[]): Promise<unknown>;
157 /**
158 * Delete the current authenticated user
159 * @return {Promise}
160 **/
161 deleteUser(): Promise<string | void>;
162 /**
163 * Update an authenticated users' attributes
164 * @param {CognitoUser} - The currently logged in user object
165 * @return {Promise}
166 **/
167 updateUserAttributes(user: CognitoUser | any, attributes: object, clientMetadata?: ClientMetaData): Promise<string>;
168 /**
169 * Return user attributes
170 * @param {Object} user - The CognitoUser object
171 * @return - A promise resolves to user attributes if success
172 */
173 userAttributes(user: CognitoUser | any): Promise<CognitoUserAttribute[]>;
174 verifiedContact(user: CognitoUser | any): Promise<{
175 verified: {};
176 unverified: {};
177 }>;
178 private isErrorWithMessage;
179 private isTokenRevokedError;
180 private isRefreshTokenRevokedError;
181 private isUserDisabledError;
182 private isUserDoesNotExistError;
183 private isRefreshTokenExpiredError;
184 private isSignedInHostedUI;
185 private isSessionInvalid;
186 private cleanUpInvalidSession;
187 /**
188 * Get current authenticated user
189 * @return - A promise resolves to current authenticated CognitoUser if success
190 */
191 currentUserPoolUser(params?: CurrentUserOpts): Promise<CognitoUser | any>;
192 private isOAuthInProgress;
193 /**
194 * Get current authenticated user
195 * @param {CurrentUserOpts} - options for getting the current user
196 * @return - A promise resolves to current authenticated CognitoUser if success
197 */
198 currentAuthenticatedUser(params?: CurrentUserOpts): Promise<CognitoUser | any>;
199 /**
200 * Get current user's session
201 * @return - A promise resolves to session object if success
202 */
203 currentSession(): Promise<CognitoUserSession>;
204 private _userSession;
205 /**
206 * Get the corresponding user session
207 * @param {Object} user - The CognitoUser object
208 * @return - A promise resolves to the session
209 */
210 userSession(user: any): Promise<CognitoUserSession>;
211 /**
212 * Get authenticated credentials of current user.
213 * @return - A promise resolves to be current user's credentials
214 */
215 currentUserCredentials(): Promise<ICredentials>;
216 currentCredentials(): Promise<ICredentials>;
217 /**
218 * Initiate an attribute confirmation request
219 * @param {Object} user - The CognitoUser
220 * @param {Object} attr - The attributes to be verified
221 * @return - A promise resolves to callback data if success
222 */
223 verifyUserAttribute(user: CognitoUser | any, attr: string, clientMetadata?: ClientMetaData): Promise<void>;
224 /**
225 * Confirm an attribute using a confirmation code
226 * @param {Object} user - The CognitoUser
227 * @param {Object} attr - The attribute to be verified
228 * @param {String} code - The confirmation code
229 * @return - A promise resolves to callback data if success
230 */
231 verifyUserAttributeSubmit(user: CognitoUser | any, attr: string, code: string): Promise<string>;
232 verifyCurrentUserAttribute(attr: string): Promise<void>;
233 /**
234 * Confirm current user's attribute using a confirmation code
235 * @param {Object} attr - The attribute to be verified
236 * @param {String} code - The confirmation code
237 * @return - A promise resolves to callback data if success
238 */
239 verifyCurrentUserAttributeSubmit(attr: string, code: string): Promise<string>;
240 private cognitoIdentitySignOut;
241 private oAuthSignOutRedirect;
242 private oAuthSignOutAndResolve;
243 private oAuthSignOutRedirectOrReject;
244 /**
245 * Sign out method
246 * @
247 * @return - A promise resolved if success
248 */
249 signOut(opts?: SignOutOpts): Promise<any>;
250 private cleanCachedItems;
251 /**
252 * Change a password for an authenticated user
253 * @param {Object} user - The CognitoUser object
254 * @param {String} oldPassword - the current password
255 * @param {String} newPassword - the requested new password
256 * @return - A promise resolves if success
257 */
258 changePassword(user: CognitoUser | any, oldPassword: string, newPassword: string, clientMetadata?: ClientMetaData): Promise<'SUCCESS'>;
259 /**
260 * Initiate a forgot password request
261 * @param {String} username - the username to change password
262 * @return - A promise resolves if success
263 */
264 forgotPassword(username: string, clientMetadata?: ClientMetaData): Promise<any>;
265 /**
266 * Confirm a new password using a confirmation Code
267 * @param {String} username - The username
268 * @param {String} code - The confirmation code
269 * @param {String} password - The new password
270 * @return - A promise that resolves if success
271 */
272 forgotPasswordSubmit(username: string, code: string, password: string, clientMetadata?: ClientMetaData): Promise<string>;
273 /**
274 * Get user information
275 * @async
276 * @return {Object }- current User's information
277 */
278 currentUserInfo(): Promise<any>;
279 federatedSignIn(options?: FederatedSignInOptions): Promise<ICredentials>;
280 federatedSignIn(provider: LegacyProvider, response: FederatedResponse, user: FederatedUser): Promise<ICredentials>;
281 federatedSignIn(options?: FederatedSignInOptionsCustom): Promise<ICredentials>;
282 /**
283 * Used to complete the OAuth flow with or without the Cognito Hosted UI
284 * @param {String} URL - optional parameter for customers to pass in the response URL
285 */
286 private _handleAuthResponse;
287 /**
288 * Compact version of credentials
289 * @param {Object} credentials
290 * @return {Object} - Credentials
291 */
292 essentialCredentials(credentials: any): ICredentials;
293 private attributesToObject;
294 private isTruthyString;
295 private createCognitoUser;
296 private _isValidAuthStorage;
297 private noUserPoolErrorHandler;
298 private rejectAuthError;
299 private rejectNoUserPool;
300 rememberDevice(): Promise<string | AuthError>;
301 forgetDevice(): Promise<void>;
302 fetchDevices(): Promise<IAuthDevice[]>;
303}
304export declare const Auth: AuthClass;