@aws-amplify/auth 5.6.3 → 5.6.4-unstable.bdaee91.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -117,7 +117,7 @@ export default class OAuth {
117
117
  this._urlOpener(URL, redirectSignIn);
118
118
  }
119
119
 
120
- private async _handleCodeFlow(currentUrl: string, userAgentValue?: string) {
120
+ private async _handleCodeFlow(currentUrl: string) {
121
121
  /* Convert URL into an object with parameters as keys
122
122
  { redirect_uri: 'http://localhost:3000/', response_type: 'code', ...} */
123
123
  const { code } = (parse(currentUrl).query || '')
@@ -169,12 +169,17 @@ export default class OAuth {
169
169
  .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
170
170
  .join('&');
171
171
 
172
+ const customUserAgentDetails: CustomUserAgentDetails = {
173
+ category: Category.Auth,
174
+ action: AuthAction.FederatedSignIn,
175
+ };
176
+
172
177
  const { access_token, refresh_token, id_token, error } = await (
173
178
  (await fetch(oAuthTokenEndpoint, {
174
179
  method: 'POST',
175
180
  headers: {
176
181
  'Content-Type': 'application/x-www-form-urlencoded',
177
- [USER_AGENT_HEADER]: userAgentValue,
182
+ [USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),
178
183
  },
179
184
  body,
180
185
  })) as any
@@ -212,10 +217,7 @@ export default class OAuth {
212
217
  };
213
218
  }
214
219
 
215
- public async handleAuthResponse(
216
- currentUrl?: string,
217
- userAgentValue?: string
218
- ) {
220
+ public async handleAuthResponse(currentUrl?: string) {
219
221
  try {
220
222
  const urlParams = currentUrl
221
223
  ? ({
@@ -242,10 +244,7 @@ export default class OAuth {
242
244
  `Starting ${this._config.responseType} flow with ${currentUrl}`
243
245
  );
244
246
  if (this._config.responseType === 'code') {
245
- return {
246
- ...(await this._handleCodeFlow(currentUrl, userAgentValue)),
247
- state,
248
- };
247
+ return { ...(await this._handleCodeFlow(currentUrl)), state };
249
248
  } else {
250
249
  return { ...(await this._handleImplicitFlow(currentUrl)), state };
251
250
  }
@@ -1,8 +0,0 @@
1
- {
2
- "name": "@aws-amplify/auth/internals",
3
- "types": "../lib-esm/internals/index.d.ts",
4
- "main": "../lib/internals/index.js",
5
- "module": "../lib-esm/internals/index.js",
6
- "react-native": "../lib-esm/internals/index.js",
7
- "sideEffects": false
8
- }
@@ -1,353 +0,0 @@
1
- import { AuthOptions, FederatedResponse, SignUpParams, FederatedUser, ConfirmSignUpOptions, SignOutOpts, CurrentUserOpts, GetPreferredMFAOpts, SignInOpts, FederatedSignInOptionsCustom, LegacyProvider, FederatedSignInOptions, ClientMetaData } from '../types';
2
- import { CustomUserAgentDetails, 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 InternalAuthClass {
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
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
35
- * @return - A promise resolves callback data if success
36
- */
37
- signUp(params: string | SignUpParams, ...restOfAttrs: any): Promise<ISignUpResult>;
38
- private handleAutoSignIn;
39
- private handleCodeAutoSignIn;
40
- private handleLinkAutoSignIn;
41
- private signInAfterUserConfirmed;
42
- /**
43
- * Send the verification code to confirm sign up
44
- * @param {String} username - The username to be confirmed
45
- * @param {String} code - The verification code
46
- * @param {ConfirmSignUpOptions} options - other options for confirm signup
47
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
48
- * @return - A promise resolves callback data if success
49
- */
50
- confirmSignUp(username: string, code: string, options?: ConfirmSignUpOptions, customUserAgentDetails?: CustomUserAgentDetails): Promise<any>;
51
- private isTrueStorageValue;
52
- /**
53
- * Resend the verification code
54
- * @param {String} username - The username to be confirmed
55
- * @param {ClientMetadata} clientMetadata - Metadata to be passed to Cognito Lambda triggers
56
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
57
- * @return - A promise resolves code delivery details if successful
58
- */
59
- resendSignUp(username: string, clientMetadata?: ClientMetaData, customUserAgentDetails?: CustomUserAgentDetails): Promise<any>;
60
- /**
61
- * Sign in
62
- * @param {String | SignInOpts} usernameOrSignInOpts - The username to be signed in or the sign in options
63
- * @param {String} pw - The password of the username
64
- * @param {ClientMetaData} clientMetadata - Client metadata for custom workflows
65
- * @return - A promise resolves the CognitoUser
66
- */
67
- signIn(usernameOrSignInOpts: string | SignInOpts, pw?: string, clientMetadata?: ClientMetaData, customUserAgentDetails?: CustomUserAgentDetails): Promise<CognitoUser | any>;
68
- /**
69
- * Return an object with the authentication callbacks
70
- * @param {InternalCognitoUser} user - the cognito user object
71
- * @param {} resolve - function called when resolving the current step
72
- * @param {} reject - function called when rejecting the current step
73
- * @return - an object with the callback methods for user authentication
74
- */
75
- private authCallbacks;
76
- /**
77
- * Sign in with a password
78
- * @private
79
- * @param {AuthenticationDetails} authDetails - the user sign in data
80
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
81
- * @return - A promise resolves the CognitoUser object if success or mfa required
82
- */
83
- private signInWithPassword;
84
- /**
85
- * Sign in without a password
86
- * @private
87
- * @param {AuthenticationDetails} authDetails - the user sign in data
88
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
89
- * @return - A promise resolves the InternalCognitoUser object if success or mfa required
90
- */
91
- private signInWithoutPassword;
92
- /**
93
- * This was previously used by an authenticated user to get MFAOptions,
94
- * but no longer returns a meaningful response. Refer to the documentation for
95
- * how to setup and use MFA: https://docs.amplify.aws/lib/auth/mfa/q/platform/js
96
- * @deprecated
97
- * @param {CognitoUser} user - the current user
98
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
99
- * @return - A promise resolves the current preferred mfa option if success
100
- */
101
- getMFAOptions(user: CognitoUser | any, customUserAgentDetails?: CustomUserAgentDetails): Promise<MFAOption[]>;
102
- /**
103
- * get preferred mfa method
104
- * @param {CognitoUser} user - the current cognito user
105
- * @param {GetPreferredMFAOpts} params - options for getting the current user preferred MFA
106
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
107
- */
108
- getPreferredMFA(user: CognitoUser | any, params?: GetPreferredMFAOpts, customUserAgentDetails?: CustomUserAgentDetails): Promise<string>;
109
- private _getMfaTypeFromUserData;
110
- private _getUserData;
111
- /**
112
- * set preferred MFA method
113
- * @param {CognitoUser} user - the current Cognito user
114
- * @param {string} mfaMethod - preferred mfa method
115
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
116
- * @return - A promise resolve if success
117
- */
118
- setPreferredMFA(user: CognitoUser | any, mfaMethod: 'TOTP' | 'SMS' | 'NOMFA' | 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA', customUserAgentDetails?: CustomUserAgentDetails): Promise<string>;
119
- /**
120
- * disable SMS
121
- * @deprecated
122
- * @param {CognitoUser} user - the current user
123
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
124
- * @return - A promise resolves is success
125
- */
126
- disableSMS(user: CognitoUser, customUserAgentDetails?: CustomUserAgentDetails): Promise<string>;
127
- /**
128
- * enable SMS
129
- * @deprecated
130
- * @param {CognitoUser} user - the current user
131
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
132
- * @return - A promise resolves is success
133
- */
134
- enableSMS(user: CognitoUser, customUserAgentDetails?: CustomUserAgentDetails): Promise<string>;
135
- /**
136
- * Setup TOTP
137
- * @param {CognitoUser} user - the current user
138
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
139
- * @return - A promise resolves with the secret code if success
140
- */
141
- setupTOTP(user: CognitoUser | any, customUserAgentDetails?: CustomUserAgentDetails): Promise<string>;
142
- /**
143
- * verify TOTP setup
144
- * @param {CognitoUser} user - the current user
145
- * @param {string} challengeAnswer - challenge answer
146
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
147
- * @return - A promise resolves is success
148
- */
149
- verifyTotpToken(user: CognitoUser | any, challengeAnswer: string, customUserAgentDetails?: CustomUserAgentDetails): Promise<CognitoUserSession>;
150
- /**
151
- * Send MFA code to confirm sign in
152
- * @param {Object} user - The CognitoUser object
153
- * @param {String} code - The confirmation code
154
- * @param {string} mfaType - optional mfaType: 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA'
155
- * @param {ClientMetaData} clientMetadata - optional client metadata defaults to config
156
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
157
- */
158
- confirmSignIn(user: CognitoUser | any, code: string, mfaType?: 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA' | null, clientMetadata?: ClientMetaData, customUserAgentDetails?: CustomUserAgentDetails): Promise<CognitoUser | any>;
159
- completeNewPassword(user: CognitoUser | any, password: string, requiredAttributes?: any, clientMetadata?: ClientMetaData, customUserAgentDetails?: CustomUserAgentDetails): Promise<CognitoUser | any>;
160
- /**
161
- * Send the answer to a custom challenge
162
- * @param {CognitoUser} user - The CognitoUser object
163
- * @param {String} challengeResponses - The confirmation code
164
- * @param {ClientMetaData} clientMetadata - optional client metadata defaults to config
165
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
166
- *
167
- */
168
- sendCustomChallengeAnswer(user: CognitoUser | any, challengeResponses: string, clientMetadata?: ClientMetaData, customUserAgentDetails?: CustomUserAgentDetails): Promise<CognitoUser | any>;
169
- /**
170
- * Delete an authenticated users' attributes
171
- * @param {CognitoUser} user - The currently logged in user object
172
- * @param {string[]} attributeNames - Attributes to delete
173
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
174
- * @return {Promise}
175
- **/
176
- deleteUserAttributes(user: CognitoUser | any, attributeNames: string[], customUserAgentDetails?: CustomUserAgentDetails): Promise<unknown>;
177
- /**
178
- * Delete the current authenticated user
179
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
180
- * @return {Promise}
181
- **/
182
- deleteUser(customUserAgentDetails?: CustomUserAgentDetails): Promise<string | void>;
183
- /**
184
- * Update an authenticated users' attributes
185
- * @param {CognitoUser} user - The currently logged in user object
186
- * @param {object} attributes - attributes to update
187
- * @param {ClientMetaData} clientMetadata - optional client metadata, defaults to config
188
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
189
- * @return {Promise}
190
- **/
191
- updateUserAttributes(user: CognitoUser | any, attributes: object, clientMetadata?: ClientMetaData, customUserAgentDetails?: CustomUserAgentDetails): Promise<string>;
192
- private createUpdateAttributesResultList;
193
- /**
194
- * Return user attributes
195
- * @param {Object} user - The CognitoUser object
196
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
197
- * @return - A promise resolves to user attributes if success
198
- */
199
- userAttributes(user: CognitoUser | any, customUserAgentDetails?: CustomUserAgentDetails): Promise<CognitoUserAttribute[]>;
200
- private _userAttributes;
201
- verifiedContact(user: CognitoUser | any, customUserAgentDetails?: CustomUserAgentDetails): Promise<{
202
- verified: {};
203
- unverified: {};
204
- }>;
205
- private isErrorWithMessage;
206
- private isTokenRevokedError;
207
- private isRefreshTokenRevokedError;
208
- private isUserDisabledError;
209
- private isUserDoesNotExistError;
210
- private isRefreshTokenExpiredError;
211
- private isPasswordResetRequiredError;
212
- private isSignedInHostedUI;
213
- private isSessionInvalid;
214
- private cleanUpInvalidSession;
215
- /**
216
- * Get current authenticated user
217
- * @param {CurrentUserOpts} params - options for getting the current user
218
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
219
- * @return - A promise resolves to current authenticated CognitoUser if success
220
- */
221
- currentUserPoolUser(params?: CurrentUserOpts, customUserAgentDetails?: CustomUserAgentDetails): Promise<CognitoUser | any>;
222
- private _currentUserPoolUser;
223
- private isOAuthInProgress;
224
- /**
225
- * Get current authenticated user
226
- * @param {CurrentUserOpts} - options for getting the current user
227
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
228
- * @return - A promise resolves to current authenticated CognitoUser if success
229
- */
230
- currentAuthenticatedUser(params?: CurrentUserOpts, customUserAgentDetails?: CustomUserAgentDetails): Promise<CognitoUser | any>;
231
- private _currentAuthenticatedUser;
232
- /**
233
- * Get current user's session
234
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
235
- * @return - A promise resolves to session object if success
236
- */
237
- currentSession(customUserAgentDetails?: CustomUserAgentDetails): Promise<CognitoUserSession>;
238
- private _currentSession;
239
- private _userSession;
240
- /**
241
- * Get the corresponding user session
242
- * @param {Object} user - The CognitoUser object
243
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
244
- * @return - A promise resolves to the session
245
- */
246
- userSession(user: any, customUserAgentDetails?: CustomUserAgentDetails): Promise<CognitoUserSession>;
247
- /**
248
- * Get authenticated credentials of current user.
249
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
250
- * @return - A promise resolves to be current user's credentials
251
- */
252
- currentUserCredentials(customUserAgentDetails?: CustomUserAgentDetails): Promise<ICredentials>;
253
- currentCredentials(customUserAgentDetails?: CustomUserAgentDetails): Promise<ICredentials>;
254
- /**
255
- * Initiate an attribute confirmation request
256
- * @param {Object} user - The CognitoUser
257
- * @param {Object} attr - The attributes to be verified
258
- * @param {ClientMetaData} clientMetadata - optional client metadata, defaults to config
259
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
260
- * @return - A promise resolves to callback data if success
261
- */
262
- verifyUserAttribute(user: CognitoUser | any, attr: string, clientMetadata?: ClientMetaData, customUserAgentDetails?: CustomUserAgentDetails): Promise<void>;
263
- private _verifyUserAttribute;
264
- /**
265
- * Confirm an attribute using a confirmation code
266
- * @param {Object} user - The CognitoUser
267
- * @param {Object} attr - The attribute to be verified
268
- * @param {String} code - The confirmation code
269
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
270
- * @return - A promise resolves to callback data if success
271
- */
272
- verifyUserAttributeSubmit(user: CognitoUser | any, attr: string, code: string, customUserAgentDetails?: CustomUserAgentDetails): Promise<string>;
273
- private _verifyUserAttributeSubmit;
274
- verifyCurrentUserAttribute(attr: string, customUserAgentDetails?: CustomUserAgentDetails): Promise<void>;
275
- /**
276
- * Confirm current user's attribute using a confirmation code
277
- * @param {Object} attr - The attribute to be verified
278
- * @param {String} code - The confirmation code
279
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
280
- * @return - A promise resolves to callback data if success
281
- */
282
- verifyCurrentUserAttributeSubmit(attr: string, code: string, customUserAgentDetails?: CustomUserAgentDetails): Promise<string>;
283
- private cognitoIdentitySignOut;
284
- private oAuthSignOutRedirect;
285
- private oAuthSignOutAndResolve;
286
- private oAuthSignOutRedirectOrReject;
287
- /**
288
- * Sign out method
289
- * @param {SignOutOpts} opts - options for sign out
290
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
291
- * @return - A promise resolved if success
292
- */
293
- signOut(opts?: SignOutOpts, customUserAgentDetails?: CustomUserAgentDetails): Promise<any>;
294
- private cleanCachedItems;
295
- /**
296
- * Change a password for an authenticated user
297
- * @param {Object} user - The CognitoUser object
298
- * @param {String} oldPassword - the current password
299
- * @param {String} newPassword - the requested new password
300
- * @param {ClientMetaData} clientMetadata - optional client metadata, defaults to config
301
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
302
- * @return - A promise resolves if success
303
- */
304
- changePassword(user: CognitoUser | any, oldPassword: string, newPassword: string, clientMetadata?: ClientMetaData, customUserAgentDetails?: CustomUserAgentDetails): Promise<'SUCCESS'>;
305
- /**
306
- * Initiate a forgot password request
307
- * @param {String} username - the username to change password
308
- * @param {ClientMetaData} clientMetadata - optional client metadata, defaults to config
309
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
310
- * @return - A promise resolves if success
311
- */
312
- forgotPassword(username: string, clientMetadata?: ClientMetaData, customUserAgentDetails?: CustomUserAgentDetails): Promise<any>;
313
- /**
314
- * Confirm a new password using a confirmation Code
315
- * @param {String} username - The username
316
- * @param {String} code - The confirmation code
317
- * @param {String} password - The new password
318
- * @param {ClientMetaData} clientMetadata - optional client metadata, defaults to config
319
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
320
- * @return - A promise that resolves if success
321
- */
322
- forgotPasswordSubmit(username: string, code: string, password: string, clientMetadata?: ClientMetaData, customUserAgentDetails?: CustomUserAgentDetails): Promise<string>;
323
- /**
324
- * Get user information
325
- * @async
326
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
327
- * @return {Object }- current User's information
328
- */
329
- currentUserInfo(customUserAgentDetails?: CustomUserAgentDetails): Promise<any>;
330
- federatedSignIn(providerOrOptions: LegacyProvider | FederatedSignInOptions | FederatedSignInOptionsCustom, response?: FederatedResponse, user?: FederatedUser, customUserAgentDetails?: CustomUserAgentDetails): Promise<ICredentials>;
331
- /**
332
- * Used to complete the OAuth flow with or without the Cognito Hosted UI
333
- * @param {String} URL - optional parameter for customers to pass in the response URL
334
- */
335
- private _handleAuthResponse;
336
- /**
337
- * Compact version of credentials
338
- * @param {Object} credentials
339
- * @return {Object} - Credentials
340
- */
341
- essentialCredentials(credentials: any): ICredentials;
342
- private attributesToObject;
343
- private isTruthyString;
344
- private createCognitoUser;
345
- private _isValidAuthStorage;
346
- private noUserPoolErrorHandler;
347
- private rejectAuthError;
348
- private rejectNoUserPool;
349
- rememberDevice(customUserAgentDetails?: CustomUserAgentDetails): Promise<string | AuthError>;
350
- forgetDevice(customUserAgentDetails?: CustomUserAgentDetails): Promise<void>;
351
- fetchDevices(customUserAgentDetails?: CustomUserAgentDetails): Promise<IAuthDevice[]>;
352
- }
353
- export declare const InternalAuth: InternalAuthClass;