amplify-swift: Unable to login on iOS, works on Android
Describe the bug
We have an application that is both for Android and iOS. We also have two environments: staging and production. In staging both iOS and Android application can log in successfully. In production Android application works, but on iOS application we are not able to log in users. This is the message we get:
“Incorrect username or password”
We suppose that production config on iOS is correct because user registration on iOS is working.
Steps To Reproduce
This is our login code:
import Amplify
import AWSPluginsCore
import Combine
import CombineExt
import Foundation
class LoginViewModel: BaseViewModel {
@Published var loginStatus: LoginStatus = .idle
enum LoginStatus: Equatable {
case idle
case error(desc: String)
case loading
case success
}
func login(email: String, password: String) {
loginStatus = .loading
Amplify.Publisher.create {
//_ = await Amplify.Auth.signOut()
_ = try await Amplify.Auth.signIn(username: email.lowercased(), password: password)
}
.flatMap {
Amplify.Publisher.create {
try await Amplify.Auth.fetchAuthSession()
}
.tryMap {
if let cognitoTokenProvider = $0 as? AuthCognitoTokensProvider,
let tokens = try? cognitoTokenProvider.getCognitoTokens().get() {
appLog("Id token - \(tokens.accessToken) ")
GlobalSettings.accessToken = tokens.accessToken
}
return $0.isSignedIn
}
}
.sinkOnMain(receiveFailure: { error in
self.loginStatus = .error(desc: self.getErrorDescription(from: error))
}, receiveValue: { self.loginStatus = $0 ? .success : .error(desc: .init(localized: "generic_error")) })
.store(in: &subscribers)
}
}
### Expected behavior
User is authenticated
### Amplify Framework Version
2.45.0
### Amplify Categories
Auth
### Dependency manager
Swift PM
### Swift version
5
### CLI version
--
### Xcode version
16.1
### Relevant log output
```shell
<details>
<summary>Relevant log</summary>
[APP ERROR 🔴] LoginView.swift - body - line 85
loginStatus: error: Incorrect username or password.
2024-12-04 17:33:07.976093+0100 -prod[495:19561] [AuthenticationAWSCognitoAuthPlugin] Auth state change:
{
"AuthState.configured" = {
"AuthenticationState.signingIn" = {
"SignInState.signingInWithSRP" = {
"SRPSignInState.error" = {
Error = "AWSCognitoAuthPlugin.SignInError.service(error: AWSCognitoIdentityProvider.NotAuthorizedException(properties: AWSCognitoIdentityProvider.NotAuthorizedException.Properties(message: Optional(\"Incorrect username or password.\")), httpResponse: \nStatus Code: HTTP status code: 400 \n x-amzn-errormessage: Incorrect username or password., \nx-amzn-requestid: e7e0b232-6215-4611-b1f5-bf04243e5a73, \nContent-Length: 79, \nDate: Wed, 04 Dec 2024 16:33:07 GMT, \nContent-Type: application/x-amz-json-1.1, \nx-amzn-errortype: NotAuthorizedException:, message: nil, requestID: nil))";
};
clientMetadata = {
};
password = "<REDACTED>";
session = "";
signInMethod = "AWSCognitoAuthPlugin.SignInMethod.apiBased(AWSCognitoAuthPlugin.AuthFlowType.userSRP)";
username = "om************om";
};
};
"AuthorizationState.configured" = {
};
"SignUpState.notStarted" = {
};
};
}
2024-12-04 17:33:07.976667+0100 -prod[495:19561] [AuthenticationAWSCognitoAuthPlugin] Auth state change:
{
"AuthState.configured" = {
"AuthenticationState.signedOut" = {
lastKnownUserName = "(nil)";
};
"AuthorizationState.configured" = {
};
"SignUpState.notStarted" = {
};
};
}
```
Is this a regression?
No
Regression additional context
No response
Platforms
iOS
OS Version
16.7.10
Device
iPhoneX
Specific to simulators
No response
Additional context
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 27 (14 by maintainers)
SRP always works in staging environment (both iOS and Android) and never works in production (both iOS and Android).
Anyway I feel we can close this issue as it is probably not related to amplify-swift specifically, but it may be related to Cognito or both the client libraries.