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

Amplify.Auth.signIn authentication flow calls Browser logout

Open ten-skv opened this issue 4 years ago • 3 comments

Before opening, please confirm:

Language and Async Model

Kotlin

Amplify Categories

Authentication

Gradle script dependencies

// Put output below this line
    implementation 'com.amplifyframework:core:1.31.1'
    implementation 'com.amplifyframework:aws-auth-cognito:1.31.1'

Environment information

# Put output below this line


Please include any relevant guides or documentation you're referencing

No response

Describe the bug

Our App uses both username/password authentication and also Custom Provider (SAML) through socialWebUI. When the user signed in using Amplify.Auth.signIn, when I call Amplify.Auth.signOut, browser signout is called.

Currenlty there is no way to provide dynamic amplifyconfiguration, it throws AlreadyConfiguredException("Remove the duplicate call to Amplify.configure().");

Based on the user, we use either Amplify.Auth.signIn or Amplify.Auth.signInWithSocialWebUI( AuthProvider.custom("custom_provider"),...)

Expected behavior is when I use the flow Amplify.Auth.signIn, it should not call web sign out (launching the browser logout).

We don't have this issue in iOS Amplify.

Reproduction steps (if applicable)

No response

Code Snippet

// Put your code below this line.
{
  "auth": {
    "plugins": {
      "awsCognitoAuthPlugin": {
        "IdentityManager": {
          "Default": {}
        },
        "CognitoUserPool": {
          "Default": {
            "PoolId": "xxxxxxxxxxxxx",
            "AppClientId": "xxxxxxxxxxxxxxxx",
            "Region": "us-east-2"
          }
        },
        "Auth": {
          "Default": {
            "authenticationFlowType": "USER_SRP_AUTH",
            "OAuth": {
              "WebDomain": "auth.dv2.nonprod.xxxxxxx.com",
              "AppClientId": "xxxxxxxxxxxxxxxxx",
              "SignInRedirectURI": "myapp://signin",
              "SignOutRedirectURI": "myapp://signout",
              "responseType": "code",
              "Scopes": [
                "phone",
                "email",
                "openid",
                "profile",
                "aws.cognito.signin.user.admin"
              ]
            }
          }
        }
      }
    }
  }
}

Log output

// Put your logs below this line


amplifyconfiguration.json

No response

GraphQL Schema

// Put your schema below this line


Additional information and screenshots

No response

ten-skv avatar Jan 11 '22 19:01 ten-skv

We will need some more info to debug the issue. Can you provide the code snippets and reproduction steps?

div5yesh avatar Feb 18 '22 20:02 div5yesh

We have both username/password authentication and also Custom Provider (SAML) through socialWebUI. Either one will be called based on the user. When I call Amplify.Auth.signIn, it logs in successfully. In this case when I try to signout using Amplify.Auth.signOut, it is taking the user to web to singnout. I guess it is using the configuration as we have configured socialWebUI sign flow as well. Does Amplify support both username/password and socialWebUI authentication from a single app instance. We will use only one at a time based on who the user is.

Username/password authentication ->

Amplify.Auth.signIn(
        vm.login,
        vm.password,
        { result ->
            Timber.i { if (result.isSignInComplete) "Sign in succeeded" else "Sign in not complete" }
            if (result.isSignInComplete) {
                vm.getCognitoAuthSession()
            } else {
                when(result.nextStep?.signInStep) {
                    AuthSignInStep.CONFIRM_SIGN_IN_WITH_NEW_PASSWORD -> {
                        Timber.i { "CONFIRM_SIGN_IN_WITH_NEW_PASSWORD" }
                        runOnMainLooperForReneterNewPassword()
                    }

                    AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE -> {
                        Timber.i { "CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE" }
                        runOnMainLooperForMFA()
                    }
                    else ->  { vm.error = "Invalid (Error: A100)." }
                }
            }
        },
        { error ->
            vm.hideProgress()
            vm.error = "That password or email was invalid (Error: A101)."
            vm.signInButtonVisibility = true
            Timber.i { "That password or email was invalid (Error: A101)." }
            Timber.e(error)
        }
)

Social web UI signin autehntication ->

 Amplify.Auth.signInWithSocialWebUI(
    AuthProvider.custom(vm.userProviderName),
    activity as MainActivity,
    {
        Timber.i {"Signin Callback = ${it}"}
        vm.signInButtonVisibility = false
        if (it.isSignInComplete) {
            vm.storage.ssoUserFlag = true
            vm.signInButtonVisibility = false
            vm.getCognitoAuthSession()
        }
    },
    {
        Timber.e(it)
        vm.storage.ssoUserFlag = false
        vm.signInButtonVisibility = true
        Handler(Looper.getMainLooper()).post {
            user_name?.isEnabled = true
            edit_user_name?.visibility = View.GONE
        }
    }
)

ten-skv avatar Feb 18 '22 21:02 ten-skv

Amplify does support both username/password and socialWebUI authentication in a single app instance but cannot make this distinction currently for sign out. If hostedUI is configured, browser signout will be called which clearly seems unnecessary when username/password signin was used. We will look into finding a fix for this issue. Meanwhile feel free to contribute by creating a PR for the fix.

div5yesh avatar Apr 23 '22 01:04 div5yesh

@ten-skv if upgrading is possible for you I would highly recommend you upgrade your amplify library to V2 where we track which method the user was signed in under so that sign out follows the right approach for sign out.

gpanshu avatar Jan 20 '23 20:01 gpanshu

⚠️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.

github-actions[bot] avatar Feb 03 '23 17:02 github-actions[bot]