aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.32k stars 247 forks source link

Reset Password is not sending any verification messages using SMS Flow Auth #2506

Closed caramelfactorydevp closed 1 year ago

caramelfactorydevp commented 1 year ago

Description

I am working on a feature "Forgot Password" which allows the user to receive a verification code from the SMS message than reset the password to the new one. However, when I call the functionawait Amplify.Auth.resetPassword( username: phoneNum,);, no messages regarding this are received. When I check the SNS, I haven't reached the limit yet and the signIn and resendSignUpCode are working as well. Besides, I can't find any errors in the SMS delivery logs in the SNS. Can I know what is the issue regarding this?

Categories

Steps to Reproduce

No response

Screenshots

No response

Platforms

Android Device/Emulator API Level

No response

Environment

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.9, on macOS 13.0.1 22A400 darwin-arm, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.73.1)
[✓] VS Code (version 1.63.0)
[✓] Connected device (4 available)
[✓] HTTP Host Availability

Dependencies

dependencies:
- amplify_api 0.6.10 [amplify_api_android amplify_api_ios amplify_core amplify_flutter aws_common collection flutter meta plugin_platform_interface]
- amplify_auth_cognito 0.6.10 [amplify_auth_cognito_android amplify_auth_cognito_ios amplify_core aws_common collection flutter meta plugin_platform_interface]
- amplify_flutter 0.6.10 [amplify_core amplify_datastore_plugin_interface amplify_flutter_android amplify_flutter_ios aws_common collection flutter meta plugin_platform_interface]
- another_flushbar 1.12.29 [flutter]
- cupertino_icons 1.0.5
- flex_color_scheme 6.1.1 [flex_seed_scheme flutter meta]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]
- flutter_markdown 0.6.13 [flutter markdown meta path]
- flutter_screenutil 5.6.0 [flutter]
- flutter_spinkit 5.1.0 [flutter]
- google_fonts 3.0.1 [flutter http path_provider crypto]
- provider 6.0.4 [collection flutter nested]
- shared_preferences 2.0.15 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- string_validator 0.3.0

Device

IPhone 14

OS

IOS 14

Deployment Method

Amplify CLI

CLI Version

No response

Additional Context

No response

Amplify Config

const amplifyconfig = ''' { "UserAgent": "aws-amplify-cli/2.0", "Version": "1.0", "auth": { "plugins": { "awsCognitoAuthPlugin": { "UserAgent": "aws-amplify-cli/0.1.0", "Version": "0.1.0", "IdentityManager": { "Default": {} }, "CognitoUserPool": { "Default": { "PoolId": "", "AppClientId": "", "Region": "" } }, "Auth": { "Default": { "OAuth": { "WebDomain": "", "AppClientId": "", "SignInRedirectURI": "http://localhost:3000/", "SignOutRedirectURI": "http://localhost:3000/signout", "Scopes": [ "email", "openid", "profile" ] }, "authenticationFlowType": "USER_SRP_AUTH", "socialProviders": [], "usernameAttributes": [ "EMAIL" ], "signupAttributes": [], "passwordProtectionSettings": { "passwordPolicyMinLength": 8, "passwordPolicyCharacters": [ "REQUIRES_LOWERCASE", "REQUIRES_UPPERCASE" ] }, "mfaConfiguration": "OFF", "mfaTypes": [], "verificationMechanisms": [ "EMAIL" ] } } } } } }''';

Jordan-Nelson commented 1 year ago

Hi @caramelfactorydevp - It looks like you are calling resetPassword with a phone number, but the config you shared has the usernameAttributes set to email. Have you configured Amplify to use phone number as a username? I also see that you have verificationMechanisms set to email. Have you configured Amplify to use phone number for verification?

caramelfactorydevp commented 1 year ago

Hi apology, I think I have copied the wrong config into this issue. The config below is what I am currently using.

const amplifyconfig = ''' { "UserAgent": "aws-amplify-cli/2.0", "Version": "1.0", "api": { "plugins": { "awsAPIPlugin": { "appsync-XXX": { "endpointType": "GraphQL", "endpoint": "XXX", "region": "us-east-1", "authorizationType": "AWS_IAM" } } } }, "auth": { "plugins": { "awsCognitoAuthPlugin": { "UserAgent": "aws-amplify-cli/0.1.0", "Version": "0.1.0", "IdentityManager": { "Default": {} }, "AppSync": { "Default": { "ApiUrl": "XXX", "Region": "us-east-1", "AuthMode": "AWS_IAM", "ClientDatabasePrefix": "appsync-XXX_AWS_IAM" } }, "CredentialsProvider": { "CognitoIdentity": { "Default": { "PoolId": "us-east-1:XXX", "Region": "us-east-1" } } }, "CognitoUserPool": { "Default": { "PoolId": "us-east-1_XXX", "AppClientId": "XXX", "Region": "us-east-1" } }, "Auth": { "Default": { "OAuth": { "WebDomain": "XXX", "AppClientId": "XXX", "SignInRedirectURI": "http://localhost:3000/", "SignOutRedirectURI": "http://localhost:3000/signout", "Scopes": [ "email", "openid", "profile" ] }, "authenticationFlowType": "USER_SRP_AUTH", "socialProviders": [], "usernameAttributes": [ "PHONE_NUMBER" ], "signupAttributes": [], "passwordProtectionSettings": { "passwordPolicyMinLength": 8, "passwordPolicyCharacters": [ "REQUIRES_LOWERCASE", "REQUIRES_UPPERCASE" ] }, "mfaConfiguration": "ON", "mfaTypes": [ "SMS", "TOTP" ], "verificationMechanisms": ["PHONE_NUMBER"] } } } } } }''';

caramelfactorydevp commented 1 year ago

Besides, the phone number that I am using has been verified

Jordan-Nelson commented 1 year ago

Okay. I have a few follow up questions:

  1. Are you receiving texts when signing up a user? is this issue specific to reset password?
  2. Is the recovery attribute verified? By default, the user will be sent a verification code during sign up (email or text, based on your configuration). The user will have to enter that code to complete sign up. This will verify the attribute, which will allow it to be used for account recovery. If you update the attribute, it will have to be re-verified. The response from Amplify.Auth.fetchUserAttributes() will contain info on which attributes are verified.
  3. Can you confirm your settings in Cognito under Sign Up -> Attributes to verify (see example screenshot below)
Screen Shot 2022-12-22 at 11 24 33 AM
caramelfactorydevp commented 1 year ago
  1. Yes, this issue only specific to reset password.
  2. Yes, the attribute are verified.
  3. image

I saw the banner in my SNS, and I haven't registered the origination number yet. Is this the reason that I can't callreset password? The image below is the documentation about reset password that I found. image

faisalmushtaq007 commented 1 year ago

I have a requirement that i have to use aws authentication in my app, now i remember that the backend guy told me to use aws cognito. When i was doing research i came across aws amplify. Now i am confused if i can use aws amplify or not. Please guide me here!

Jordan-Nelson commented 1 year ago

@faisalmushtaq007 - amplify_auth_cognito uses AWS Cognito. You can use the Amplify CLI to create a new Cognito backend, or you can use an existing Cognito backend as described here. If you have any other questions, please open a new issue so that we can keep this issue focused on the reset password flow and SMS use. Thanks.

Jordan-Nelson commented 1 year ago

@caramelfactorydevp - I was able to reproduce this when creating an app with the Amplify CLI and accepting the majority of the default settings. I looked into the failures in AWS SNS (note: to do this you need to enable logging in SNS). I found that the messages were failing with this message: Phone carrier has blocked this message.

It is possible that your messages are being blocked by the carriers. Have you registered your toll free number?

Note: I was able to get messages to send again simply by updating the message template from the default to something a little more custom to my sample app. That may work, but I would suggest looking at the TFN docs above.

If you have already registered your TFN, can you enable logging in SNS and let me know if there is a failure log?

Jordan-Nelson commented 1 year ago

I am going to close this out since we have not heard back and I think it is likely that your messages were simply being blocked by carriers as spam. If you are still experiencing this issue please enable logging in SNS and share the failure reason.