2013-10-07 196 views
12

我们的网络应用程序不提供Google帐户身份验证。我们已经使用WebApp2认证实施了我们自己的认证:http://webapp-improved.appspot.com/tutorials/auth.html没有Google帐户的Google Cloud端点

我们希望将Cloud Endpoints用作移动应用程序/第三方开发者的API,但我们仍然希望使用oAuth2进行身份验证。

执行此操作需要什么步骤?我们是否需要在AppEngine上设置自己的oAuth服务器,并且Google客户端库是否兼容?

回答

1

你不必做任何事情。我在应用引擎上有一个联合登录应用,我最近添加了一个使用云终端的Android应用。你不需要做任何特别的事情,只需要在你的函数中添加一个User参数。在用户对象中,您将找到您必须授权才能访问数据的用户电子邮件。

@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并测试它

更新:上面的例子仅限于谷歌账号。如果你想要一个不同类型的账户,你可以看看这篇文章: Custom Authentication for Google Cloud Endpoints (instead of OAuth2)

0

谷歌云终点是无状态的,所以如果你不使用谷歌认证,你不能检索用户的电子邮件到终点。

事实上,端点只是http请求,所以你可以通过你所知道的http授权就像一个承载者。您可以完全访问这些信息信息的端点。

我希望它能帮助你。

相关问题