1 | import { AuthOptions, FederatedResponse, SignUpParams, FederatedUser, ConfirmSignUpOptions, SignOutOpts, CurrentUserOpts, GetPreferredMFAOpts, SignInOpts, FederatedSignInOptionsCustom, LegacyProvider, FederatedSignInOptions, ClientMetaData } from './types';
|
2 | import { ICredentials } from '@aws-amplify/core';
|
3 | import { ISignUpResult, CognitoUser, MFAOption, CognitoUserSession, CognitoUserAttribute, NodeCallback } from 'amazon-cognito-identity-js';
|
4 | import { AuthError } from './Errors';
|
5 | import { IAuthDevice } from './types/Auth';
|
6 | /**
|
7 | * Provide authentication steps
|
8 | */
|
9 | export 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 | * String[]} restOfAttrs - for the backward compatability
{ |
34 | * if success
- A promise resolves callback data |
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 | private createUpdateAttributesResultList;
|
169 | /**
|
170 | * Return user attributes
|
171 | * @param {Object} user - The CognitoUser object
|
172 | * @return - A promise resolves to user attributes if success
|
173 | */
|
174 | userAttributes(user: CognitoUser | any): Promise<CognitoUserAttribute[]>;
|
175 | verifiedContact(user: CognitoUser | any): Promise<{
|
176 | verified: {};
|
177 | unverified: {};
|
178 | }>;
|
179 | private isErrorWithMessage;
|
180 | private isTokenRevokedError;
|
181 | private isRefreshTokenRevokedError;
|
182 | private isUserDisabledError;
|
183 | private isUserDoesNotExistError;
|
184 | private isRefreshTokenExpiredError;
|
185 | private isSignedInHostedUI;
|
186 | private isSessionInvalid;
|
187 | private cleanUpInvalidSession;
|
188 | /**
|
189 | * Get current authenticated user
|
190 | * @return - A promise resolves to current authenticated CognitoUser if success
|
191 | */
|
192 | currentUserPoolUser(params?: CurrentUserOpts): Promise<CognitoUser | any>;
|
193 | private isOAuthInProgress;
|
194 | /**
|
195 | * Get current authenticated user
|
196 | * @param {CurrentUserOpts} - options for getting the current user
|
197 | * @return - A promise resolves to current authenticated CognitoUser if success
|
198 | */
|
199 | currentAuthenticatedUser(params?: CurrentUserOpts): Promise<CognitoUser | any>;
|
200 | /**
|
201 | * Get current user's session
|
202 | * @return - A promise resolves to session object if success
|
203 | */
|
204 | currentSession(): Promise<CognitoUserSession>;
|
205 | private _userSession;
|
206 | /**
|
207 | * Get the corresponding user session
|
208 | * @param {Object} user - The CognitoUser object
|
209 | * @return - A promise resolves to the session
|
210 | */
|
211 | userSession(user: any): Promise<CognitoUserSession>;
|
212 | /**
|
213 | * Get authenticated credentials of current user.
|
214 | * @return - A promise resolves to be current user's credentials
|
215 | */
|
216 | currentUserCredentials(): Promise<ICredentials>;
|
217 | currentCredentials(): Promise<ICredentials>;
|
218 | /**
|
219 | * Initiate an attribute confirmation request
|
220 | * @param {Object} user - The CognitoUser
|
221 | * @param {Object} attr - The attributes to be verified
|
222 | * @return - A promise resolves to callback data if success
|
223 | */
|
224 | verifyUserAttribute(user: CognitoUser | any, attr: string, clientMetadata?: ClientMetaData): Promise<void>;
|
225 | /**
|
226 | * Confirm an attribute using a confirmation code
|
227 | * @param {Object} user - The CognitoUser
|
228 | * @param {Object} attr - The attribute to be verified
|
229 | * @param {String} code - The confirmation code
|
230 | * @return - A promise resolves to callback data if success
|
231 | */
|
232 | verifyUserAttributeSubmit(user: CognitoUser | any, attr: string, code: string): Promise<string>;
|
233 | verifyCurrentUserAttribute(attr: string): Promise<void>;
|
234 | /**
|
235 | * Confirm current user's attribute using a confirmation code
|
236 | * @param {Object} attr - The attribute to be verified
|
237 | * @param {String} code - The confirmation code
|
238 | * @return - A promise resolves to callback data if success
|
239 | */
|
240 | verifyCurrentUserAttributeSubmit(attr: string, code: string): Promise<string>;
|
241 | private cognitoIdentitySignOut;
|
242 | private oAuthSignOutRedirect;
|
243 | private oAuthSignOutAndResolve;
|
244 | private oAuthSignOutRedirectOrReject;
|
245 | /**
|
246 | * Sign out method
|
247 | * @
|
248 | * @return - A promise resolved if success
|
249 | */
|
250 | signOut(opts?: SignOutOpts): Promise<any>;
|
251 | private cleanCachedItems;
|
252 | /**
|
253 | * Change a password for an authenticated user
|
254 | * @param {Object} user - The CognitoUser object
|
255 | * @param {String} oldPassword - the current password
|
256 | * @param {String} newPassword - the requested new password
|
257 | * @return - A promise resolves if success
|
258 | */
|
259 | changePassword(user: CognitoUser | any, oldPassword: string, newPassword: string, clientMetadata?: ClientMetaData): Promise<'SUCCESS'>;
|
260 | /**
|
261 | * Initiate a forgot password request
|
262 | * @param {String} username - the username to change password
|
263 | * @return - A promise resolves if success
|
264 | */
|
265 | forgotPassword(username: string, clientMetadata?: ClientMetaData): Promise<any>;
|
266 | /**
|
267 | * Confirm a new password using a confirmation Code
|
268 | * @param {String} username - The username
|
269 | * @param {String} code - The confirmation code
|
270 | * @param {String} password - The new password
|
271 | * @return - A promise that resolves if success
|
272 | */
|
273 | forgotPasswordSubmit(username: string, code: string, password: string, clientMetadata?: ClientMetaData): Promise<string>;
|
274 | /**
|
275 | * Get user information
|
276 | * @async
|
277 | * @return {Object }- current User's information
|
278 | */
|
279 | currentUserInfo(): Promise<any>;
|
280 | federatedSignIn(options?: FederatedSignInOptions): Promise<ICredentials>;
|
281 | federatedSignIn(provider: LegacyProvider, response: FederatedResponse, user: FederatedUser): Promise<ICredentials>;
|
282 | federatedSignIn(options?: FederatedSignInOptionsCustom): Promise<ICredentials>;
|
283 | /**
|
284 | * Used to complete the OAuth flow with or without the Cognito Hosted UI
|
285 | * @param {String} URL - optional parameter for customers to pass in the response URL
|
286 | */
|
287 | private _handleAuthResponse;
|
288 | /**
|
289 | * Compact version of credentials
|
290 | * @param {Object} credentials
|
291 | * @return {Object} - Credentials
|
292 | */
|
293 | essentialCredentials(credentials: any): ICredentials;
|
294 | private attributesToObject;
|
295 | private isTruthyString;
|
296 | private createCognitoUser;
|
297 | private _isValidAuthStorage;
|
298 | private noUserPoolErrorHandler;
|
299 | private rejectAuthError;
|
300 | private rejectNoUserPool;
|
301 | rememberDevice(): Promise<string | AuthError>;
|
302 | forgetDevice(): Promise<void>;
|
303 | fetchDevices(): Promise<IAuthDevice[]>;
|
304 | }
|
305 | export declare const Auth: AuthClass;
|