功能User.getUserId()云终端API的用户对象不为空,则返回null终端、为空、对象、功能

2023-09-06 13:33:32 作者:瘾迷者

我有获得用户ID为云终端方法的问题。我曾在我的Andr​​oid客户端使用oauth2认证,并通过了凭据我的服务。下面是类似于我的方法看起来像(简化,使之更加清楚)。

I have a problem with getting the userid for a cloud endpoint method. I have used oauth2 authentication in my android client and passed the credentials to my service. The below is similar to what my method looks like (simplified to make it more clear).

我注意到问题8848 的蟒蛇似乎是非常相似的这个问题。

I note that issue 8848 for python seems to be very similar to this problem.

时相同的问题的Java API的问题呢?该方法

Is the same issue a problem in java api as well? The method

public SuccessCode doSomething(WireFormat wire, User user){
    log.info("User id: "+user.getUserId());
    log.info("Federated identity: "+user.getFederatedIdentity());
    log.info("Email address: "+user.getEmail());
}

将显示空的联合身份,即使在Android客户端证书有oauth2认证进行用户ID。电子邮件地址正确地显示了在日志中。这是所有已部署的应用程序BTW。

will show null for federated identity and userId even though credentials in android client have had oauth2 authentication performed. The email address shows up correctly in the log. This is all on a deployed application btw.

任何人有任何其他建议,什么是错的?任何已知的解决方法的问题?我已经遵循了https://developers.google.com/appengine/docs/java/endpoints/consume_android#making-authenticated-calls设置我的Andr​​oid客户端。

Anybody have any other suggestions as to what is wrong? Any known workarounds for the issue? I have followed the method suggested in https://developers.google.com/appengine/docs/java/endpoints/consume_android#making-authenticated-calls to set up my android client.

推荐答案

你是正确的这一问题8848是一样的原因。根本的问题是语言无关的,会影响运行时。此刻的你不能指望填充在用户对象通过在端点方法参数传入的用户ID字段。

You're correct that issue 8848 is the same cause. The underlying issue is language-agnostic and affects both runtimes. At the moment you shouldn't expect the user ID field populated in a User object passed in via method argument in Endpoints.

一个超级次优的解决办法是坚持了用户对象的数据存储和读取它。重新读对象将具有用户ID包括

A super suboptimal workaround is to persist the User object to the datastore and read it back. The re-read object will have the user ID included.