Endpoints User Authentication

I am trying to access User in one of my endpoints but cannot get the magic from Android. The documentation seems to be in a somewhat broken state, seeing it just move from the trusted testers program, and I see conflicting information, so I hope someone here can help me.

I have created a client id for Android in the API Console. I am specifying it as the customer ID and audience in my endpoint, like so:

@Api(
name = "tictactoe",
clientIds = {"myAndroidClientId.apps.googleusercontent.com"},
audiences = {"myAndroidClientId.apps.googleusercontent.com"}
)

      

In my Android activity, I create my credentials:

credential =  GoogleAccountCredential.usingAudience(this, "server:client_id:myAndroidClientId.apps.googleusercontent.com");
credential.setSelectedAccountName(myAccountName);

      

and I use this to create my service before making a network call in the AsyncTask:

Builder builder = new MyService.Builder(transport, jsonFactory, credential);
MyService service = builder.build();
thing = service.things().get().execute();

      

which then throws this exception:

com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException
Caused by: 
com.google.android.gms.auth.GoogleAuthException: Unknown
com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:192) 
com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:217)

      

Thanks in advance for your help!

+3


source to share


1 answer


Found out where I went wrong:



You have to specify the web client id as audience in @API as well as in Android. The android client id is only used in @API client.

+4


source







All Articles