【问题标题】:Securing API calls GAE endpoints保护 API 调用 GAE 端点
【发布时间】:2015-05-16 21:16:34
【问题描述】:

我正在编写一个移动应用程序作为从服务器获取数据的瘦客户端。我正在使用 Google 应用引擎来托管我的后端并使用他们提供的所有服务。我正在使用端点来公开我的 API。我找到了this tutorial 来保护我的 API。我从 api explorer 进行测试,因为一切正常。如果我不使用 Oauth 2,我将无法使用 API。但是,当我调查 HTTP 标头时,我没有找到“授权:承载”行,该行将持有一次性令牌,该令牌将用于对 API 调用进行身份验证和授权。现在我怀疑我做错了什么,因为通常我必须看到这条线。有一个我的请求的屏幕截图显示它已执行,尽管没有我之前指出的那行。还有一些我的代码部分是由 Android Studio 生成的。

    @ApiMethod(
        name = "get",
        path = "offer/{id}",
        httpMethod = ApiMethod.HttpMethod.GET)
public Offer get(@Named("id") long id, User user) throws NotFoundException, UnauthorizedException {

    if (user == null) throw new UnauthorizedException("User is Not Valid");

    logger.info("Getting Offer with ID: " + id);
    Offer offer = ofy().load().type(Offer.class).id(id).now();
    if (offer == null) {
        throw new NotFoundException("Could not find Offer with ID: " + id);
    }
    return offer;
}

关于为什么包含令牌的行丢失的任何线索?

【问题讨论】:

    标签: android google-app-engine google-cloud-endpoints


    【解决方案1】:

    您可能希望记录 user.getUserId()、user.getNickname() 和 user.getEmail() 以查看发生了什么。

    我认为有 cookie 和其他方式可以存储身份验证信息,因为我很少需要登录两次网站。

    【讨论】:

      猜你喜欢
      • 2019-02-20
      • 2020-11-30
      • 2014-06-30
      • 2020-02-13
      • 2015-08-07
      • 2013-11-28
      • 2016-08-22
      • 2023-03-19
      • 2021-06-25
      相关资源
      最近更新 更多