Describe the bug
Hello friends i got this error when i try to authentication using Auth0 Hosted UI
Exception: Failed to exchange code for tokens
at com.amazonaws.mobile.client.internal.oauth2.OAuth2Client.requestTokens(OAuth2Client.java:334)
at com.amazonaws.mobile.client.AWSMobileClient$24$1.onResult(AWSMobileClient.java:2721)
at com.amazonaws.mobile.client.AWSMobileClient$24$1.onResult(AWSMobileClient.java:2717)
at com.amazonaws.mobile.client.internal.oauth2.OAuth2Client.handleRedirect(OAuth2Client.java:266)
at com.amazonaws.mobile.client.AWSMobileClient.handleAuthResponse(AWSMobileClient.java:2555)
at com.kpn.amplifypoc.MainActivity$3.run(MainActivity.java:71)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: com.amazonaws.mobile.client.internal.oauth2.OAuth2Exception: Failed to exchange code for tokens
at com.amazonaws.mobile.client.internal.oauth2.HTTPUtil.parseHttpResponse(OAuth2Client.java:576)
at com.amazonaws.mobile.client.internal.oauth2.OAuth2Client.requestTokens(OAuth2Client.java:330)
at com.amazonaws.mobile.client.AWSMobileClient$24$1.onResult(AWSMobileClient.java:2721)聽
at com.amazonaws.mobile.client.AWSMobileClient$24$1.onResult(AWSMobileClient.java:2717)聽
at com.amazonaws.mobile.client.internal.oauth2.OAuth2Client.handleRedirect(OAuth2Client.java:266)聽
at com.amazonaws.mobile.client.AWSMobileClient.handleAuthResponse(AWSMobileClient.java:2555)聽
at com.kpn.amplifypoc.MainActivity$3.run(MainActivity.java:71)聽
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)聽
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)聽
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)聽
at java.lang.Thread.run(Thread.java:764)聽
To Reproduce
A code sample
AWSMobileClient.getInstance().handleAuthResponse(intent);
Additional context
implementation('com.amazonaws:aws-android-sdk-mobile-client:2.16.7') { transitive = true }
implementation('com.amazonaws:aws-android-sdk-cognitoauth:2.16.7') { transitive = true }
implementation 'com.amazonaws:aws-android-sdk-auth-userpools:2.16.7'
implementation 'com.amazonaws:aws-android-sdk-auth-ui:2.16.7'
I believe this error can occur if you launch hosted UI before initializing MobileClient. Could you check on that?
Fixed it by init mobile client before launch hosted UI