Google Sign In Authenticate with a backend server
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
add a comment |
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
add a comment |
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
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
java
edited Nov 19 '18 at 16:34
Fantômas
32.4k156388
32.4k156388
asked Nov 19 '18 at 14:39
GiuseppeGiuseppe
488
488
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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 '18 at 9:54
GiuseppeGiuseppe
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.
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