Aws amplify signIn method returns Incorrect username and password while federatedSignIn (Hosted UI) works

1.8k Views Asked by At

I am using aws cognito for authentication. I have two environment for development and production hosted in two different region.

Development in us-east-1

Production in us-west-2

I want to change cognito hosted UI authentication (federatedSignIn) to custom aws-amplify signIn. Development configuration works fine while signIn in both hosted UI authentication and custom signIn aws-amplify. In production environment hosted UI works fine while signIn but custom signIn returns

{"__type":"NotAuthorizedException","message":"Incorrect username or password."}

for already existing users.

The only different configuration in development and production environment is

Development -> Always

Production -> No

Does this configuration effects custom signIn ?

enter image description here

aws-amplify configure

Amplify.configure({
  aws_project_region: *******************,
  aws_cognito_region: *******************,
  aws_user_pools_id: *******************,
  aws_user_pools_web_client_id: *******************,
  authenticationFlowType: 'USER_SRP_AUTH'
  oauth: {
    domain: *******************,
    scope: ['email', 'openid', 'profile'],
    redirectSignIn: `*******************`,
    redirectSignOut: `*******************`,
    responseType: 'code',
  },
});
2

There are 2 best solutions below

1
On

I am able to replicate the issue. The issue was wrong POOL_ID. Wrong POOL_ID doesn't effect hosted UI signIn but does effect effect amplify login, that's why its return 'Incorrect username and password' for correct email and password.

0
On

Try changing

authenticationFlowType: 'USER_SRP_AUTH'

to

authenticationFlowType: 'USER_PASSWORD_AUTH',

This changes the authentication flow to a standard built in flow as opposed to the more configurable Auth challenge flow.

I've not quite tracked down why I can't use auth-challenge flow, answers in the comments..