【问题标题】:iOS Google cloud Endpoint Authenticated API call using local dev serveriOS Google Cloud Endpoint Authenticated API 调用使用本地开发服务器
【发布时间】:2013-07-28 14:04:09
【问题描述】:

我已经实现了一个云端点,其中一些调用需要 Google 用户身份验证,我现在想使用 iOS 应用程序测试这些调用。到目前为止,我已经按照文档中的所有步骤进行操作,并且我已经设法让用户 OAUTH 登录从应用程序中工作,但是,当我随后尝试对本地开发服务器(本地主机:8888)进行 API 调用时),我收到以下错误:

无法使用方案 http 授权请求

根据我的阅读,auth 不适用于 http 方案并且需要 https。所以我的问题是:是否可以将 https 与本地开发服务器一起使用?或者,还有什么我遗漏的东西可以让我在本地环境中测试用户身份验证吗?

非常感谢任何帮助。 干杯。

【问题讨论】:

  • 您使用什么客户端拨打电话? http 在开发服务器中可以正常工作。
  • @bossylobster 我正在从 iOS 应用程序拨打电话。我认为我得到的错误是因为我正在进行经过身份验证的调用(需要 HTTPS),但本地开发服务器只是 HTTP。我的理解不正确吗?谢谢!
  • 开发服务器无法签署https 请求,因为没有证书颁发机构知道您机器上的本地主机。结果,大多数事情都行不通,所以使用http

标签: ios google-app-engine google-oauth google-cloud-endpoints


【解决方案1】:

感谢您的帮助@bossylobster。我一直在本地开发服务器上使用 http,但是,真正的问题是 iOS OAuth2 库不会授权非 https 请求,这意味着我无法在本地测试经过身份验证的调用。

我最终在 iOS OAuth2 库的 GTMOAuth2Authentication 类中找到了一个标志,它允许该库授权所有请求(包括非 https):

// Property indicating if this object will authorize plain http request
// (as well as any non-https requests.) Default is NO, only requests with the
// scheme https are authorized, since security may be compromised if tokens
// are sent over the wire using an unencrypted protocol like http.
@property (assign) BOOL shouldAuthorizeAllRequests;

默认情况下,此标志设置为 false/NO。为了更新这个标志以处理我的请求,我在发出 API 请求之前在 OAUTH 回调方法中更改了它的值:

- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
      finishedWithAuth:(GTMOAuth2Authentication *)auth
                 error:(NSError *)error {
    [self dismissViewControllerAnimated:YES completion:nil];

    if (error != nil) {
        // Authentication failed
        ...
    } else {
        // Authentication succeeded
        ...

        // TODO: for development purposes only to use non-https....remove for release.
        auth.shouldAuthorizeAllRequests = YES;

        // Make some API calls
        ...
    }
}

一旦我做了这个改变,iOS 库就会授权非 https 请求到本地开发服务器。请务必注意,此标志只能用于开发目的。

【讨论】:

    猜你喜欢
    • 2017-04-22
    • 1970-01-01
    • 2017-06-09
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 2014-07-21
    • 1970-01-01
    相关资源
    最近更新 更多