amplify-android: Social sign in adds user to federated pool but doesn't redirect

Describe the bug I’m integrating social signIn using Facebook and google into my android app. I’m using this guide . when the user clicks on the social sign in button, he gets added to the social pool however the app does not redirect. For Google, it stays loading the redirection url with a blank webview. this is the redirect URL https://projectxyz13568-ffff-local.auth.us-east-1.amazoncognito.com/oauth2/authorize?client_id=4hmdq6hcn2cjj6cl9q57vnhhvi&redirect_uri=redirectURI%3A%2F%2F&response_type=code&code_challenge=sreyQtr86U6HWSgzQ04wnSpi2rKyyAX5azG21KoNUxc&code_challenge_method=S256&state=CRVUtDPhnXMQz967j_CZe60cNJvvk0ga7IIbSyDvN2o&userContextData=null&identity_provider=Google

in the first tries, it allows to choose the account if there’s multiple accounts on the device but after that it just keeps loading nothing. just a blank webview. When I close the webview I get the ’ authentication flow canceled by user’.

To Reproduce A code sample or steps:

  Amplify.Auth.signInWithSocialWebUI(AuthProvider.google(), this.requireActivity(), {
            Log.i("successGG", it.isSignInComplete.toString())
          
        }, {
            Log.i("errorGG", it.localizedMessage)
        })
override  fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
            super.onActivityResult(requestCode, resultCode, data)
            Log.d("requestCode","${requestCode} resultCode=${resultCode} data=$data")
            if (requestCode == AWSCognitoAuthPlugin.WEB_UI_SIGN_IN_ACTIVITY_CODE) {
                if (data != null) {
                    if (resultCode == Activity.RESULT_CANCELED) {
                        Amplify.Auth.handleWebUISignInResponse(data)
                    }
                }
            }
        }

Which AWS service(s) are affected?

Expected behavior User chooses account, signs in and gets redirected to my application, homefragment

Screenshots

Screen Shot 2022-01-14 at 11 01 01 AM

Environment Information (please complete the following information):

  • AWS Android SDK Version: [e.g. 2.6.25]
  • Device: [e.g. Pixel XL, Simulator]
  • Android Version: [e.g. Nougat 7.1.2]
  • Specific to simulators: [e.g. Yes/No]

Additional context Add any other context about the problem here.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 39 (12 by maintainers)

Most upvoted comments

@poojamat, what are we supposed to make sure in AndroidManifest.xml?

To clarify, the important parts of the manifest file are:

  • the <queries> block (outside of the <application> block)
  • the <activity android:name="com.amplifyframework.auth.cognito.activities.HostedUIRedirectActivity" ...> ... block (inside the <application> block) to handle both the login and the logout callbacks
  • if you want to implement custom Activities for the login and logout callbacks, you need a block that looks similar to this:
<activity android:name=".LogoutActivity" android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="myapp" android:host="signout" />
    </intent-filter>
</activity>

where the name of the Activity (android:name="...") and the URI (android:scheme="myapp" android:host="signout", corresponding to myapp://signout) match the Activity you want to redirect to and the URI you specified when configuring Auth.

Thanks with your suggestion I solved the question too. I remain of the idea that the documentation should be clearer on this point

@taouichaimaa — it looks like the tutorial you linked is for the Android SDK section of the documentation (i.e. using AWSMobileClient), while the code you’re showing is for the Amplify section of the documentation (i.e. using Amplify) — did you happen to link the wrong documentation page?  Also, could you make sure that your redirect URL in GCP is https://<your-user-pool-domain>/oauth2/idpresponse?  Please let us know if either of those changes resolves your issue. We were unable to reproduce your issue using Amplify version 1.31.1 — would you mind sharing your version number, as there were changes over the past year to fix some bugs with this code? @Reenagrg100 and @elax46, your issues seem to be subtly different.  If they are not resolved by these changes, I’d recommend that you open new issues with more specific details.  For example: @Reenagrg100, I find it confusing that you say you’re using Amplify.federatedSignIn(provider) when that particular API only exists on AWSMobileClient to my knowledge, and to @elax46 I would expect that a followup question would be asking you what value you selected for your redirect signin/signout URIs when configuring Auth in the first place, so it would be beneficial to include that when creating a new issue. Hope this helps!

Hi thanks for your answer I simply entered myapp://mainactivity/ and myapp://login/ the first to redirect to bring the user into main activity after access the second to return the user to the page to the login activity if he logs out since the documentation page does not indicate the use of android:host="" I simply entered in the manifest <data android:scheme="myapp" /> the thing that is not clear in detail is what is meant by appname? the pakage or what else? from this point of view the documentation is unclear

@elax46 I think I see what’s happening – “appname” just refers to whatever URI prefix you chose, in this case “myapp”. To match a logout URI of myapp://login/ the corresponding line you need to put in the manifest file <intent-filter> is <data android:scheme="myapp" android:host="signout" /> and similarly for the redirect URI.

Hey thanks, @tjleing my issues have been resolved the day I did my last comment. The issue was only related to I missed to add uri scheme in my AndroidManifest.xml file.

Still facing the same issue 😦

@poojamat, what are we supposed to make sure in AndroidManifest.xml?

To clarify, the important parts of the manifest file are:

  • the <queries> block (outside of the <application> block)
  • the <activity android:name="com.amplifyframework.auth.cognito.activities.HostedUIRedirectActivity" ...> ... block (inside the <application> block) to handle both the login and the logout callbacks
  • if you want to implement custom Activities for the login and logout callbacks, you need a block that looks similar to this:
<activity android:name=".LogoutActivity" android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="myapp" android:host="signout" />
    </intent-filter>
</activity>

where the name of the Activity (android:name="...") and the URI (android:scheme="myapp" android:host="signout", corresponding to myapp://signout) match the Activity you want to redirect to and the URI you specified when configuring Auth.

Please make sure your manifest has:

<queries>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="https" />
  </intent>
  <intent>
    <action android:name=
        "android.support.customtabs.action.CustomTabsService" />
  </intent>
</queries>
<application ...>
  ...
  <activity
      android:name="com.amazonaws.mobile.client.activities.HostedUIRedirectActivity"
      android:exported="true">
      <intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <data android:scheme="myapp" />
      </intent-filter>
  </activity>