I’m using AWS Cognito to perform login authentication. When login is successful we get below request body :
Request body:
> {"UserContextData":{"EncodedData":"eyJ..9”},”ClientMetadata":{"cognito:deviceName":"MacBookPro12-01","cognito:bundleShortV":"1.0.0",
> "cognito:idForVendor":"A6FD46FBB205","cognito:bundleVersion":"207",
> "cognito:bundleId":"com.abc.Project-Dev","cognito:model":"iPhone", "cognito:systemName":"iOS","cognito:iOSVersion":"11.3"},
> "AuthParameters":{"SRP_A":"a6..627","SECRET_HASH":"vr..Oo=", "USERNAME":"[email protected]”},**”AuthFlow":"USER_SRP_AUTH"**,
> "ClientId”:”123”}
Now, there is a scenario wherein I’ve to set “AuthFlow” value to “USER_PASSWORD_AUTH”. How can this be done?
The headache with this is that all these values are set in Pods. Below code prints the request body that is added above :
passwordAuthenticationCompletion?.set(result: AWSCognitoIdentityPasswordAuthenticationDetails(username: username, password: password))
If you will look into AWSCognitoIdentityUser in method getSessionWithUserName andPassword you will see that there is a ternary operator switching migration auth that is driven by migrationEnabled Boolean value. In order to switch auth type just configure identity pool like so:
let userPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration (
clientId: clientId,
clientSecret: nil,
poolId: userPoolId,
shouldProvideCognitoValidationData: false,
pinpointAppId: nil,
migrationEnabled: true
)
I found you need to enable the migration in your amplifyconfigurqaton.json so that it uses the USER_PASSWORD_AUTH mode (it will ignore it otherwise):
{
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "xxxx",
"Region": "xxxxx"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "xxxxx",
"AppClientId": "xxxxx",
"Region": "xxxxx",
"MigrationEnabled" : true
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With