How to use the Shortener API Client Library for Java in Android Studio?
I am using Google+ to login to an android app and I want to send an authentication token to my web server. I am following the link [ https://developers.google.com/identity/sign-in/android/backend-auth] [1 ] and use the following code to generate idToken.
private class GetIdTokenTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient);
Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
String scopes = "audience:server:client_id:" + Constants.SERVER_CLIENT_ID; // Not the app client ID.
String idToken = "";
try {
idToken = GoogleAuthUtil.getToken(getApplicationContext(), account, scopes);
} catch (IOException e) {
Log.e(TAG, "Error retrieving ID token.", e);
} catch (GoogleAuthException e) {
Log.e(TAG, "Error retrieving ID token.", e);
}
return idToken;
}
@Override
protected void onPostExecute(String result) {
authToken=result;
Log.i(TAG, "ID token: " + result);
}
}
and I am getting the id like this:
eyJhbGciOiJSUzI1NiIsImtpZCI6IxxxxxNThkODVjODU3hiMjI3MjBhM2E1NWxxxxzM0NDcifQ.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwic3ViIjoiMTEyMzA2OTkwMjA1NDYyMjkzMDExIiwiYXpwIjoiNDU5NTM4MTI1OTIzLXUzNTEzNGZ0aTZyOWJnNGM4MDFjZW82MzVhNWVoNTZzLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiZW1haWwiOiJsZWppbmtyQGdtYWlsLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJhdWQiOiI0NTk1MzgxMjU5MjMtNDZlN3Q3YzNhbmQ3M2VqcThyZWZvZTFzYTIzdm9wOHEuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJpYXQiOjE0MzI2MzI5ODUsImV4cCI6MTQzMjYzNjU4NX0.vCT8lanz5Pa2_m_AQ4tZHaME_y_ffa5zqA5_O3u7ZhuOQTmK8xXUh7M-Q_R67KosGPX-ikr_7Tz57OiXNIyKtNBOFKssssxxE0v7wEJvFhVgLSpbuD
is this the real idToken format?
but my back end server authentication token needs a format like this (some other people make the end)
ya29.QwGqNA9LsssggddjKZxxRD74HT_viU0wHxoDieWbsIJG3R0xvW3bDij4jzxxxxxP6wPSi7w1bysA
and the code terminators suggest that I use something like urlshortener and userinfo.email to get such a token. How can I get this token? I am using GoogleApiClient to connect to google plus and drive api in the following code:
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addApi(Plus.API)
.addScope(new Scope("profile"))
.addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mGoogleApiClient.connect();
}
});
how to get the auth token in the shorthand format described above?
source to share
No one has answered this question yet
Check out similar questions: