aws-amplify / amplify-swift

A declarative library for application development using cloud services.
Apache License 2.0
447 stars 193 forks source link

CUSTOM_AUTH not working on v2.2.0 (working on 1.28.3) #2608

Closed JurajBegovac closed 1 year ago

JurajBegovac commented 1 year ago

Describe the bug

Confirming SMS code is not working when using CUSTOM_AUTH as authenticationFlowType.

Not working on 2.2.0 - working on 1.28.3 (it would be nice to have 2.0.0 because of async await)

Steps To Reproduce

This is our use case:

  1. Call signup (in case of success go to signIn, or in case user exists go to signIn) - Working ✅

try await Amplify.Auth.signUp(username: username, password: password, options: options)

2. Call signIn - Working ✅ 
```swift
try await Amplify.Auth.signIn(username: username, password: password)
  1. After that I get SMS code which I want to confirm with - not Working 🔴 (just calls the function and get stucked forever)
    try await Amplify.Auth.confirmSignIn(challengeResponse: smsCode)

Our awsConfig:

{
    "auth":
    {
        "plugins":
        {
            "awsCognitoAuthPlugin":
            {
                "CognitoUserPool":
                {
                    "Default":
                    {
                        "PoolId": "our-pool",
                        "AppClientId": "our-appclientId",
                        "AppClientSecret": "our-appSecret",
                        "Region": "our-region"
                    }
                },
                "Auth":
                {
                    "Default":
                    {
                        "authenticationFlowType": "CUSTOM_AUTH"
                    }
                }
            }
        }
    }
}

### Expected behavior

It works - returns succes or error

### Amplify Framework Version

2.2.0

### Amplify Categories

Auth

### Dependency manager

Swift PM

### Swift version

5.7

### CLI version

-

### Xcode version

14.1

### Relevant log output

```shell
<details>
<summary>Log Messages</summary>

INSERT LOG MESSAGES HERE



### Is this a regression?

No

### Regression additional context

_No response_

### Device

iPhone 14- Simulator

### iOS Version

iOS 16.1

### Specific to simulators

_No response_

### Additional context

I'm working on KMM project where I have interface/protocol inside shared module and implementations on iOS and Android side. 
I have to say this error exists in Android 2.x.x version as well (just slightly different) - will post issue there as well.
phantumcode commented 1 year ago

@JurajBegovac Can you share your amplifyconfiguration.json (with identifiable details redacted)?

JurajBegovac commented 1 year ago

@phantumcode but I added awsConfig in my initial post. We don't use amplifyconfiguration.json because we want to insert some data dynamically. So we add it like this:

        AuthCategoryConfiguration(
                plugins: [
                    "awsCognitoAuthPlugin": [
                        "CognitoUserPool": [
                            "Default": [
                                "PoolId": .string("poolId"),
                                "Region": .string("region"),
                                "AppClientId": .string("clientId"),
                                "AppClientSecret": .string("clientSecret")
                            ]
                        ],
                        "Auth": [
                            "Default": [
                                "authenticationFlowType": "CUSTOM_AUTH"
                            ]
                        ]
                    ]
                ]
        )
phantumcode commented 1 year ago

@JurajBegovac Since you didn't use the Amplify CLI and don't have an amplifyconfiguration.json, it's difficult to reproduce the issue without additional context or specific details of how you've configuration authentication with MFA. Can you provide additional logs or console logs when you're seeing the issue? Is there an error be thrown or captured?

Some other information that would help:

phantumcode commented 1 year ago

@JurajBegovac Additional logging can be enabled by adding this line when configuring Amplify plugins: Amplify.Logging.logLevel = .verbose

patrickjohnson97 commented 1 year ago

I'm having the same issue as OP. I'm not sure how helpful this will be, but here is my amplify configuration.json file:

Amplify Configuration ```json { "UserAgent": "aws-amplify-cli/2.0", "Version": "1.0", "api": { "plugins": { "awsAPIPlugin": { "radar": { "endpointType": "GraphQL", "endpoint": "https://.appsync-api.us-west-2.amazonaws.com/graphql", "region": "us-west-2", "authorizationType": "AMAZON_COGNITO_USER_POOLS", "apiKey": "" } } } }, "auth": { "plugins": { "awsCognitoAuthPlugin": { "UserAgent": "aws-amplify/cli", "Version": "0.1.0", "IdentityManager": { "Default": {} }, "CredentialsProvider": { "CognitoIdentity": { "Default": { "PoolId": "us-west-2:", "Region": "us-west-2" } } }, "CognitoUserPool": { "Default": { "PoolId": "us-west-2_", "AppClientId": "", "Region": "us-west-2" } }, "GoogleSignIn": { "Permissions": "email,profile,openid", "ClientId-WebApp": ".apps.googleusercontent.com", "ClientId-iOS": ".apps.googleusercontent.com" }, "Auth": { "Default": { "OAuth": { "WebDomain": ".auth.us-west-2.amazoncognito.com", "AppClientId": "", "SignInRedirectURI": "://", "SignOutRedirectURI": "://", "Scopes": [ "phone", "email", "openid", "profile", "aws.cognito.signin.user.admin" ] }, "authenticationFlowType": "CUSTOM_AUTH", "socialProviders": [], "usernameAttributes": [ "EMAIL", "PHONE_NUMBER" ], "signupAttributes": [ "EMAIL" ], "passwordProtectionSettings": { "passwordPolicyMinLength": 8, "passwordPolicyCharacters": [] }, "mfaConfiguration": "OPTIONAL", "mfaTypes": [ "SMS" ], "verificationMechanisms": [ "PHONE_NUMBER" ] } }, "AppSync": { "Default": { "ApiUrl": "https://.appsync-api.us-west-2.amazonaws.com/graphql", "Region": "us-west-2", "AuthMode": "AMAZON_COGNITO_USER_POOLS", "ClientDatabasePrefix": "radar_AMAZON_COGNITO_USER_POOLS" }, "radar_API_KEY": { "ApiUrl": "https://.appsync-api.us-west-2.amazonaws.com/graphql", "Region": "us-west-2", "AuthMode": "API_KEY", "ApiKey": "", "ClientDatabasePrefix": "radar_API_KEY" } }, "S3TransferUtility": { "Default": { "Bucket": "", "Region": "us-west-2" } } } } }, "storage": { "plugins": { "awsS3StoragePlugin": { "bucket": "", "region": "us-west-2", "defaultAccessLevel": "guest" } } } } ```

To answer your follow up questions:

patrickjohnson97 commented 1 year ago

As per the instructions in the setup guide, I have 3 lambdas to execute the custom auth flow. Looking into the cloudwatch logs / metrics I can see that the Define Challenge and Create Challenge lambdas were invoked with the sign in method invocation, but there is never an invocation of the Verify Challenge lambda when the confirm sign in method is executed. On my app, I know that the process must be hung somewhere because after submitting the challenge code (while waiting for the confirmation), if I go back to the sign in page and sign in using a different email / phone number, that new sign in call will not finish either. Looks like something is going wrong in the verify code before it reaches my lambda.

phantumcode commented 1 year ago

@JurajBegovac @patrickjohnson97 Do you have client side log? From Xcode console or logs from your iOS app or a stacktrace in a debug session?

phantumcode commented 1 year ago

@patrickjohnson97 If you have email verification enabled, are you calling confirmSignUp with the email verification code prior to calling signIn and confirmSignIn?

JurajBegovac commented 1 year ago

@phantumcode Ok here is some verbose log: After I make signup, then signin (that's ok) - then I call confirmCredential - and then nothing happens:

Logs ``` 2022-12-19 11:00:09.674875+0100 iosApp[65648:2045451] [Amplify] Configuring 2022-12-19 11:00:09.677581+0100 iosApp[65648:2045451] [Amplify] Configuration: Optional(Amplify.AmplifyConfiguration(analytics: nil, api: nil, auth: Optional(Amplify.AuthCategoryConfiguration(plugins: ["awsCognitoAuthPlugin": Amplify.JSONValue.object(["CognitoUserPool": Amplify.JSONValue.object(["Default": Amplify.JSONValue.object(["AppClientSecret": Amplify.JSONValue.string(), "PoolId": Amplify.JSONValue.string(""), "AppClientId": Amplify.JSONValue.string(), "Region": Amplify.JSONValue.string()])]), "Auth": Amplify.JSONValue.object(["Default": Amplify.JSONValue.object(["authenticationFlowType": Amplify.JSONValue.string("CUSTOM_AUTH")])])])])), dataStore: nil, geo: nil, hub: nil, logging: nil, predictions: nil, storage: nil)) 2022-12-19 11:00:09.684011+0100 iosApp[65648:2045451] [Amplify] Could not find Cognito Identity Pool configuration 2022-12-19 11:00:09.691145+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.notConfigured" = { }; } 2022-12-19 11:00:09.691686+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] Credential Store state change: notConfigured 2022-12-19 11:00:09.695634+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configuringAuth" = { }; } 2022-12-19 11:00:09.695739+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeAuthConfiguration.swift Starting execution 2022-12-19 11:00:09.696738+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] Credential Store state change: migratingLegacyStore 2022-12-19 11:00:09.696957+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/MigrateLegacyCredentialStore.swift Starting execution 2022-12-19 11:00:09.723054+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/MigrateLegacyCredentialStore.swift Sending event CredentialStoreEvent.loadCredentialStore 2022-12-19 11:00:09.723156+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Credential Store state change: loadingStoredCredentials 2022-12-19 11:00:09.723186+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Starting execution 2022-12-19 11:00:09.723643+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Retreiving credential amplifyCredentials 2022-12-19 11:00:09.726848+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Sending event CredentialStoreEvent.throwError 2022-12-19 11:00:09.726953+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution 2022-12-19 11:00:09.727001+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState 2022-12-19 11:00:09.727042+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] No existing session found. 2022-12-19 11:00:09.727114+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeAuthConfiguration.swift Sending event AuthEvent.validateCredentialAndConfiguration 2022-12-19 11:00:09.727180+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Credential Store state change: error(KeychainStoreError: Unable to find the keychain item Recovery suggestion: This should not happen. There is a possibility that there is a bug if this error persists. Please take a look at https://github.com/aws-amplify/amplify-ios/issues to see if there are any existing issues that match your scenario, and file an issue with the details of the bug if there isn't. Issue encountered at: file: /Users/jurajbegovac/Library/Developer/Xcode/DerivedData/iosApp-ceumhqdilblatpbydusmyekmjbds/SourcePackages/checkouts/amplify-swift/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreError.swift function: recoverySuggestion line: 69) 2022-12-19 11:00:09.727243+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Credential Store state change: idle 2022-12-19 11:00:09.727437+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/ValidateCredentialsAndConfiguration.swift Starting execution 2022-12-19 11:00:09.727469+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.validatingCredentialsAndConfiguration" = { }; } 2022-12-19 11:00:09.727481+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/ValidateCredentialsAndConfiguration.swift Sending event AuthEvent.configureAuthentication 2022-12-19 11:00:09.729082+0100 iosApp[65648:2045686] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configuringAuthentication" = { "AuthenticationState.notConfigured" = { }; }; } 2022-12-19 11:00:09.729398+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeAuthenticationConfiguration.swift Starting execution 2022-12-19 11:00:09.729453+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeAuthenticationConfiguration.swift Sending event AuthenticationEvent.configure 2022-12-19 11:00:09.730483+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/ConfigureAuthentication.swift Start execution 2022-12-19 11:00:09.730499+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configuringAuthentication" = { "AuthenticationState.configured" = { }; }; } 2022-12-19 11:00:09.731065+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/ConfigureAuthentication.swift Sending event AuthenticationEvent.initializedSignedOut 2022-12-19 11:00:09.731161+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/ConfigureAuthentication.swift Sending event AuthEvent.authenticationConfigured 2022-12-19 11:00:09.731184+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configuringAuthentication" = { "AuthenticationState.signedOut" = { lastKnownUserName = "(nil)"; }; }; } 2022-12-19 11:00:09.732568+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeAuthorizationConfiguration.swift Starting execution 2022-12-19 11:00:09.732767+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeAuthorizationConfiguration.swift Sending event AuthorizationEvent.configure 2022-12-19 11:00:09.732956+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configuringAuthorization" = { "AuthenticationState.signedOut" = { lastKnownUserName = "(nil)"; }; "AuthorizationState.notConfigured" = { }; }; } 2022-12-19 11:00:09.734674+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/ConfigureAuthorization.swift Starting execution 2022-12-19 11:00:09.734707+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configuringAuthorization" = { "AuthenticationState.signedOut" = { lastKnownUserName = "(nil)"; }; "AuthorizationState.configured" = { }; }; } 2022-12-19 11:00:09.734723+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/ConfigureAuthorization.swift Sending event AuthEvent.authorizationConfigured 2022-12-19 11:00:09.735068+0100 iosApp[65648:2045686] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signedOut" = { lastKnownUserName = "(nil)"; }; "AuthorizationState.configured" = { }; }; } 2022-12-19 11:00:09.805350+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signedOut" = { lastKnownUserName = "(nil)"; }; "AuthorizationState.fetchingUnAuthSession" = { "FetchSessionState.notStarted" = { }; }; }; } 2022-12-19 11:00:09.805439+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeFetchUnAuthSession.swift Starting execution 2022-12-19 11:00:09.805488+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeFetchUnAuthSession.swift Sending event FetchAuthSessionEvent.throwError 2022-12-19 11:00:09.805843+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InformSessionError.swift Starting execution 2022-12-19 11:00:09.805889+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InformSessionError.swift Sending event AuthorizationEvent.receivedSessionError 2022-12-19 11:00:09.807211+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signedOut" = { lastKnownUserName = "(nil)"; }; "AuthorizationState.fetchingUnAuthSession" = { "FetchSessionState.error" = { error = "AWSCognitoAuthPlugin.FetchSessionError.noIdentityPool"; }; }; }; } 2022-12-19 11:00:09.808553+0100 iosApp[65648:2045684] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signedOut" = { lastKnownUserName = "(nil)"; }; "AuthorizationState.error" = { Error = "AWSCognitoAuthPlugin.AuthorizationError.sessionError(AWSCognitoAuthPlugin.FetchSessionError.noIdentityPool, noCredentials)"; }; }; } 2022-12-19 11:00:12.112559+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signedOut" = { lastKnownUserName = "(nil)"; }; "AuthorizationState.refreshingSession" = { existing = noCredentials; refreshState = { "RefreshSessionState.notStarted" = { }; }; }; }; } 2022-12-19 11:00:12.113301+0100 iosApp[65648:2045686] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeRefreshSession.swift Starting execution 2022-12-19 11:00:12.113612+0100 iosApp[65648:2045686] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeRefreshSession.swift Sending event RefreshSessionEvent.throwError 2022-12-19 11:00:12.114470+0100 iosApp[65648:2045686] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InformSessionError.swift Starting execution 2022-12-19 11:00:12.114569+0100 iosApp[65648:2045686] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InformSessionError.swift Sending event AuthorizationEvent.receivedSessionError 2022-12-19 11:00:12.114754+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signedOut" = { lastKnownUserName = "(nil)"; }; "AuthorizationState.refreshingSession" = { existing = noCredentials; refreshState = { "RefreshSessionState.error" = { error = "AWSCognitoAuthPlugin.FetchSessionError.noCredentialsToRefresh"; }; }; }; }; } 2022-12-19 11:00:12.115910+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signedOut" = { lastKnownUserName = "(nil)"; }; "AuthorizationState.error" = { Error = "AWSCognitoAuthPlugin.AuthorizationError.sessionError(AWSCognitoAuthPlugin.FetchSessionError.noCredentialsToRefresh, noCredentials)"; }; }; } 2022-12-19 11:00:15.100161+0100 iosApp[65648:2045686] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Starting execution 2022-12-19 11:00:15.100172+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] Credential Store state change: loadingStoredCredentials 2022-12-19 11:00:15.100833+0100 iosApp[65648:2045686] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Retreiving credential deviceMetadata(username: "+385915013359") 2022-12-19 11:00:15.111150+0100 iosApp[65648:2045686] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Sending event CredentialStoreEvent.throwError 2022-12-19 11:00:15.111290+0100 iosApp[65648:2045686] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution 2022-12-19 11:00:15.111294+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] Credential Store state change: error(KeychainStoreError: Unable to find the keychain item Recovery suggestion: This should not happen. There is a possibility that there is a bug if this error persists. Please take a look at https://github.com/aws-amplify/amplify-ios/issues to see if there are any existing issues that match your scenario, and file an issue with the details of the bug if there isn't. Issue encountered at: file: /Users/jurajbegovac/Library/Developer/Xcode/DerivedData/iosApp-ceumhqdilblatpbydusmyekmjbds/SourcePackages/checkouts/amplify-swift/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreError.swift function: recoverySuggestion line: 69) 2022-12-19 11:00:15.111367+0100 iosApp[65648:2045686] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState 2022-12-19 11:00:15.111444+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] Credential Store state change: idle 2022-12-19 11:00:15.111555+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Starting execution 2022-12-19 11:00:15.111566+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] Credential Store state change: loadingStoredCredentials 2022-12-19 11:00:15.111625+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Retreiving credential asfDeviceId(username: "+385915013359") 2022-12-19 11:00:15.114595+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Sending event CredentialStoreEvent.throwError 2022-12-19 11:00:15.114732+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution 2022-12-19 11:00:15.114745+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] Credential Store state change: error(KeychainStoreError: Unable to find the keychain item Recovery suggestion: This should not happen. There is a possibility that there is a bug if this error persists. Please take a look at https://github.com/aws-amplify/amplify-ios/issues to see if there are any existing issues that match your scenario, and file an issue with the details of the bug if there isn't. Issue encountered at: file: /Users/jurajbegovac/Library/Developer/Xcode/DerivedData/iosApp-ceumhqdilblatpbydusmyekmjbds/SourcePackages/checkouts/amplify-swift/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreError.swift function: recoverySuggestion line: 69) 2022-12-19 11:00:15.114769+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState 2022-12-19 11:00:15.114887+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Credential Store state change: idle 2022-12-19 11:00:15.114977+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/StoreCredentials.swift Starting execution 2022-12-19 11:00:15.114984+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Credential Store state change: storingCredentials 2022-12-19 11:00:15.123888+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/StoreCredentials.swift Sending event CredentialStoreEvent.completedOperation 2022-12-19 11:00:15.123992+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution 2022-12-19 11:00:15.124029+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState 2022-12-19 11:00:15.124692+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Credential Store state change: success(AWSCognitoAuthPlugin.CredentialStoreData.asfDeviceId("EE262985-A013-4B7B-8C7B-B064279C1EA7", "", "hostedUI": "N/A", "poolId": "eu-w****6K4O", "pinpointAppId": "(nil)", "clientSecret": "1a****b1", "endpoint": "N/A"]), userPoolConfigData: Optional(["clientId": "3c22****pc70", "region": "", "hostedUI": "N/A", "poolId": "eu-w****6K4O", "pinpointAppId": "(nil)", "clientSecret": "1a****b1", "endpoint": "N/A"]), identityPoolConfigData: nil, authenticationEnvironment: Optional(AWSCognitoAuthPlugin.BasicAuthenticationEnvironment(srpSignInEnvironment: AWSCognitoAuthPlugin.BasicSRPSignInEnvironment(srpAuthEnvironment: AWSCognitoAuthPlugin.BasicSRPAuthEnvironment(userPoolConfiguration: ["poolId": "eu-w****6K4O", "clientId": "3c22****pc70", "pinpointAppId": "(nil)", "endpoint": "N/A", "clientSecret": "1a****b1", "hostedUI": "N/A", "region": ""], cognitoUserPoolFactory: (Function), eventIDFactory: (Function), srpClientFactory: (Function), srpConfiguration: (nHexValue: "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF", gHexValue: "2"))), userPoolEnvironment: AWSCognitoAuthPlugin.BasicUserPoolEnvironment(userPoolConfiguration: ["pinpointAppId": "(nil)", "hostedUI": "N/A", "endpoint": "N/A", "poolId": "eu-w****6K4O", "clientId": "3c22****pc70", "region": "", "clientSecret": "1a****b1"], cognitoUserPoolFactory: (Function), cognitoUserPoolASFFactory: (Function), cognitoUserPoolAnalyticsHandlerFactory: (Function)), hostedUIEnvironment: nil)), authorizationEnvironment: nil, credentialsClient: AWSCognitoAuthPlugin.CredentialStoreOperationClient, logger: Amplify.OSLogWrapper) 2022-12-19 11:00:15.658558+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IntializeSignInFlow.swift Sending event SignInEvent.initiateCustomSignInWithSRP 2022-12-19 11:00:15.660118+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/StartSRPFlow.swift Start execution 2022-12-19 11:00:15.660172+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/StartSRPFlow.swift Sending event SignInEvent.initiateSignInWithSRP 2022-12-19 11:00:15.660233+0100 iosApp[65648:2045682] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signingIn" = { "SignInState.signingInWithSRPCustom" = { SRPSignInStaet = { "SRPSignInState.notStarted" = { }; }; }; }; "AuthorizationState.signingIn" = { }; }; } 2022-12-19 11:00:15.660394+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitiateAuthSRP.swift Starting execution 2022-12-19 11:00:15.661791+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signingIn" = { "SignInState.signingInWithSRPCustom" = { SRPSignInStaet = { "SRPSignInState.initiatingSRPA" = { clientMetadata = { }; password = ""; signInMethod = "AWSCognitoAuthPlugin.SignInMethod.apiBased(AWSCognitoAuthPlugin.AuthFlowType.customWithSRP)"; username = "+3*********59"; }; }; }; }; "AuthorizationState.signingIn" = { }; }; } 2022-12-19 11:00:15.665843+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Starting execution 2022-12-19 11:00:15.665860+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Credential Store state change: loadingStoredCredentials 2022-12-19 11:00:15.665920+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Retreiving credential deviceMetadata(username: "+385915013359") 2022-12-19 11:00:15.668747+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Sending event CredentialStoreEvent.throwError 2022-12-19 11:00:15.668828+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution 2022-12-19 11:00:15.668845+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Credential Store state change: error(KeychainStoreError: Unable to find the keychain item Recovery suggestion: This should not happen. There is a possibility that there is a bug if this error persists. Please take a look at https://github.com/aws-amplify/amplify-ios/issues to see if there are any existing issues that match your scenario, and file an issue with the details of the bug if there isn't. Issue encountered at: file: /Users/jurajbegovac/Library/Developer/Xcode/DerivedData/iosApp-ceumhqdilblatpbydusmyekmjbds/SourcePackages/checkouts/amplify-swift/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreError.swift function: recoverySuggestion line: 69) 2022-12-19 11:00:15.668871+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState 2022-12-19 11:00:15.668937+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Credential Store state change: idle 2022-12-19 11:00:15.668994+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Credential Store state change: loadingStoredCredentials 2022-12-19 11:00:15.669025+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Starting execution 2022-12-19 11:00:15.669091+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Retreiving credential asfDeviceId(username: "+385915013359") 2022-12-19 11:00:15.671394+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Sending event CredentialStoreEvent.completedOperation 2022-12-19 11:00:15.671474+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution 2022-12-19 11:00:15.671506+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Credential Store state change: success(AWSCognitoAuthPlugin.CredentialStoreData.asfDeviceId("EE262985-A013-4B7B-8C7B-B064279C1EA7", "+385915013359")) 2022-12-19 11:00:15.671511+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState 2022-12-19 11:00:15.671594+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Credential Store state change: idle 2022-12-19 11:00:15.673164+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitiateAuthSRP.swift Starting execution 2022-12-19T11:00:15+0100 info CognitoIdentityProviderClient : [Logging] Request: POST https:443 Path: / Content-Type: application/x-amz-json-1.1, x-amz-user-agent: aws-sdk-swift/1.0, User-Agent: aws-sdk-swift/1.0 api/cognito-identity-provider/1.0 os/iOS/16.1.0 lang/swift/5.7 lib/amplify-ios/2.2.0, Host: cognito-idp.eu-west-1.amazonaws.com, Content-Length: 6786, X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth Optional([]) 2022-12-19T11:00:15+0100 info SerialExecutor : [Logging] Creating connection pool for Optional("https://cognito-idp.eu-west-1.amazonaws.com/?")with max connections: 50 2022-12-19T11:00:16+0100 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-idp.eu-west-1.amazonaws.com/?") 2022-12-19T11:00:17+0100 info CRTClientEngine : [Logging] headers were received 2022-12-19T11:00:17+0100 info CRTClientEngine : [Logging] headers were received 2022-12-19T11:00:17+0100 info CRTClientEngine : [Logging] headers were received 2022-12-19T11:00:17+0100 info CRTClientEngine : [Logging] headers were received 2022-12-19T11:00:17+0100 info CRTClientEngine : [Logging] headers were received 2022-12-19T11:00:17+0100 info CRTClientEngine : [Logging] header block is done 2022-12-19T11:00:17+0100 info CRTClientEngine : [Logging] incoming data 2022-12-19T11:00:17+0100 info CRTClientEngine : [Logging] stream completed 2022-12-19 11:00:17.013544+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitiateAuthSRP.swift InitiateAuth response success 2022-12-19 11:00:17.017576+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitiateAuthSRP.swift Sending event SignInEvent(data: nil, id: "6B636947-5177-4E1B-AE6D-ADB0E9FFC248", eventType: AWSCognitoAuthPlugin.SignInEvent.EventType.receivedChallenge(AWSCognitoAuthPlugin.RespondToAuthChallenge(challenge: AWSCognitoIdentityProvider.CognitoIdentityProviderClientTypes.ChallengeNameType.customChallenge, username: "0e70e643-2534-4fb5-ba8d-3ca4e1c4c7e0", session: Optional("AYABeIUQp3iPtEZRsIYb8_37W44AHQABAAdTZXJ2aWNlABBDb2duaXRvVXNlclBvb2xzAAEAB2F3cy1rbXMAS2Fybjphd3M6a21zOmV1LXdlc3QtMTo0NTU0NTg0OTMwODE6a2V5L2FiN2U3M2UzLWU2NDEtNDk5Zi1iNzc0LWZkZmM1MWM3NzFhYQC4AQIBAHigzwqzlp0D8sA0ltw8SHdsZPaJakxa-4NzPukgGo7dmgFHfCwNuz6Qj-9fnXXX5p7AAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMakPGxsF_O5LKUpMKAgEQgDvdsMCZ9t-ZkdfRKGrTsMzWNO524kdrp1iqXjwr9w2Kl0di0I_JdCOi0jm10drChbs9gu8tWH5eBYyFzwIAAAAADAAAEAAAAAAAAAAAAAAAAABqXLY-bQ05dyTk7NBAWHCY_____wAAAAEAAAAAAAAAAAAAAAEAAAFCOlojgtepDGCNPhtofiBCzVQIDKA81lNR0pcmry4F8yRhWxIY8AllVYwAQB3-PmMq1YSjXYfKWMtLdTrQsvt564Xqo3RrKi4DIGsHkWBg-1kqrHIpy1Ay22h0Rs-D4DXW0bHPVQ4FM1wPgB_23a33MRv3ei_zqytytFc3WdlV5P-f5KYcsTlF15tcuVUXNNLEYUq9yzRXbKCb1nUy5GXuAXPryfgQNGutSvmHFlKeprZdJHh7mmzWe8JCMsWVXV17EH6kD7FbGoISeMyD_hnXB8D7ziA5TP66p0s3YzWBHHmokcaCWh9tBxotF-bwsI-QWS34yWI0MFJBlVodDA63qSuckxoa7lSl6Vo6zhIEMQzhIFkLeto4nBy6UKo13ahSMy8L0R3XPg1aOoQ99lZL30b-0TmRrUZSoLLGEHkdW1_3e-IHOF1F_4fvWanItoLQQKc"), parameters: Optional(["USERNAME": "0e70e643-2534-4fb5-ba8d-3ca4e1c4c7e0"]))), time: nil) 2022-12-19T11:00:17+0100 info SerialExecutor : [Logging] Connection to endpoint: Optional("https://cognito-idp.eu-west-1.amazonaws.com/?") is closing 2022-12-19 11:00:17.018630+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeResolveChallenge.swift Starting execution 2022-12-19 11:00:17.018701+0100 iosApp[65648:2045681] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeResolveChallenge.swift Sending event SignInChallengeEvent.waitForAnswer 2022-12-19 11:00:17.019774+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signingIn" = { "SignInState.resolvingChallenge" = { "SignInChallengeState.notStarted" = { }; challengeType = "AWSCognitoAuthPlugin.AuthChallengeType.customChallenge"; signInMethod = "AWSCognitoAuthPlugin.SignInMethod.apiBased(AWSCognitoAuthPlugin.AuthFlowType.customWithSRP)"; }; }; "AuthorizationState.signingIn" = { }; }; } 2022-12-19 11:00:17.020384+0100 iosApp[65648:2045683] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signingIn" = { "SignInState.resolvingChallenge" = { "SignInChallengeState.waitingForAnswer" = { challenge = "AWSCognitoIdentityProvider.CognitoIdentityProviderClientTypes.ChallengeNameType.customChallenge"; username = "0e********************************e0"; }; challengeType = "AWSCognitoAuthPlugin.AuthChallengeType.customChallenge"; signInMethod = "AWSCognitoAuthPlugin.SignInMethod.apiBased(AWSCognitoAuthPlugin.AuthFlowType.customWithSRP)"; }; }; "AuthorizationState.signingIn" = { }; }; } SignInResult: com.wesports.data.common.aws.SignInResult.WaitForCredentialConfirmation@2520a50 // This is my custom log ```
royjit commented 1 year ago

Thank you for the logs, @JurajBegovac this gives us more insight into the internals now. Looks like the auth plugin is waiting for confirm signIn api call to be invoked to continue the custom auth flow. Are you invoking Amplify.Auth.confirmSignIn in your flow?

patrickjohnson97 commented 1 year ago

Speaking for myself, I have the same logs and I am indeed invoking the confirmSignIn method with withSRP strategy (my custom lambda handles the SRP_A attribute). I have tried withoutSRP and updating my Define Auth Challenge lambda to match the example in the Amplify docs, but I am still facing this same issue.

phantumcode commented 1 year ago

Can you retry and test with the latest Amplify version 2.2.1

patrickjohnson97 commented 1 year ago

It is still not working after pulling in the new Amplify version. I was poking around today trying to see if I could get anything to work and I deleted the user I was trying to sign in with and created a new user with the same phone number. This may be unrelated, but I witnessed new behavior that I had not seen since the last version of Amplify I had (1.5X). I called .signUp, then .confirmSignUp with the confirmation code, and that was successful (yay!). However, then I saw these logs:

Confirm signUp succeeded
2022-12-21 09:00:18.117938-0800 radarios[24248:4410762] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeRefreshSession.swift Starting execution
2022-12-21 09:00:18.117990-0800 radarios[24248:4410762] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeRefreshSession.swift Sending event RefreshSessionEvent.throwError
2022-12-21 09:00:18.118224-0800 radarios[24248:4411353] [AWSCognitoAuthPlugin] Auth state change:

{
    "AuthState.configured" =     {
        "AuthenticationState.signedOut" =         {
            lastKnownUserName = "(nil)";
        };
        "AuthorizationState.refreshingSession" =         {
            existing = noCredentials;
            refreshState =             {
                "RefreshSessionState.notStarted" =                 {
                };
            };
        };
    };
}
2022-12-21 09:00:18.118367-0800 radarios[24248:4410762] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InformSessionError.swift Starting execution
2022-12-21 09:00:18.118391-0800 radarios[24248:4410762] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InformSessionError.swift Sending event AuthorizationEvent.receivedSessionError
2022-12-21 09:00:18.118409-0800 radarios[24248:4411353] [AWSCognitoAuthPlugin] Auth state change:

{
    "AuthState.configured" =     {
        "AuthenticationState.signedOut" =         {
            lastKnownUserName = "(nil)";
        };
        "AuthorizationState.refreshingSession" =         {
            existing = noCredentials;
            refreshState =             {
                "RefreshSessionState.error" =                 {
                    error = "AWSCognitoAuthPlugin.FetchSessionError.noCredentialsToRefresh";
                };
            };
        };
    };
}
2022-12-21 09:00:18.118592-0800 radarios[24248:4411353] [AWSCognitoAuthPlugin] Auth state change:

{
    "AuthState.configured" =     {
        "AuthenticationState.signedOut" =         {
            lastKnownUserName = "(nil)";
        };
        "AuthorizationState.error" =         {
            Error = "AWSCognitoAuthPlugin.AuthorizationError.sessionError(AWSCognitoAuthPlugin.FetchSessionError.noCredentialsToRefresh, noCredentials)";
        };
    };
}
AuthError: There is no user signed in to retreive cognito tokens
Recovery suggestion: Call Auth.signIn to sign in a user and then call Auth.fetchSession

When I relaunched my app - I was no longer signed in (thus having to go back through the broken sign in flow again, sigh). Hopefully this information is relevant to the case.

patrickjohnson97 commented 1 year ago

I know it's the holiday season, so I'm not expecting much progress on this right now. However, I do see this was marked as pending response from requester. As I am not the requester but I am affected by the same issue, should I reopen a new ticket or can we keep this open to continue tracking this issue?

royjit commented 1 year ago

Hi @patrickjohnson97

Invoking Amplify.Auth.signUp does not automatically signIn the user. You need to invoke Amplify.Auth.signIn and check its result, if the result next step is .done (result.nextStep == .done) the user is authenticated. If it is not .done you need to invoke subsequent api as mentioned here - https://docs.amplify.aws/lib/auth/signin_next_steps/q/platform/ios

Once the user is authenticated your can call other apis like Amplify.Auth.fetchAuthsession to get authenticated credentials.

From your logs it is not clear regarding what response you are getting when you invoke Amplify.Auth.signIn.

As I am not the requester but I am affected by the same issue, should I reopen a new ticket or can we keep this open to continue tracking this issue?

We are still trying to figure out if your issue is same as the requester's, for now we can keep this GitHub issue assuming that they are the same. @JurajBegovac are you still facing the same issue with the latest Amplify swift release?

patrickjohnson97 commented 1 year ago

@royjit Just to clarify - I am still seeing the aforementioned hanging confirm sign in process. Here is every log I have for the entire auth process (starting immediately after I press the "Sign in" button on my app:

Signing in with radar...
2022-12-30 14:05:47.951377-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IntializeSignInFlow.swift Starting execution
2022-12-30 14:05:47.951437-0800 radarios[6472:2019048] [AWSCognitoAuthPlugin] Credential Store state change:

loadingStoredCredentials
2022-12-30 14:05:47.951457-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Starting execution
2022-12-30 14:05:47.951483-0800 radarios[6472:2019042] [AWSCognitoAuthPlugin] Auth state change:

{
    "AuthState.configured" =     {
        "AuthenticationState.signingIn" =         {
            "SignInState.notStarted" =             {
            };
        };
        "AuthorizationState.signingIn" =         {
        };
    };
}
2022-12-30 14:05:47.952248-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Retreiving credential deviceMetadata(username: "<REDACTED>")
2022-12-30 14:05:47.958872-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Sending event CredentialStoreEvent.throwError
2022-12-30 14:05:47.958907-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution
2022-12-30 14:05:47.958914-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState
2022-12-30 14:05:47.959278-0800 radarios[6472:2019042] [AWSCognitoAuthPlugin] Credential Store state change:

error(KeychainStoreError: Unable to find the keychain item
Recovery suggestion: This should not happen. There is a possibility that there is a bug if this error persists. Please take a look at https://github.com/aws-amplify/amplify-ios/issues to see if there are any existing issues that match your scenario, and file an issue with the details of the bug if there isn't. Issue encountered at:
file: /Users/patrickjohnson/Library/Developer/Xcode/DerivedData/radarios-dknagqfhvptgcvcevboslsbwdhqv/SourcePackages/checkouts/amplify-swift/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreError.swift
function: recoverySuggestion
line: 69)
2022-12-30 14:05:47.959298-0800 radarios[6472:2019042] [AWSCognitoAuthPlugin] Credential Store state change:

idle
2022-12-30 14:05:47.973842-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] No existing device metadata found. AuthEnvironment(configuration: AWSCognitoAuthPlugin.AuthConfiguration.userPoolsAndIdentityPools(["clientId": "6num****35nf", "poolId": "us-w****54x6", "clientSecret": "(nil)", "region": "<REDACTED>", "hostedUI": "[\"clientId\": \"6num****35nf\", \"clientSecret\": \"(nil)\", \"oauth\": \"[\\\"domain\\\": \\\"rada****.com\\\", \\\"signInRedirectURI\\\": \\\"rada***s://\\\", \\\"signOutRedirectURI\\\": \\\"rada***s://\\\"]\"]", "pinpointAppId": "(nil)", "endpoint": "N/A"], ["region": "<REDACTED>", "poolId": "us-w****9f49"]), userPoolConfigData: Optional(["clientId": "6num****35nf", "poolId": "us-w****54x6", "clientSecret": "(nil)", "region": "<REDACTED>", "hostedUI": "[\"clientId\": \"6num****35nf\", \"clientSecret\": \"(nil)\", \"oauth\": \"[\\\"domain\\\": \\\"rada****.com\\\", \\\"signInRedirectURI\\\": \\\"rada***s://\\\", \\\"signOutRedirectURI\\\": \\\"rada***s://\\\"]\"]", "pinpointAppId": "(nil)", "endpoint": "N/A"]), identityPoolConfigData: Optional(["region": "<REDACTED>", "poolId": "us-w****9f49"]), authenticationEnvironment: Optional(AWSCognitoAuthPlugin.BasicAuthenticationEnvironment(srpSignInEnvironment: AWSCognitoAuthPlugin.BasicSRPSignInEnvironment(srpAuthEnvironment: AWSCognitoAuthPlugin.BasicSRPAuthEnvironment(userPoolConfiguration: ["endpoint": "N/A", "poolId": "us-w****54x6", "pinpointAppId": "(nil)", "region": "<REDACTED>", "clientSecret": "(nil)", "clientId": "6num****35nf", "hostedUI": "[\"oauth\": \"[\\\"signInRedirectURI\\\": \\\"rada***s://\\\", \\\"domain\\\": \\\"rada****.com\\\", \\\"signOutRedirectURI\\\": \\\"rada***s://\\\"]\", \"clientId\": \"6num****35nf\", \"clientSecret\": \"(nil)\"]"], cognitoUserPoolFactory: (Function), eventIDFactory: (Function), srpClientFactory: (Function), srpConfiguration: (nHexValue: "<REDACTED>", gHexValue: "2"))), userPoolEnvironment: AWSCognitoAuthPlugin.BasicUserPoolEnvironment(userPoolConfiguration: ["clientId": "6num****35nf", "poolId": "us-w****54x6", "clientSecret": "(nil)", "region": "<REDACTED>", "hostedUI": "[\"clientId\": \"6num****35nf\", \"clientSecret\": \"(nil)\", \"oauth\": \"[\\\"domain\\\": \\\"rada****.com\\\", \\\"signInRedirectURI\\\": \\\"rada***s://\\\", \\\"signOutRedirectURI\\\": \\\"rada***s://\\\"]\"]", "pinpointAppId": "(nil)", "endpoint": "N/A"], cognitoUserPoolFactory: (Function), cognitoUserPoolASFFactory: (Function), cognitoUserPoolAnalyticsHandlerFactory: (Function)), hostedUIEnvironment: Optional(AWSCognitoAuthPlugin.BasicHostedUIEnvironment(configuration: ["clientId": "6num****35nf", "clientSecret": "(nil)", "oauth": "[\"domain\": \"rada****.com\", \"signInRedirectURI\": \"rada***s://\", \"signOutRedirectURI\": \"rada***s://\"]"], hostedUISessionFactory: (Function), urlSessionFactory: (Function), randomStringFactory: (Function))))), authorizationEnvironment: Optional(AWSCognitoAuthPlugin.BasicAuthorizationEnvironment(identityPoolConfiguration: ["region": "<REDACTED>", "poolId": "us-w****9f49"], cognitoIdentityFactory: (Function), eventIDFactory: (Function))), credentialsClient: AWSCognitoAuthPlugin.CredentialStoreOperationClient, logger: Amplify.OSLogWrapper)
2022-12-30 14:05:47.974516-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IntializeSignInFlow.swift Sending event SignInEvent.initiateCustomSignInWithSRP
2022-12-30 14:05:47.975745-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/StartSRPFlow.swift Start execution
2022-12-30 14:05:47.975754-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/StartSRPFlow.swift Sending event SignInEvent.initiateSignInWithSRP
2022-12-30 14:05:47.975779-0800 radarios[6472:2019042] [AWSCognitoAuthPlugin] Auth state change:

{
    "AuthState.configured" =     {
        "AuthenticationState.signingIn" =         {
            "SignInState.signingInWithSRPCustom" =             {
                SRPSignInStaet =                 {
                    "SRPSignInState.notStarted" =                     {
                    };
                };
            };
        };
        "AuthorizationState.signingIn" =         {
        };
    };
}
2022-12-30 14:05:47.975862-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitiateAuthSRP.swift Starting execution
2022-12-30 14:05:47.977267-0800 radarios[6472:2019048] [AWSCognitoAuthPlugin] Auth state change:

{
    "AuthState.configured" =     {
        "AuthenticationState.signingIn" =         {
            "SignInState.signingInWithSRPCustom" =             {
                SRPSignInStaet =                 {
                    "SRPSignInState.initiatingSRPA" =                     {
                        clientMetadata =                         {
                        };
                        password = "(nil)";
                        signInMethod = "AWSCognitoAuthPlugin.SignInMethod.apiBased(AWSCognitoAuthPlugin.AuthFlowType.customWithSRP)";
                        username = "+1********58";
                    };
                };
            };
        };
        "AuthorizationState.signingIn" =         {
        };
    };
}
2022-12-30 14:05:47.979477-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Starting execution
2022-12-30 14:05:47.979484-0800 radarios[6472:2019048] [AWSCognitoAuthPlugin] Credential Store state change:

loadingStoredCredentials
2022-12-30 14:05:47.979496-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Retreiving credential deviceMetadata(username: "<REDACTED>")
2022-12-30 14:05:47.981078-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Sending event CredentialStoreEvent.throwError
2022-12-30 14:05:47.981099-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution
2022-12-30 14:05:47.981105-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState
2022-12-30 14:05:47.981118-0800 radarios[6472:2019042] [AWSCognitoAuthPlugin] Credential Store state change:

error(KeychainStoreError: Unable to find the keychain item
Recovery suggestion: This should not happen. There is a possibility that there is a bug if this error persists. Please take a look at https://github.com/aws-amplify/amplify-ios/issues to see if there are any existing issues that match your scenario, and file an issue with the details of the bug if there isn't. Issue encountered at:
file: /Users/patrickjohnson/Library/Developer/Xcode/DerivedData/radarios-dknagqfhvptgcvcevboslsbwdhqv/SourcePackages/checkouts/amplify-swift/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreError.swift
function: recoverySuggestion
line: 69)
2022-12-30 14:05:47.981130-0800 radarios[6472:2019042] [AWSCognitoAuthPlugin] Credential Store state change:

idle
2022-12-30 14:05:47.981134-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Starting execution
2022-12-30 14:05:47.981139-0800 radarios[6472:2019042] [AWSCognitoAuthPlugin] Credential Store state change:

loadingStoredCredentials
2022-12-30 14:05:47.981147-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Retreiving credential asfDeviceId(username: "+14053651058")
2022-12-30 14:05:47.982697-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Sending event CredentialStoreEvent.completedOperation
2022-12-30 14:05:47.982719-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution
2022-12-30 14:05:47.982725-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState
2022-12-30 14:05:47.983648-0800 radarios[6472:2019048] [AWSCognitoAuthPlugin] Credential Store state change:

success(AWSCognitoAuthPlugin.CredentialStoreData.asfDeviceId("<REDACTED>", "<REDACTED>"))
2022-12-30 14:05:47.983665-0800 radarios[6472:2019048] [AWSCognitoAuthPlugin] Credential Store state change:

idle
2022-12-30 14:05:47.985732-0800 radarios[6472:2019045] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitiateAuthSRP.swift Starting execution
2022-12-30T14:05:47-0800 info CognitoIdentityProviderClient : [Logging] Request: POST https:443 
 Path: / 
 Host: cognito-idp.us-west-2.amazonaws.com, 
User-Agent: aws-sdk-swift/1.0 api/cognito-identity-provider/1.0 os/iOS/16.2.0 lang/swift/5.7 lib/amplify-ios/2.2.1, 
X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth, 
Content-Type: application/x-amz-json-1.1, 
x-amz-user-agent: aws-sdk-swift/1.0, 
Content-Length: 6632 
 Optional([])
2022-12-30T14:05:47-0800 info SerialExecutor : [Logging] Creating connection pool for Optional("https://cognito-idp.us-west-2.amazonaws.com/?")with max connections: 50
2022-12-30T14:05:48-0800 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-idp.us-west-2.amazonaws.com/?")
2022-12-30T14:05:49-0800 info CRTClientEngine : [Logging] headers were received
2022-12-30T14:05:49-0800 info CRTClientEngine : [Logging] headers were received
2022-12-30T14:05:49-0800 info CRTClientEngine : [Logging] headers were received
2022-12-30T14:05:49-0800 info CRTClientEngine : [Logging] headers were received
2022-12-30T14:05:49-0800 info CRTClientEngine : [Logging] headers were received
2022-12-30T14:05:49-0800 info CRTClientEngine : [Logging] header block is done
2022-12-30T14:05:49-0800 info CRTClientEngine : [Logging] incoming data
2022-12-30T14:05:49-0800 info CRTClientEngine : [Logging] stream completed
2022-12-30 14:05:49.340789-0800 radarios[6472:2019048] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitiateAuthSRP.swift InitiateAuth response success
2022-12-30T14:05:49-0800 info SerialExecutor : [Logging] Connection to endpoint: Optional("https://cognito-idp.us-west-2.amazonaws.com/?") is closing
2022-12-30 14:05:49.351703-0800 radarios[6472:2019048] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitiateAuthSRP.swift Sending event SignInEvent(data: nil, id: "703A1D8E-2560-4A03-B144-CB387B13DFA5", eventType: AWSCognitoAuthPlugin.SignInEvent.EventType.receivedChallenge(AWSCognitoAuthPlugin.RespondToAuthChallenge(challenge: AWSCognitoIdentityProvider.CognitoIdentityProviderClientTypes.ChallengeNameType.customChallenge, username: "<REDACTED>", session: Optional("<REDACTED>"), parameters: Optional(["USERNAME": "<REDACTED>"]))), time: nil)
2022-12-30 14:05:49.352453-0800 radarios[6472:2019048] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeResolveChallenge.swift Starting execution
2022-12-30 14:05:49.352603-0800 radarios[6472:2019048] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeResolveChallenge.swift Sending event SignInChallengeEvent.waitForAnswer
GGGG confirmSignInWithCustomChallenge2022-12-30 14:05:49.355480-0800 radarios[6472:2019042] [AWSCognitoAuthPlugin] Auth state change:

{
    "AuthState.configured" =     {
        "AuthenticationState.signingIn" =         {
            "SignInState.resolvingChallenge" =             {
                "SignInChallengeState.notStarted" =                 {
                };
                challengeType = "AWSCognitoAuthPlugin.AuthChallengeType.customChallenge";
                signInMethod = "AWSCognitoAuthPlugin.SignInMethod.apiBased(AWSCognitoAuthPlugin.AuthFlowType.customWithSRP)";
            };
        };
        "AuthorizationState.signingIn" =         {
        };
    };
}

2022-12-30 14:05:49.356672-0800 radarios[6472:2019042] [AWSCognitoAuthPlugin] Auth state change:

{
    "AuthState.configured" =     {
        "AuthenticationState.signingIn" =         {
            "SignInState.resolvingChallenge" =             {
                "SignInChallengeState.waitingForAnswer" =                 {
                    challenge = "AWSCognitoIdentityProvider.CognitoIdentityProviderClientTypes.ChallengeNameType.customChallenge";
                    username = "45********************************b0";
                };
                challengeType = "AWSCognitoAuthPlugin.AuthChallengeType.customChallenge";
                signInMethod = "AWSCognitoAuthPlugin.SignInMethod.apiBased(AWSCognitoAuthPlugin.AuthFlowType.customWithSRP)";
            };
        };
        "AuthorizationState.signingIn" =         {
        };
    };
}
Confirming user... 895533

After this last log (which includes the OTP I am sending back), there are no more logs for any other operation I try to perform with Amplify.Auth. Any fetchAuthSession calls, sign in calls, everything is just unresponsive.

royjit commented 1 year ago

Thank you for the patience while we try to narrow down the root cause of this issue. We are still trying to reproduce this behavior, from my testing this is what I found:

  1. I could not reproduce the issue where calling Amplify.Auth.confirmSignIn is getting stuck.
  2. But I found an issue where fetchAuthSession get stuck and all subsequent calls to Auth when a signIn is in progress.

Here is my branch royjit.fixfetchAuthSession that I am currently working on to fix this, and the PR https://github.com/aws-amplify/amplify-swift/pull/2653. Will you able to try the signIn flow with this branch?

For custom auth I used the following define auth lambda trigger:

Define auth lambda ``` if (event.request.session.length === 1 && event.request.session[0].challengeName === 'SRP_A') { event.response.issueTokens = false; event.response.failAuthentication = false; event.response.challengeName = 'CUSTOM_CHALLENGE'; } else if ( event.request.session.length === 2 && event.request.session[1].challengeName === 'CUSTOM_CHALLENGE' && event.request.session[1].challengeResult === true ) { event.response.issueTokens = true; event.response.failAuthentication = false; } else { event.response.issueTokens = false; event.response.failAuthentication = true; } ```

And my logs are here:

Log Messages for signIn ``` 2023-01-03 20:27:46.264967-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IntializeSignInFlow.swift Starting execution 2023-01-03 20:27:46.265190-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Starting execution 2023-01-03 20:27:46.265503-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signingIn" = { "SignInState.notStarted" = { }; }; "AuthorizationState.signingIn" = { }; }; } 2023-01-03 20:27:46.265838-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Credential Store state change: loadingStoredCredentials 2023-01-03 20:27:46.266146-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Retreiving credential deviceMetadata(username: "xxx@xx.com") 2023-01-03 20:27:46.270537-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Sending event CredentialStoreEvent.throwError 2023-01-03 20:27:46.270832-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Credential Store state change: error(KeychainStoreError: Unable to find the keychain item Recovery suggestion: This should not happen. There is a possibility that there is a bug if this error persists. Please take a look at https://github.com/aws-amplify/amplify-ios/issues to see if there are any existing issues that match your scenario, and file an issue with the details of the bug if there isn't. Issue encountered at: file: /Users/royji/work/iOS/amplify-swift/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreError.swift function: recoverySuggestion line: 69) 2023-01-03 20:27:46.270811-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution 2023-01-03 20:27:46.270931-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState 2023-01-03 20:27:46.271078-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Credential Store state change: idle 2023-01-03 20:27:46.279436-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] No existing device metadata found. AuthEnvironment(configuration: AWSCognitoAuthPlugin.AuthConfiguration.userPoolsAndIdentityPools(["hostedUI": "N/A", "poolId": "us-e****Amot", "endpoint": "N/A", "region": "", "clientSecret": "(nil)", "pinpointAppId": "(nil)", "clientId": "xxx"], ["poolId": "xxx", "region": ""]), userPoolConfigData: Optional(["hostedUI": "N/A", "poolId": "us-e****Amot", "endpoint": "N/A", "region": "", "clientSecret": "(nil)", "pinpointAppId": "(nil)", "clientId": "xxx"]), identityPoolConfigData: Optional(["poolId": "xxx", "region": ""]), authenticationEnvironment: Optional(AWSCognitoAuthPlugin.BasicAuthenticationEnvironment(srpSignInEnvironment: AWSCognitoAuthPlugin.BasicSRPSignInEnvironment(srpAuthEnvironment: AWSCognitoAuthPlugin.BasicSRPAuthEnvironment(userPoolConfiguration: ["poolId": "us-e****Amot", "region": "", "endpoint": "N/A", "clientId": "xxx", "pinpointAppId": "(nil)", "clientSecret": "(nil)", "hostedUI": "N/A"], cognitoUserPoolFactory: (Function), eventIDFactory: (Function), srpClientFactory: (Function), srpConfiguration: (nHexValue: "xxx", gHexValue: "2"))), userPoolEnvironment: AWSCognitoAuthPlugin.BasicUserPoolEnvironment(userPoolConfiguration: ["endpoint": "N/A", "hostedUI": "N/A", "region": "", "clientId": "xxx", "pinpointAppId": "(nil)", "clientSecret": "(nil)", "poolId": "us-e****Amot"], cognitoUserPoolFactory: (Function), cognitoUserPoolASFFactory: (Function), cognitoUserPoolAnalyticsHandlerFactory: (Function)), hostedUIEnvironment: nil)), authorizationEnvironment: Optional(AWSCognitoAuthPlugin.BasicAuthorizationEnvironment(identityPoolConfiguration: ["region": "", "poolId": "xxx"], cognitoIdentityFactory: (Function), eventIDFactory: (Function))), credentialsClient: AWSCognitoAuthPlugin.CredentialStoreOperationClient, logger: Amplify.OSLogWrapper) 2023-01-03 20:27:46.280342-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IntializeSignInFlow.swift Sending event SignInEvent.initiateCustomSignInWithSRP 2023-01-03 20:27:46.281047-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/StartSRPFlow.swift Start execution 2023-01-03 20:27:46.281132-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signingIn" = { "SignInState.signingInWithSRPCustom" = { SRPSignInStaet = { "SRPSignInState.notStarted" = { }; }; }; }; "AuthorizationState.signingIn" = { }; }; } 2023-01-03 20:27:46.281153-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/StartSRPFlow.swift Sending event SignInEvent.initiateSignInWithSRP 2023-01-03 20:27:46.281399-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitiateAuthSRP.swift Starting execution 2023-01-03 20:27:46.282432-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signingIn" = { "SignInState.signingInWithSRPCustom" = { SRPSignInStaet = { "SRPSignInState.initiatingSRPA" = { clientMetadata = { }; password = ""; signInMethod = "AWSCognitoAuthPlugin.SignInMethod.apiBased(AWSCognitoAuthPlugin.AuthFlowType.customWithSRP)"; username = "xxx@xx.com"; }; }; }; }; "AuthorizationState.signingIn" = { }; }; } 2023-01-03 20:27:46.286757-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Starting execution 2023-01-03 20:27:46.286767-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Credential Store state change: loadingStoredCredentials 2023-01-03 20:27:46.286866-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Retreiving credential deviceMetadata(username: "xxx@xx.com") 2023-01-03 20:27:46.288962-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Sending event CredentialStoreEvent.throwError 2023-01-03 20:27:46.289038-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Credential Store state change: error(KeychainStoreError: Unable to find the keychain item Recovery suggestion: This should not happen. There is a possibility that there is a bug if this error persists. Please take a look at https://github.com/aws-amplify/amplify-ios/issues to see if there are any existing issues that match your scenario, and file an issue with the details of the bug if there isn't. Issue encountered at: file: /Users/royji/work/iOS/amplify-swift/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreError.swift function: recoverySuggestion line: 69) 2023-01-03 20:27:46.289038-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution 2023-01-03 20:27:46.289070-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState 2023-01-03 20:27:46.289147-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Credential Store state change: idle 2023-01-03 20:27:46.289212-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Credential Store state change: loadingStoredCredentials 2023-01-03 20:27:46.289171-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Starting execution 2023-01-03 20:27:46.289258-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Retreiving credential asfDeviceId(username: "xxx@xx.com") 2023-01-03 20:27:46.291179-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/LoadCredentialStore.swift Sending event CredentialStoreEvent.completedOperation 2023-01-03 20:27:46.291248-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Starting execution 2023-01-03 20:27:46.291300-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/IdleCredentialStore.swift Sending event CredentialStoreEvent.moveToIdleState 2023-01-03 20:27:46.291857-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Credential Store state change: success(AWSCognitoAuthPlugin.CredentialStoreData.asfDeviceId("1F0AE0A5-1DD8-4CA4-8464-C40C90F3BF45", "xxx@xx.com")) 2023-01-03 20:27:46.291897-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Credential Store state change: idle 2023-01-03 20:27:46.296803-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitiateAuthSRP.swift Starting execution 2023-01-03T20:27:46-0800 info CognitoIdentityProviderClient : [Logging] Request: POST https:443 Path: / Content-Length: 6749, Host: cognito-idp.us-east-1.amazonaws.com, Content-Type: application/x-amz-json-1.1, X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth, User-Agent: aws-sdk-swift/1.0 api/cognito-identity-provider/1.0 os/iOS/16.2.0 lang/swift/5.7 lib/amplify-ios/2.2.1, x-amz-user-agent: aws-sdk-swift/1.0 Optional([]) 2023-01-03T20:27:46-0800 info SerialExecutor : [Logging] Creating connection pool for Optional("https://cognito-idp.us-east-1.amazonaws.com/?")with max connections: 50 2023-01-03T20:27:46-0800 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-idp.us-east-1.amazonaws.com/?") 2023-01-03T20:27:47-0800 info CRTClientEngine : [Logging] headers were received 2023-01-03T20:27:47-0800 info CRTClientEngine : [Logging] headers were received 2023-01-03T20:27:47-0800 info CRTClientEngine : [Logging] headers were received 2023-01-03T20:27:47-0800 info CRTClientEngine : [Logging] headers were received 2023-01-03T20:27:47-0800 info CRTClientEngine : [Logging] headers were received 2023-01-03T20:27:47-0800 info CRTClientEngine : [Logging] header block is done 2023-01-03T20:27:47-0800 info CRTClientEngine : [Logging] incoming data 2023-01-03T20:27:47-0800 info CRTClientEngine : [Logging] stream completed 2023-01-03 20:27:47.873586-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitiateAuthSRP.swift InitiateAuth response success 2023-01-03 20:27:47.875040-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitiateAuthSRP.swift Sending event SignInEvent(data: nil, id: "D6B16423-131D-4A15-9E5C-083C59A36CE0", eventType: AWSCognitoAuthPlugin.SignInEvent.EventType.receivedChallenge(AWSCognitoAuthPlugin.RespondToAuthChallenge(challenge: AWSCognitoIdentityProvider.CognitoIdentityProviderClientTypes.ChallengeNameType.customChallenge, username: "xxx@xx.com", session: Optional("xxxx"), parameters: Optional(["USERNAME": "xxx@xx.com", "trigger": "true"]))), time: nil) 2023-01-03T20:27:47-0800 info SerialExecutor : [Logging] Connection to endpoint: Optional("https://cognito-idp.us-east-1.amazonaws.com/?") is closing 2023-01-03 20:27:47.875433-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeResolveChallenge.swift Starting execution 2023-01-03 20:27:47.875476-0800 AmplifyAuthSample[38816:428902] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/InitializeResolveChallenge.swift Sending event SignInChallengeEvent.waitForAnswer 2023-01-03 20:27:47.875814-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signingIn" = { "SignInState.resolvingChallenge" = { "SignInChallengeState.notStarted" = { }; challengeType = "AWSCognitoAuthPlugin.AuthChallengeType.customChallenge"; signInMethod = "AWSCognitoAuthPlugin.SignInMethod.apiBased(AWSCognitoAuthPlugin.AuthFlowType.customWithSRP)"; }; }; "AuthorizationState.signingIn" = { }; }; } 2023-01-03 20:27:47.876035-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signingIn" = { "SignInState.resolvingChallenge" = { "SignInChallengeState.waitingForAnswer" = { challenge = "AWSCognitoIdentityProvider.CognitoIdentityProviderClientTypes.ChallengeNameType.customChallenge"; username = "xxx@xx.com"; }; challengeType = "AWSCognitoAuthPlugin.AuthChallengeType.customChallenge"; signInMethod = "AWSCognitoAuthPlugin.SignInMethod.apiBased(AWSCognitoAuthPlugin.AuthFlowType.customWithSRP)"; }; }; "AuthorizationState.signingIn" = { }; }; } VC signIn: Result = AuthSignInResult(nextStep: Amplify.AuthSignInStep.confirmSignInWithCustomChallenge(Optional(["USERNAME": "xxx@xx.com", "trigger": "true"]))) 2023-01-03 20:27:50.848391-0800 AmplifyAuthSample[38816:428906] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/VerifySignInChallenge.swift Starting execution 2023-01-03 20:27:50.850362-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signingIn" = { "SignInState.resolvingChallenge" = { "SignInChallengeState.verifying" = { challenge = "AWSCognitoIdentityProvider.CognitoIdentityProviderClientTypes.ChallengeNameType.customChallenge"; username = "xxx@xx.com"; }; challengeType = "AWSCognitoAuthPlugin.AuthChallengeType.customChallenge"; signInMethod = "AWSCognitoAuthPlugin.SignInMethod.apiBased(AWSCognitoAuthPlugin.AuthFlowType.customWithSRP)"; }; }; "AuthorizationState.signingIn" = { }; }; } 2023-01-03T20:27:50-0800 info CognitoIdentityProviderClient : [Logging] Request: POST https:443 Path: / User-Agent: aws-sdk-swift/1.0 api/cognito-identity-provider/1.0 os/iOS/16.2.0 lang/swift/5.7 lib/amplify-ios/2.2.1, Host: cognito-idp.us-east-1.amazonaws.com, Content-Length: 1099, x-amz-user-agent: aws-sdk-swift/1.0, X-Amz-Target: AWSCognitoIdentityProviderService.RespondToAuthChallenge, Content-Type: application/x-amz-json-1.1 Optional([]) 2023-01-03T20:27:50-0800 info SerialExecutor : [Logging] Creating connection pool for Optional("https://cognito-idp.us-east-1.amazonaws.com/?")with max connections: 50 2023-01-03T20:27:51-0800 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-idp.us-east-1.amazonaws.com/?") 2023-01-03T20:27:51-0800 info CRTClientEngine : [Logging] headers were received 2023-01-03T20:27:51-0800 info CRTClientEngine : [Logging] headers were received 2023-01-03T20:27:51-0800 info CRTClientEngine : [Logging] headers were received 2023-01-03T20:27:51-0800 info CRTClientEngine : [Logging] headers were received 2023-01-03T20:27:51-0800 info CRTClientEngine : [Logging] headers were received 2023-01-03T20:27:51-0800 info CRTClientEngine : [Logging] headers were received 2023-01-03T20:27:51-0800 info CRTClientEngine : [Logging] headers were received 2023-01-03T20:27:51-0800 info CRTClientEngine : [Logging] header block is done 2023-01-03T20:27:51-0800 info CRTClientEngine : [Logging] incoming data 2023-01-03T20:27:51-0800 info CRTClientEngine : [Logging] stream completed 2023-01-03 20:27:51.945814-0800 AmplifyAuthSample[38816:428906] [AWSCognitoAuthPlugin] AWSCognitoAuthPlugin/VerifySignInChallenge.swift Sending event SignInEvent(data: nil, id: "6CB37A40-3846-4A21-9E5D-F3D6C9D9936D", eventType: AWSCognitoAuthPlugin.SignInEvent.EventType.throwAuthError(AWSCognitoAuthPlugin.SignInError.service(error: ClientRuntime.SdkError.client(ClientRuntime.ClientError.retryError(ClientRuntime.SdkError.service(AWSCognitoIdentityProvider.RespondToAuthChallengeOutputError.notAuthorizedException(AWSCognitoIdentityProvider.NotAuthorizedException(_headers: Optional(x-amzn-RequestId: xxxx, Content-Length: 79, x-amzn-ErrorType: NotAuthorizedException:, x-amzn-ErrorMessage: Incorrect username or password., Date: Wed, 04 Jan 2023 04:27:51 GMT, Connection: keep-alive, Content-Type: application/x-amz-json-1.1), _statusCode: Optional(http_status_400), _message: Optional("Incorrect username or password."), _requestID: Optional("xxxx"), _retryable: false, _isThrottling: false, _type: ClientRuntime.ErrorType.client, message: Optional("Incorrect username or password."))), Status Code: http_status_400 x-amzn-RequestId: xxxx, Content-Length: 79, x-amzn-ErrorType: NotAuthorizedException:, x-amzn-ErrorMessage: Incorrect username or password., Date: Wed, 04 Jan 2023 04:27:51 GMT, Connection: keep-alive, Content-Type: application/x-amz-json-1.1)), nil))), time: nil) 2023-01-03T20:27:51-0800 info SerialExecutor : [Logging] Connection to endpoint: Optional("https://cognito-idp.us-east-1.amazonaws.com/?") is closing 2023-01-03 20:27:51.947376-0800 AmplifyAuthSample[38816:428907] [AWSCognitoAuthPlugin] Auth state change: { "AuthState.configured" = { "AuthenticationState.signingIn" = { "SignInState.resolvingChallenge" = { "SignInChallengeState.error" = { challenge = "AWSCognitoIdentityProvider.CognitoIdentityProviderClientTypes.ChallengeNameType.customChallenge"; error = "AWSCognitoAuthPlugin.SignInError.service(error: ClientRuntime.SdkError.client(ClientRuntime.ClientError.retryError(ClientRuntime.SdkError.service(AWSCognitoIdentityProvider.RespondToAuthChallengeOutputError.notAuthorizedException(AWSCognitoIdentityProvider.NotAuthorizedException(_headers: Optional(Date: Wed, 04 Jan 2023 04:27:51 GMT, \nContent-Length: 79, \nx-amzn-RequestId: xxxx, \nContent-Type: application/x-amz-json-1.1, \nx-amzn-ErrorMessage: Incorrect username or password., \nConnection: keep-alive, \nx-amzn-ErrorType: NotAuthorizedException:), _statusCode: Optional(http_status_400), _message: Optional(\"Incorrect username or password.\"), _requestID: Optional(\"xxxx\"), _retryable: false, _isThrottling: false, _type: ClientRuntime.ErrorType.client, message: Optional(\"Incorrect username or password.\"))), \nStatus Code: http_status_400 \n Content-Type: application/x-amz-json-1.1, \nx-amzn-ErrorMessage: Incorrect username or password., \nContent-Length: 79, \nDate: Wed, 04 Jan 2023 04:27:51 GMT, \nConnection: keep-alive, \nx-amzn-RequestId: xxxx, \nx-amzn-ErrorType: NotAuthorizedException:)), nil))"; username = "xxx@xx.com"; }; challengeType = "AWSCognitoAuthPlugin.AuthChallengeType.customChallenge"; signInMethod = "AWSCognitoAuthPlugin.SignInMethod.apiBased(AWSCognitoAuthPlugin.AuthFlowType.customWithSRP)"; }; }; "AuthorizationState.signingIn" = { }; }; } VC confirmSignIn: Error = AuthError: Incorrect username or password. Recovery suggestion: Check whether the given values are correct and the user is authorized to perform the operation. ```
patrickjohnson97 commented 1 year ago

Hey Jithin, I wasn't able to get any more logs for this flow, but I am still facing this issue. I saw that the PR you made above has been stalled due to some unintended consequences of the changes. Do you have any updates on this?

patrickjohnson97 commented 1 year ago

In a last ditch effort to fix this issue, I removed amplify entirely from my project locally and remotely and recreated every resource from scratch. Even still, the issue persists. I am losing hope.

royjit commented 1 year ago

Thanks, for reaching back. I will give an update today here.

royjit commented 1 year ago

Created another PR to address this issue - https://github.com/aws-amplify/amplify-swift/pull/2687 We are currently reviewing PR and testing the changes. Feel free to try out the changes by pointing to the branch royjit.fixfetchAuthSession2 and let us know if this fixes your issue.

hbmartin commented 1 year ago

In my experience setting CUSTOM_AUTH in the config is not sufficient, even if the docs say otherwise (they often incorrectly refer to SDK v1 APIs). Adding auth options to the signIn call works though: let result = try await Amplify.Auth.signIn(username: username, options: AuthSignInRequest.Options(pluginOptions: AWSAuthSignInOptions(authFlowType: .customWithoutSRP)))

patrickjohnson97 commented 1 year ago

Hey Harold - yes I have that exact line in my sign in function. I have been following this documentation almost to the tee (except for changing out the random number generation logic in the lambda).

patrickjohnson97 commented 1 year ago

Created another PR to address this issue - #2687 We are currently reviewing PR and testing the changes. Feel free to try out the changes by pointing to the branch royjit.fixfetchAuthSession2 and let us know if this fixes your issue.

I pulled in this branch and I am still facing the same issue. Just to reiterate, the app starts to hang when the confirm sign in call is made.

royjit commented 1 year ago

I am unable to figure out the root cause of this and also not able to reproduce it I followed the same doc. For custom auth I just used a hard coded value. Would you like to setup a call to debug this? You can reach us via discord or contact via email (royji at amazon.com).

patrickjohnson97 commented 1 year ago

Just to circle back here - by pulling in the main branch of the amplify sdk I was able to resolve this issue. Thank you Jithin for deep diving this issue with me and your support throughout this ticket.

royjit commented 1 year ago

Thank you for the update, the changes will be available in the next release.

gurkarangulati commented 6 months ago

Need this in the visionos-preview branch. Facing the same error.

harsh62 commented 6 months ago

@gurkarangulati Can you please open a new issue so that we can track and work on the issue.