aws-amplify / amplify-android

The fastest and easiest way to use AWS from your Android app.
https://docs.amplify.aws/lib/q/platform/android/
Apache License 2.0
247 stars 117 forks source link

CUSTOM_AUTH is working partially on v2.0.0 (working on 1.37.7 version) #2173

Closed JurajBegovac closed 1 year ago

JurajBegovac commented 1 year ago

Before opening, please confirm:

Language and Async Model

Kotlin, Kotlin - Coroutines

Amplify Categories

Authentication

Gradle script dependencies

```groovy // Put output below this line aws-amplify = "1.37.7" aws-kotlin = "0.21.7" aws-amplifyframework-core = { module = "com.amplifyframework:core", version.ref = "aws-amplify" } aws-cognito = { module = "com.amplifyframework:aws-auth-cognito", version.ref = "aws-amplify" } aws-amplifyframework-core-kotlin = { module = "com.amplifyframework:core-kotlin", version.ref = "aws-kotlin" } ```

Environment information

``` # Put output below this line ------------------------------------------------------------ Gradle 7.5 ------------------------------------------------------------ Build time: 2022-07-14 12:48:15 UTC Revision: c7db7b958189ad2b0c1472b6fe663e6d654a5103 Kotlin: 1.6.21 Groovy: 3.0.10 Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021 JVM: 11.0.16.1 (Homebrew 11.0.16.1+0) OS: Mac OS X 12.6.1 aarch64 ```

Please include any relevant guides or documentation you're referencing

No response

Describe the bug

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

Not working on 2.0.0 - working on 1.37.7

Basically, I manage to confirm the SMS code but then after the access token expires Cognito session treats user as signedOut ?!

This is our use case:

  1. Call signup (in case of success go to signIn, or in case user exists go to signIn)
    Amplify.Auth.signUp(username, password, options)
  2. Call signIn:
    Amplify.Auth.signIn(username, password)

    3.Call confirm

    Amplify.Auth.confirmSignIn(smsCode)

And everything works - I get the token - but once the accessToken expires I don't get any new accessToken (like in older version) - then I'm getting some signout exception

AWS configuration:

{
    "auth":
    {
        "plugins":
        {
            "awsCognitoAuthPlugin":
            {
                "CognitoUserPool":
                {
                    "Default":
                    {
                        "PoolId": "",
                        "AppClientId": "",
                        "AppClientSecret": "",
                        "Region": ""
                    }
                },
                "Auth":
                {
                    "Default":
                    {
                        "authenticationFlowType": "CUSTOM_AUTH"
                    }
                }
            }
        }
    }
}

Reproduction steps (if applicable)

No response

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

amplifyconfiguration.json

No response

GraphQL Schema

```graphql // Put your schema below this line ```

Additional information and screenshots

I'm working on KMM project where I have interface/protocol inside shared module and implementations on iOS and Android side. I also opened swift issue because on iOS I cannot even pass the third step https://github.com/aws-amplify/amplify-swift/issues/2608

tylerjroach commented 1 year ago

Thank you for your report. Someone on our team will take a look.

banji180 commented 1 year ago

Hi there, For the Cognito setup, did you select CUSTOM_AUTH_WITH_SRP or CUSTOM_AUTH_WITHOUT_SRP?

JurajBegovac commented 1 year ago

We use "CUSTOM_AUTH_FLOW_ONLY" so I guess it's "CUSTOM_AUTH_WITHOUT_SRP"

banji180 commented 1 year ago

Hi @JurajBegovac

Can you change your authentication flow type to CUSTOM_AUTH_WITHOUT_SRP or use the signIn(username, password, options) as mentioned here)

And please make sure you call fetchAuthSession or any other api before your token expires. Please reply here if this helps and if it doesn't, we will investigate further.

Please ensure you are using the right authFlowType because CUSTOM_AUTH_WITHOUT_SRP does not have SRP as the first step and CUSTOM_AUTH_WITHOUT_SRP does not need passsword.

JurajBegovac commented 1 year ago

@banji180 Hi, in the meantime we changed auth flow so I guess this is now oboslete

github-actions[bot] commented 1 year ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.