UNPKG

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