aez
aez

Reputation: 2396

How exactly to set clientIds and audiences to authenticate Google Cloud Endpoints for an Android App

In the endpoints App Engine backend, how exactly do I set

@Api(name=...
     clientIds = {what-goes-here-exactly-1},
     audiences = {what-goes-here-exactly-2}
)

and in the Android client, how exactly do I set

credential = GoogleAccountCredential.usingAudience(this,
           what-goes-here-exactly-3);

There are conflicting/confusing/unclear instructions here http://devthots.blogspot.com/ and here https://developers.google.com/appengine/docs/java/endpoints/consume_android#making-authenticated-calls

I've generated lots of keys in my API Console's API Access, but not sure how to use them and append/prepend them for use in the above statements.

Thanks.

Upvotes: 4

Views: 2291

Answers (1)

Dan Holevoet
Dan Holevoet

Reputation: 9183

In your backend you would include:

@Api(
  name = "myapi",
  version = "v1",
  clientIds = {Ids.WEB_CLIENT_ID, Ids.ANDROID_CLIENT_ID},
  audiences = {Ids.ANDROID_AUDIENCE}
)

Where those constants are defined as something like:

public class Ids {
  public static final String WEB_CLIENT_ID = "12345.apps.googleusercontent.com";
  public static final String ANDROID_CLIENT_ID = "12345-abc.apps.googleusercontent.com";
  public static final String ANDROID_AUDIENCE = WEB_CLIENT_ID;
}

Using the above values, the code you would use in your Android code is:

credential = GoogleAccountCredential.usingAudience(this,
    "server:client_id:" + Ids.ANDROID_AUDIENCE);

Upvotes: 6

Related Questions