简体   繁体   English

端点用户身份验证

[英]Endpoints User Authentication

I'm trying to access User in one of my endpoints but can't get the magic to happen from Android. 我试图在我的一个端点中访问用户,但无法从Android获得魔力。 The documentation seems to be in a somewhat broken state, seeing how it is just transitioning from the trusted-tester program, and I'm seeing conflicting information, so I'm hoping someone here can help me out. 文档似乎处于一种有点破碎的状态,看到它是如何从可信测试程序转换的,我看到了相互矛盾的信息,所以我希望有人可以帮助我。

I've created my client id for Android in the API console. 我已经在API控制台中为Android创建了我的客户端ID。 I'm specifying it as a client id and audience in my endpoint like so: 我将其指定为我的端点中的客户端ID和受众,如下所示:

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

In my Android activity, I'm creating my credential: 在我的Android活动中,我正在创建我的凭证:

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

and am using that to build my service before making a network call in an AsyncTask: 并在使用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! 在此先感谢您的帮助!

Figured out where I went wrong: 想出我出错的地方:

You have to specify the WEB client id as the audience in @API, and also in Android. 您必须在@API以及Android中将WEB客户端ID指定为受众。 The android client id is only used in the @API clientIds. android客户端ID仅用于@API clientIds。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM