realm / realm-tasks

To Do app built with Realm, inspired by Clear for iOS
Other
369 stars 71 forks source link

GoogleSignInResult returns Status{statusCode=unknown status code: 12501, resolution=null} when requesting Token #408

Closed ojarabo closed 7 years ago

ojarabo commented 7 years ago

Hi there, I am trying to enable google auth in my app. I have been following your example, but it didn't work.

In you example, you request the IdToken in the GoogleSignInOptions.Builder

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .requestIdToken(fragmentActivity.getString(R.string.server_client_id))
                .build();

to later use it onRegistrationComplete


 googleAuthLogin     = new GoogleAuth((Button) findViewById(R.id.google_default_button), this) {
            @Override
            public void onRegistrationComplete(GoogleSignInResult result) {
                UserManager.setAuthMode(UserManager.AUTH_MODE.GOOGLE);
                GoogleSignInAccount acct = result.getSignInAccount();
                SyncCredentials credentials = SyncCredentials.google(acct.getIdToken());
                SyncUser.loginAsync(credentials, AUTH_URL, SplashScreenActivity.this);
            }

            @Override
            public void onError(String s) {
                super.onError(s);
            }
        };

I have registered my app in the google console as an Android Client. However, during the execution, my app never got onRegistrationComplete because GoogleSignInResult returned a status code 12501.

I have been researching for a while an I have discovered that if I enabled the Outh client as a web application the error would disappear. However, my app will never reach onSuccess. It would instead call onError with a value of INVALID_CREDENTIALS. This is caused because the IdToken is linked to the web application and not to the Android Client, so the credentials don't match.

Could you please clarify if the app has to be only declared as a web application or if I am doing something else wrong?

Thanks

seferdemir commented 7 years ago

@ojarabo how did you do it?