ios - 通过 GTMOAuth 使用 REST api 让代理在成功登录保管箱时进行回调

标签 ios rest oauth restful-authentication dropbox-api

我已使用 GTMOAuth 成功登录到保管箱,但一旦返回响应,我似乎无法让委托(delegate)回调 我有这个代码可以登录..

NSURL *requestURL = [NSURL URLWithString:@"https://api.dropbox.com/1/oauth/request_token"];
NSURL *accessURL = [NSURL URLWithString:@"https://api.dropbox.com/1/oauth/access_token"];
NSURL *authorizeURL = [NSURL URLWithString:@"https://www.dropbox.com/1/oauth/authorize"];
NSString *scope = nil;

GTMOAuthAuthentication *auth = [self authForTwitter];
if (auth == nil) {
// perhaps display something friendlier in the UI?
 NSAssert(NO, @"A valid consumer key and consumer secret are required for signing in to Twitter");
}

// set the callback URL to which the site should redirect, and for which
// the OAuth controller should look to determine when sign-in has
// finished or been canceled
//
// This URL does not need to be for an actual web page; it will not be
// loaded
[auth setCallback:@"https://www.dropbox.com"];

NSString *keychainItemName = nil;
if ([self shouldSaveInKeychain]) {
  keychainItemName = kTwitterKeychainItemName;
}

// Display the autentication view.
GTMOAuthViewControllerTouch *viewController;
viewController = [[[GTMOAuthViewControllerTouch alloc] initWithScope:scope
             language:nil
      requestTokenURL:requestURL
     authorizeTokenURL:authorizeURL
       accessTokenURL:accessURL
       authentication:auth
       appServiceName:keychainItemName
             delegate:self
     finishedSelector:@selector(viewController:finishedWithAuth:error:)] autorelease];

// We can set a URL for deleting the cookies after sign-in so the next time
// the user signs in, the browser does not assume the user is already signed
// in
[viewController setBrowserCookiesURL:[NSURL URLWithString:@"http://api.dropbox.com/"]];

// You can set the title of the navigationItem of the controller here, if you want.

[[self navigationController] pushViewController:viewController animated:YES];

我尝试过编辑库的内容,但没有成功。

最佳答案

遇到同样的问题。经过一些调试后,问题似乎是回调 URL 未包含在“6.2.1. 消费者将用户引导至服务提供商”步骤 ( http://oauth.net/core/1.0a/#auth_step2 ) 中。根据 OAuth 规范,它不应该,但 Dropbox 要求它执行重定向。

为了测试,我像这样更改了 GTMOAuthAuthentication.m:

+ (NSArray *)tokenAuthorizeKeys {
  // keys for opening the authorize page, http://oauth.net/core/1.0a/#auth_step2
  NSArray *keys = [NSArray arrayWithObjects:
                   kOAuthTokenKey,
                   // extensions
                   kOAuthDomainKey,
                   kOAuthHostedDomainKey,
                   kOAuthLanguageKey,
                   kOAuthMobileKey,
                   kOAuthScopeKey,
                   kOAuthCallbackKey, // !pi! 20120313 dropbox testing
                   nil];
  return keys;
}

即还将回调 URL 添加到此步骤。现在 GTMOAuth 可以与 Dropbox 配合使用。

应该有更好的解决方案来做到这一点,但我只是测试 GTMOAuth/RESTKit,这对我来说已经足够了。

关于ios - 通过 GTMOAuth 使用 REST api 让代理在成功登录保管箱时进行回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9411695/

相关文章:

iOS - 绘制数千个符号的最佳方式

ios - 有人根据 RACSignal 制作了自更新可变 TableView 吗?

rest - 为什么在隐式授权流程中,授权服务器绝不能发出刷新 token

node.js - Google Oauth 给出代码兑换错误

ios - 从 LinkedIn API 获取电子邮件地址

ios - 在iOS8中获取contactID时出错-崩溃

ios - 打印 UIView,但不是通过渲染为位图图像

java - Spring @DateTimeFormat 在将 @PathVariable 转换为 Date 时正在更改时区

asp.net-mvc - Web API 2 需要尾部斜杠才能使自定义属性路由工作

php - Google Oauth 2.0 检查我的刷新访问 token 是否过期