auth0-samples / auth0-android-sample

Auth0 Integration Samples for Android Applications
https://auth0.com/docs/quickstart/native/android
MIT License
77 stars 141 forks source link

OAuthManager: Received state doesn't match. #69

Closed sharukhmohammed closed 5 years ago

sharukhmohammed commented 5 years ago

I get this unindentified error, couldn't debug where's the problem. Even clear app data doesn't work.

E/OAuthManager: Received state doesn't match. Received VikZhSyOD0MBxkiPG7swzaQsc2yAuM6s2Y3jn_m3yfU but expected On7vaXLWhWslEoh8ly0e9eFxhboZktfjyh_MXk3nULo
W/System.err: com.auth0.android.authentication.AuthenticationException: An error occurred when trying to authenticate with the server.
W/System.err:     at com.auth0.android.provider.OAuthManager.assertValidState(OAuthManager.java:187)
W/System.err:     at com.auth0.android.provider.OAuthManager.resumeAuthorization(OAuthManager.java:120)
W/System.err:     at com.auth0.android.provider.WebAuthProvider.resume(WebAuthProvider.java:389)
W/System.err:     at com.auth0.android.provider.AuthenticationActivity.deliverSuccessfulAuthenticationResult(AuthenticationActivity.java:126)
W/System.err:     at com.auth0.android.provider.AuthenticationActivity.onResume(AuthenticationActivity.java:85)
W/System.err:     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1413)
W/System.err:     at android.app.Activity.performResume(Activity.java:7366)
W/System.err:     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3816)
W/System.err:     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3856)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
W/System.err:     at android.os.Looper.loop(Looper.java:201)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6806)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

This is how I initialize...

WebAuthProvider
                .init(auth)
                .withScheme("xxx")
                .withAudience("https://${getString(R.string.com_auth0_domain)}/userinfo")
                .start(this, object : AuthCallback {
                    override fun onSuccess(credentials: Credentials) {

                        if (!credentials.accessToken.isNullOrEmpty())
                            AppUser(this@SplashActivity)
                                .setAccessToken(credentials.accessToken!!)
                                .save(this@SplashActivity)

                        if (!credentials.idToken.isNullOrEmpty())
                            AppUser(this@SplashActivity)
                                .setIdToken(credentials.idToken!!)
                                .save(this@SplashActivity)

                        startActivity(Intent(this@SplashActivity, MainActivity::class.java))

                    }

                    override fun onFailure(dialog: Dialog) {
                        dialog.show()
                    }

                    override fun onFailure(exception: AuthenticationException?) {
                        exception?.printStackTrace()
                    }
                })
jimmyjames commented 5 years ago

Hi @sharukhmohammed, I'm going to close this issue as it does not appear to be an issue with the sample code. If you are still having issues with the OAuthManager, please open an issue for the Auth0.Android SDK.