【发布时间】: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