UNPKG

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