简体   繁体   English

Google Cloud Endpoints自定义身份验证

[英]Google Cloud Endpoints custom Authentication

I am quite new to google cloud endpoints and I would like know how to Use Auth with Endpoints, the tutorial here is good, but I don't understand this thing: 我对google cloud端点非常陌生,我想知道如何对端点使用Auth, 这里的教程很好,但是我不明白这件事:

  • It says, that I should add a user( com.google.appengine.api.users.User ) parameter to backend's methods for auth. 它说,我应该在后端的auth方法中添加一个user( com.google.appengine.api.users.User )参数。 If I want to use android as client part, I should provide GoogleAccountCredential object to make an authenticated call [ 2 ]. 如果我想使用android作为客户端,我应该提供GoogleAccountCredential对象来进行经过身份验证的调用[ 2 ]。 The GoogleAccountCredential is created this way GoogleAccountCredential是通过这种方式创建的
credential = GoogleAccountCredential.usingAudience(this,
"server:client_id:1-web-app.apps.googleusercontent.com");
credential.setSelectedAccountName(accountName);

The accountName is the name of a Google Account, so I assume, that everyone, who has the Google Account and is using my Google Cloud Endpoint application can create the GoogleAccountCredential object and make an authenticated call to backend. accountName是Google帐户的名称,因此,我假设拥有Google帐户并使用我的Google Cloud Endpoint应用程序的每个人都可以创建GoogleAccountCredential对象,并向后端进行经过身份验证的调用。

But there are obviously many methods in my backend, which can be invoked only by some users of my app. 但是我的后端显然有很多方法,这些方法只能由我的应用程序的某些用户调用。 (example: There is a method, which will give me a details about my friend, it's clear that this method can be called only by his friends.). (示例:有一个方法,它将为我提供有关我的朋友的详细信息,很明显,该方法只能由他的朋友调用。) Hence my question is: Is there any way to map the com.google.appengine.api.users.User to some my custom User entity, to be possible to check whether the User is really authorized to call the backend's method and not only to know that the method was called by a User with Google Account ? 因此,我的问题是:有没有办法将com.google.appengine.api.users.User映射到我的自定义User实体,以便可以检查User是否真的有权调用后端的方法,而不仅仅是知道该方法是由具有Google帐户的用户调用的吗? Should I write my custom Authenticator for this, if so, could you advise me how ? 我应该为此编写我的自定义身份验证器吗?

Thank you! 谢谢!

You can set an Authenticator class which will handle the custom authentication. 您可以设置一个Authenticator类,该类将处理自定义身份验证。 https://cloud.google.com/appengine/docs/java/endpoints/javadoc/com/google/api/server/spi/config/Authenticator you just need to set the authenticators param in the @ApiMethod and you can write your own authentication logic https://cloud.google.com/appengine/docs/java/endpoints/javadoc/com/google/api/server/spi/config/Authenticator,您只需要在@ApiMethod中设置身份验证器参数,就可以编写您的自己的认证逻辑

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

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