aws-sdk-android icon indicating copy to clipboard operation
aws-sdk-android copied to clipboard

`signIn` method is always trying to perform federated sign in

Open sarbagyastha opened this issue 3 years ago • 11 comments

The signIn method here is trying to perform federated signIn (because isFederationEnabled() is always true here): https://github.com/aws-amplify/aws-sdk-android/blob/c2936ae4b075d9509d01797bb6f8f65169d54079/aws-android-sdk-mobile-client/src/main/java/com/amazonaws/mobile/client/AWSMobileClient.java#L1215-L1254

If you look into the isFederationEnabled(), which is being checked to perform federated sign in, it returns false only when the value for key FEDERATION_ENABLED_KEY is set other than "true", otherwise it's always true. https://github.com/aws-amplify/aws-sdk-android/blob/c2936ae4b075d9509d01797bb6f8f65169d54079/aws-android-sdk-mobile-client/src/main/java/com/amazonaws/mobile/client/AWSMobileClient.java#L1154-L1163

But the value for FEDERATION_ENABLED_KEY is only set in Hosted UI and OAuth2 SignIn methods.

The actual issue can be found here: aws-amplify/amplify-flutter#1362

sarbagyastha avatar Mar 01 '22 14:03 sarbagyastha

I'm seeing this issue too. I want to use normal cognito idp pool not federated

rhamnett avatar Jun 29 '22 01:06 rhamnett

I'm having the same issue using an idp pool not federated

cmunaro avatar Jul 07 '22 15:07 cmunaro

@cmunaro are you using flutter? I've added the bug here https://github.com/aws-amplify/amplify-flutter/issues/1845 as it's happening on both iOS and Android so not sure if it's upstream

rhamnett avatar Jul 07 '22 17:07 rhamnett

@rhamnett I'm experiencing it in Kotlin (Android) after invoking

  Amplify.Auth.signInWithSocialWebUI(
      provider = AuthProvider.facebook(),
      callingActivity = activity
  )

Ah sorry in my last comment I expressed myself badly, I'm using an user pool without an identity pool for that user pool

cmunaro avatar Jul 08 '22 13:07 cmunaro

signInWithSocialWebUI assumes that you have an identity pool configured. You can override this by disabling the federation using HostedUIOptions.

HostedUIOptions hostedUIOptions = HostedUIOptions.builder()
    .scopes("openid", "email")
    .disableFederation(false)
    .build();

SignInUIOptions signInUIOptions = SignInUIOptions.builder()
    .hostedUIOptions(hostedUIOptions)
    .build();

Note: The API naming is incorrect.

div5yesh avatar Jul 08 '22 22:07 div5yesh

@div5yesh how should I use signInUIOptions? The options parameter of Amplify.Auth.signInWithSocialWebUI is of type AuthWebUISignInOptions, trying to copy signInQueryParameters from one to the other doesn't work.

If I should stop using Amplify.Auth to be able to configure this, I prefer to let the sdk doing the failing requests in the background ignoring the failing result in logcat.

cmunaro avatar Jul 12 '22 08:07 cmunaro

This PR should address your issue: https://github.com/aws-amplify/amplify-android/pull/1823

If using Amplify provide AWSCognitoAuthWebUISignInOptions as:

AWSCognitoAuthWebUISignInOptions options = AWSCognitoAuthWebUISignInOptions.builder().isFederationEnabled(false).build();

div5yesh avatar Jul 13 '22 20:07 div5yesh

Wow you were super fast! 🥇 Thanks @div5yesh! 💚

cmunaro avatar Jul 15 '22 07:07 cmunaro

@cmunaro, fyi, if you are not using Identity Pool, you will not be able to fetch AWS credentials to access other AWS resources. To understand your use case clearly, can you explain how are you planning to use only user pool?

div5yesh avatar Jul 23 '22 01:07 div5yesh

@div5yesh I have to pass the id token to my backend, then with some magic (we have different teams I don't handle that part) they give me another token that I have to use to authenticate on other services

cmunaro avatar Jul 29 '22 07:07 cmunaro

With further testing, I found out that just having federation disabled is not enough to return the correct signed in result. The parts of code does point out that with federation disabled sign in should end with success in absence of identity pool, but does not return the correct result.

To fix this, changes are required in the AWS Android SDK. We are going to keep investigating and look for proper fix.

div5yesh avatar Aug 05 '22 19:08 div5yesh