I've signed my android app as a api on google console, as well as my backend server as oauth client in google console.
I've also updated updated my gradle files and so what ever neccesary to get a token Id.
But somehow, I'm always failing to get a token from google.
I've checked my package name and ssh1 code from google console and matched it with my debug ssh1 via with command: keytool -list -v -keystore mydebudpath\debug.keystore
I'm going to submit my android code here:
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
validateServerClientID();
// [START configure_signin]
// Request only the user's ID token, which can be used to identify the
// user securely to your backend. This will contain the user's basic
// profile (name, profile picture URL, etc) so you should not need to
// make an additional call to personalize your application.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.server_client_id))
.requestServerAuthCode(getString(R.string.server_client_id), false)
.requestEmail()
.build();
// [END configure_signin]
// Build GoogleAPIClient with the Google Sign-In API and the above options.
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.enableAutoManage(getActivity()/* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
}
and my onActivityResult:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_GET_TOKEN) {
// [START get_id_token]
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
Log.d(TAG, "onActivityResult:GET_TOKEN:success:" + result.getStatus().isSuccess());
if (result.isSuccess()) {
GoogleSignInAccount acct = result.getSignInAccount();
String idToken = acct.getIdToken();
// Show signed-in UI.
Log.d(TAG, "idToken:" + idToken);
updateUI(true);
// TODO(user): send token to server and validate server-side
} else {
// Show signed-out UI.
updateUI(false);
}
// [END get_id_token]
}
}
the code result.getStatus().isSuccess();
always returns false
Please also note that in above codes my R.string.server_client_id
is my server's client_id which I've created in google developer console as web application oauth2.
I've never used my android api_key
in my android authentication code. Where Am I supposed to use it?
Which part Am I doing wrong?
here is my checklist it might be useful to you
If all else fail i suggest you try to create a new api key based on a new project in Google Developer Console, goodluck!
Useful info: developers.google.com/identity/sign-in/android/start-integrating