感谢您的帮助@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 请求。需要注意的是,这个标志应该只用于开发目的。