Google Sign In Authenticate with a backend server
up vote
0
down vote
favorite
I need to get access token from android app and send it to backend server in order to make some operation with google calendar api.
I followed this:
https://developers.google.com/identity/sign-in/android/backend-auth
But I got com.google.android.gms.common.api.ApiException: 10
Something gone wrong with "server_client_id"
In https://console.cloud.google.com/apis/credentials I maked two try
1) with client id for webapplication (I am using it in app project web version)
2) with client id for android app reporting the SHA-1 as requested
What is the right way 1 or 2? And why I'm got an error?
Thank you
I'm using the code above:
/*GOOGLE OAUTH*/
public void signIn() {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("XXXXXXX.apps.googleusercontent.com")
.requestEmail()
.build();
// Build a GoogleSignInClient with the options specified by gso.
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
private void handleSignInResult(@NonNull Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
String idToken = account.getIdToken();
Log.v("MYLOG","Ottengo Access Token " + idToken);
// TODO(developer): send ID Token to server and validate
//updateUI(account);
} catch (ApiException e) {
Log.w("MYLOG", "handleSignInResult:error", e);
//updateUI(null);
}
}
/*GOOGLE OAUTH END*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
/*GOOGLE SIGN IN OAUTH SECTION*/
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
super.onActivityResult(requestCode, resultCode, data);
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
return;
}
java android google-oauth2
add a comment |
up vote
0
down vote
favorite
I need to get access token from android app and send it to backend server in order to make some operation with google calendar api.
I followed this:
https://developers.google.com/identity/sign-in/android/backend-auth
But I got com.google.android.gms.common.api.ApiException: 10
Something gone wrong with "server_client_id"
In https://console.cloud.google.com/apis/credentials I maked two try
1) with client id for webapplication (I am using it in app project web version)
2) with client id for android app reporting the SHA-1 as requested
What is the right way 1 or 2? And why I'm got an error?
Thank you
I'm using the code above:
/*GOOGLE OAUTH*/
public void signIn() {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("XXXXXXX.apps.googleusercontent.com")
.requestEmail()
.build();
// Build a GoogleSignInClient with the options specified by gso.
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
private void handleSignInResult(@NonNull Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
String idToken = account.getIdToken();
Log.v("MYLOG","Ottengo Access Token " + idToken);
// TODO(developer): send ID Token to server and validate
//updateUI(account);
} catch (ApiException e) {
Log.w("MYLOG", "handleSignInResult:error", e);
//updateUI(null);
}
}
/*GOOGLE OAUTH END*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
/*GOOGLE SIGN IN OAUTH SECTION*/
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
super.onActivityResult(requestCode, resultCode, data);
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
return;
}
java android google-oauth2
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to get access token from android app and send it to backend server in order to make some operation with google calendar api.
I followed this:
https://developers.google.com/identity/sign-in/android/backend-auth
But I got com.google.android.gms.common.api.ApiException: 10
Something gone wrong with "server_client_id"
In https://console.cloud.google.com/apis/credentials I maked two try
1) with client id for webapplication (I am using it in app project web version)
2) with client id for android app reporting the SHA-1 as requested
What is the right way 1 or 2? And why I'm got an error?
Thank you
I'm using the code above:
/*GOOGLE OAUTH*/
public void signIn() {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("XXXXXXX.apps.googleusercontent.com")
.requestEmail()
.build();
// Build a GoogleSignInClient with the options specified by gso.
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
private void handleSignInResult(@NonNull Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
String idToken = account.getIdToken();
Log.v("MYLOG","Ottengo Access Token " + idToken);
// TODO(developer): send ID Token to server and validate
//updateUI(account);
} catch (ApiException e) {
Log.w("MYLOG", "handleSignInResult:error", e);
//updateUI(null);
}
}
/*GOOGLE OAUTH END*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
/*GOOGLE SIGN IN OAUTH SECTION*/
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
super.onActivityResult(requestCode, resultCode, data);
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
return;
}
java android google-oauth2
I need to get access token from android app and send it to backend server in order to make some operation with google calendar api.
I followed this:
https://developers.google.com/identity/sign-in/android/backend-auth
But I got com.google.android.gms.common.api.ApiException: 10
Something gone wrong with "server_client_id"
In https://console.cloud.google.com/apis/credentials I maked two try
1) with client id for webapplication (I am using it in app project web version)
2) with client id for android app reporting the SHA-1 as requested
What is the right way 1 or 2? And why I'm got an error?
Thank you
I'm using the code above:
/*GOOGLE OAUTH*/
public void signIn() {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("XXXXXXX.apps.googleusercontent.com")
.requestEmail()
.build();
// Build a GoogleSignInClient with the options specified by gso.
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
private void handleSignInResult(@NonNull Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
String idToken = account.getIdToken();
Log.v("MYLOG","Ottengo Access Token " + idToken);
// TODO(developer): send ID Token to server and validate
//updateUI(account);
} catch (ApiException e) {
Log.w("MYLOG", "handleSignInResult:error", e);
//updateUI(null);
}
}
/*GOOGLE OAUTH END*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
/*GOOGLE SIGN IN OAUTH SECTION*/
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
super.onActivityResult(requestCode, resultCode, data);
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
return;
}
java android google-oauth2
java android google-oauth2
edited Nov 19 at 16:34
Kling Klang
32.2k156287
32.2k156287
asked Nov 19 at 14:39
Giuseppe
488
488
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I solved the issue, and doubts.
1) Don't forget to put credentials.json in your app root directory.
2) If you need a backend server you can use credentials.json (and client_id) from web version (for example the same you're using for your website software version).
Don't needed an android oauth client id with sha1 fingerprint etc.)
3) you can use the same apikey as website, but if you want to make a restriction based on referer (for website) and based on android app.. you have to make two api key, one with referer restriction and one with sha1 fingerprint restriction
hope this help other guys!
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I solved the issue, and doubts.
1) Don't forget to put credentials.json in your app root directory.
2) If you need a backend server you can use credentials.json (and client_id) from web version (for example the same you're using for your website software version).
Don't needed an android oauth client id with sha1 fingerprint etc.)
3) you can use the same apikey as website, but if you want to make a restriction based on referer (for website) and based on android app.. you have to make two api key, one with referer restriction and one with sha1 fingerprint restriction
hope this help other guys!
add a comment |
up vote
0
down vote
I solved the issue, and doubts.
1) Don't forget to put credentials.json in your app root directory.
2) If you need a backend server you can use credentials.json (and client_id) from web version (for example the same you're using for your website software version).
Don't needed an android oauth client id with sha1 fingerprint etc.)
3) you can use the same apikey as website, but if you want to make a restriction based on referer (for website) and based on android app.. you have to make two api key, one with referer restriction and one with sha1 fingerprint restriction
hope this help other guys!
add a comment |
up vote
0
down vote
up vote
0
down vote
I solved the issue, and doubts.
1) Don't forget to put credentials.json in your app root directory.
2) If you need a backend server you can use credentials.json (and client_id) from web version (for example the same you're using for your website software version).
Don't needed an android oauth client id with sha1 fingerprint etc.)
3) you can use the same apikey as website, but if you want to make a restriction based on referer (for website) and based on android app.. you have to make two api key, one with referer restriction and one with sha1 fingerprint restriction
hope this help other guys!
I solved the issue, and doubts.
1) Don't forget to put credentials.json in your app root directory.
2) If you need a backend server you can use credentials.json (and client_id) from web version (for example the same you're using for your website software version).
Don't needed an android oauth client id with sha1 fingerprint etc.)
3) you can use the same apikey as website, but if you want to make a restriction based on referer (for website) and based on android app.. you have to make two api key, one with referer restriction and one with sha1 fingerprint restriction
hope this help other guys!
answered Nov 20 at 9:54
Giuseppe
488
488
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376942%2fgoogle-sign-in-authenticate-with-a-backend-server%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown