谷歌云端点没有谷歌帐户 [英] Google Cloud Endpoints without Google Accounts
问题描述
我们的Web应用程序不提供谷歌帐户的认证。我们已经实现了使用webapp2的身份验证自己的身份验证:<一href=\"http://webapp-improved.appspot.com/tutorials/auth.html\">http://webapp-improved.appspot.com/tutorials/auth.html.
Our web application does not offer Google Accounts authentication. We have implemented our own authentication using WebApp2 Authentication: http://webapp-improved.appspot.com/tutorials/auth.html.
我们希望使用云作为端点移动应用/第三方开发者的API,但我们仍希望使用的oauth2进行身份验证。
We'd like to use Cloud Endpoints as an API for mobile apps/third party developers but we would still like to use oAuth2 for authentication.
什么是实现这一要求的步骤?我们是否需要设置AppEngine上和我们自己的OAuth服务器将在谷歌客户端库兼容?
What are the steps required to implement this? Do we need to setup our own oAuth server on AppEngine and will the Google client libraries be compatible?
推荐答案
您不必做任何事情。我有一个联邦登录上应用引擎应用,在那里我最近增加了使用云端点的Android应用程序。你没有做什么特别的,只是把用户参数的功能。在用户对象,你会发现,你必须按顺序访问数据授权用户的电子邮件。
You don't have to do anything. I have a federated log-in app on app-engine where i recently added an Android app that uses Cloud Endpoints. You don't have to do anything special, just put a User parameter to your function. In the User object you will find the user email that you have to Authorize in order to access the data.
@Api(name = "my_api",
version = "v1",
scopes = {"https://www.googleapis.com/auth/userinfo.email"},
clientIds = {Constants.AUTH_CLIENT,
Constants.AUTH_CLIENT_APIEXPLORER})
public class MyEndpoint {
@ApiMethod(name = "fistEndpoint")
public ResponseObject fistEndpoint(User user) throws OAuthRequestException {
if (user == null) {
throw new OAuthRequestException("Access denied!");
}
String email = user.getEmail();
//Authorize the request here
//make the ResponseObject and return it
}
}
在创建端点,请访问:
https://your-app.appspot.com/_ah/api/explorer 并对其进行测试
After you created the endpoint visit: https://your-app.appspot.com/_ah/api/explorer and test it
更新: 上面的例子仅限于谷歌帐户即可。如果你想要一个不同类型的帐户,你可以看看这篇文章:
<一href=\"http://stackoverflow.com/questions/16970327/custom-authentication-for-google-cloud-endpoints-instead-of-oauth2?rq=1\">Custom身份验证谷歌云端点(代替的OAuth2)
UPDATED: The example above is restricted to Google accounts. If you want a different type account you can check out this post: Custom Authentication for Google Cloud Endpoints (instead of OAuth2)
这篇关于谷歌云端点没有谷歌帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!