amplify-swift icon indicating copy to clipboard operation
amplify-swift copied to clipboard

authenticationFlowType: "USER_PASSWORD_AUTH not working with Amplify iOS SDK 1.26.2

Open AdiPomelo opened this issue 3 years ago • 7 comments
trafficstars

Describe the bug

In my current iOS project using Amplify iOS SDK(1.26.2). Our main aim to migrate users from database to Cognito and create new account. We are using two authentication flow CUSTOM_AUTH and USER_PASSWORD_AUTH. First I do CUSTOM_AUTH, but if the user is not found, I do USER_PASSWORD_AUTH that triggers a user migration from our db to Cognito.

ISSUE:

  • If I use CUSTOM_AUTH authentication able to create new user and login with existing users but not working for migrated users.
  • If I add MigrationEnabled": true to awsconfiguration.json and amplifyconfiguration.json at that time USER_PASSWORD_AUTH authentication working fine and user able to migrate successfully but not working CUSTOM_AUTH flow.

This is request for CUSTOM_AUTH with password nil

 let options = AWSAuthSignInOptions(metadata: [AuthUserAttributeKey.phoneNumber.rawValue:"1234567890"], authFlowType: .custom)
        Amplify.Auth.signIn(username: phone, options: .init(pluginOptions: option)) {  [weak self] result in
        }

This is request for USER_PASSWORD_AUTH with password static string

 Amplify.Auth.signIn(username: phone, password: "Static key provided by Backend team", options: .init(pluginOptions: ["authenticationFlowType": "USER_PASSWORD_AUTH"])) {  }

NOTE Both web and Android working as expected.

This is my complete json file. Screen Shot 2565-07-15 at 16 16 01

Steps To Reproduce

1.Create Custom Auth flow type and try to switch between CUSTOM_AUTH and USER_PASSWORD_AUTH auth dynamically.
2.Add Amplfy iOS SDK(1.26.2) to iOS project.
3.Try to SignIn using Amplify.Auth.Signin Api with above mentioned auth types.

Expected behavior

I can able to switch between two authentications dynamically( CUSTOM_AUTH and USER_PASSWORD_AUTH).

Amplify Framework Version

1.26.2

Amplify Categories

Auth

Dependency manager

Cocoapods

Swift version

5.0

CLI version

9.1.0

Xcode version

13.4

Relevant log output

No response

Is this a regression?

No

Regression additional context

No response

Device

iPhone 13

iOS Version

15.5

Specific to simulators

Iphone 13 Pro Max

Additional context

No response

AdiPomelo avatar Jul 15 '22 10:07 AdiPomelo

@AdiPomelo There are a couple of things that needs to be mentioned here

  1. options: .init(pluginOptions: ["authenticationFlowType": "USER_PASSWORD_AUTH"]) is not the correct way to provide flow type to Amplify. authFlowType: .custom in the sign in parameter is the correct way to do it. This way the Amplify will default to the flow type in the configuration file.
  2. Amplify iOS only supports userSRP and custom flows at the moment.

harsh62 avatar Jul 15 '22 18:07 harsh62

@harsh62 Thank you for quick reply.

NOTE: If I add MigrationEnabled": true to awsconfiguration.json and amplifyconfiguration.json at that time USER_PASSWORD_AUTH authentication working fine and user is able to migrate successfully but not working CUSTOM_AUTH flow.

Like you said USER_PASSWORD_AUTH not supporting in IOS, why it is working when I add MigrationEnabled": true to json config file of amplify?

OR Can you suggest me is there any way to fix this problem, right now our app release process is struck because of this.

AdiPomelo avatar Jul 18 '22 01:07 AdiPomelo

@AdiPomelo : It could work because the low level AWS-SDK supports it. So you are running into a scenario which is an undocumented feature and I personally would not rely on it.

Our team is working on fixing all these scenarios on Amplify and hopefully we would be able to tackle them soon.

harsh62 avatar Jul 18 '22 13:07 harsh62

@harsh62 Thank you for reply.

Can I expect this feature in the coming release or It would be great if you provide a date based on that will plan further.

AdiPomelo avatar Jul 19 '22 02:07 AdiPomelo

@AdiPomelo

We are unable to provide any concrete dates at the moment, we will send out communication and update the ticket once we have more information on this. Thank you!

harsh62 avatar Jul 20 '22 16:07 harsh62

This has been identified as a feature request. If this feature is important to you, we strongly encourage you to give a 👍 reaction on the request. This helps us prioritize new features most important to you. Thank you!

github-actions[bot] avatar Jul 20 '22 16:07 github-actions[bot]

@harsh62 I am currently looking into amplify iOS SDK to add new authFlowType called USER_PASSWORD_AUTH. is there anything you can help on this OR could you suggest something ?

NOTE I have cloned the Amplify iOS SDK from git and added one more case to AuthFlowType enum and tested with my application but that is not working. I think added code is not enough.

Screenshots added for your reference. Screen Shot 2565-07-28 at 17 41 51 Screen Shot 2565-07-28 at 17 41 59

AdiPomelo avatar Jul 28 '22 10:07 AdiPomelo

We released User password auth as a flow type in the latest version of Amplify. Released in v2.0.0

royjit avatar Oct 20 '22 02:10 royjit

Hi, It seems that it is not added Amplify v1.30.4. How can I login with USER_PASSWORD_AUTH in Amplify v1?

sekitaka avatar Jul 19 '23 00:07 sekitaka

@sekitaka This feature is only available in Amplify V2+. This was a feature addition done to V2 and was never part of Amplify V1. There are currently no plans to support this on Amplify V1.

I would suggest upgrading to Amplify V2.

harsh62 avatar Jul 19 '23 02:07 harsh62

@harsh62 Hi thank you for response. OK. I got it. by the way we can not use Amplify v2 because of swift package manager. we excluded arm64...

sekitaka avatar Jul 19 '23 02:07 sekitaka