Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amplify.Auth.signIn not throwing userNotFound error #1600

Closed
YanZhaoNV opened this issue Aug 15, 2021 · 1 comment
Closed

Amplify.Auth.signIn not throwing userNotFound error #1600

YanZhaoNV opened this issue Aug 15, 2021 · 1 comment
Labels
auth Issues related to the Auth category closing soon This issue will be closed in 7 days unless further comments are made. question General question

Comments

@YanZhaoNV
Copy link

Describe the bug
Using iOS signIn function with none existing account, expecting userNotFound error but throw notAuthorized. Using the same account testing on Android give back the right error type.

To Reproduce
Steps to reproduce the behavior:

  1. try to sign in any cognito user db
  2. login with none existing user
  3. throw "notAuthorized" error

Observed Behavior

Expected Behavior
Should throw userNotFound as Android.

Stack Trace
Please provide a stack trace if applicable e.g. a crash is occurring.

Code Snippet

_ = Amplify.Auth.signIn(username: username, password: password) { result in
  switch result {
  case .success(let signInResult):
      if case .confirmSignUp(_) = signInResult.nextStep {
          confirm?()
      } else {
          success()
          UserDefaultsManager.shared.setValue(key: .userHasSignedIn, value: true)
      }
      DDLogDebug("Sign in succeeded")
  case .failure(let error):
      DDLogError("Sign in failed \(error)")
      switch error {
      case .service(let message, _, let uError):
          if let uError = uError as? AmplifyPlugins.AWSCognitoAuthError {
              switch uError {
              case .userNotFound:
                  failure(.usernameDoesntExist, message)
              default:
                  failure(.unknownError(underlyingError: error), message)
              }
          } else {
              failure(.unknownError(underlyingError: error), message)
          }
      case .notAuthorized(let description, _, _):
          failure(.notAuthorised, description)
          
      default:
          failure( .unknownError(underlyingError: error), error.errorDescription)
      }
  }

Environment(please complete the following information):

  • SDK Version: 1.13.0
  • Dependency Manager: Cocoapods
  • Swift Version : 5
  • Xcode Version: 12.5.1

Device Information (please complete the following information):

  • Device: any
  • iOS Version: any
  • Specific to simulators:

Additional context
Add any other context about the problem here like your specific use case.

@ghost ghost assigned ameter Jan 7, 2022
@ameter ameter transferred this issue from aws-amplify/aws-sdk-ios Jan 21, 2022
@ameter
Copy link
Contributor

ameter commented Jan 21, 2022

Thanks for the question. The error returned when attempting to sign in with a user that does not exist is configurable in the App Client settings of the Cognito User Pool. If you enable Prevent user existence errors for the App client, you will receive a .notAuthorized error:

Screen Shot 2022-01-21 at 4 29 39 PM

If you do not enable this feature, you will receive the legacy .service error with the .userNotFound underlying error:

Screen Shot 2022-01-21 at 4 33 31 PM

The reason for this change is to enable increased security by preventing disclosure of valid login ids while still supporting the legacy behavior if desired. Additional documentation is available here.

@ameter ameter added auth Issues related to the Auth category closing soon This issue will be closed in 7 days unless further comments are made. question General question labels Jan 21, 2022
@royjit royjit closed this as completed Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Issues related to the Auth category closing soon This issue will be closed in 7 days unless further comments are made. question General question
Projects
None yet
Development

No branches or pull requests

3 participants