我正在使用RestKit与自己的OAuth2提供程序。我尝试通过Resource Owner Password Credentials进行身份验证。RestKit OAuth 2密码验证流程
任何人都可以提供一些示例代码和最佳实践,通过一般的RestKit请求受保护资源并通过凭证进行身份验证以获取特定的访问令牌吗?
可能ResKit本身不是最好的选择?
我正在使用RestKit与自己的OAuth2提供程序。我尝试通过Resource Owner Password Credentials进行身份验证。RestKit OAuth 2密码验证流程
任何人都可以提供一些示例代码和最佳实践,通过一般的RestKit请求受保护资源并通过凭证进行身份验证以获取特定的访问令牌吗?
可能ResKit本身不是最好的选择?
你应该检查出此链接:https://github.com/RestKit/RestKit/wiki/OAuth-Support-on-RestKit
你可以尝试这样的事情(我在我的应用程序委托):
RKObjectManager *manager = [RKObjectManager objectManagerWithBaseURLString:@"http://www.yourdomain.com"];
[manager setSerializationMIMEType:RKMIMETypeJSON];
[[RKClient sharedClient] setAuthenticationType:RKRequestAuthenticationTypeOAuth2];
[[RKClient sharedClient] setUsername:@"username"];
[[RKClient sharedClient] setPassword:@"password"];
注意:我没有测试它,因为我使用AuthenticationTypeHTTPBasic而不是
希望这有助于!
编辑:
我发现这个代码示例,可以帮助您更多:
在厌倦了非常复杂的客户端和API之后,我决定自己做,并使用HTTP客户端。
使用RubyMotion和BubbleWrap我已经实现了使用资源所有者密码凭证和API。
params = {
"grant_type" => "password",
"username" => "<USERNAME>",
"password" => "<PASSWORD>",
"client_id" => "<SOMETHING>",
"client_secret" => "<SOMETHING>",
"scope" => "public write"
}
BW::HTTP.post("https://example.com/oauth/token",
:payload => params,
:headers => {}) do |response|
if response.ok?
# Do something
end
end
谢谢你的帮助的例子和参考。 – 2012-11-18 22:33:42
我很高兴帮助你。我也在用RestKit挣扎,所以我知道它是什么样子。 – 2012-11-19 00:39:30
github/rodchile中引用的代码示例根本没有完成,并且使用了在[0.2x文档](http://cocoadocs.org/docsets/RestKit/0.20.3/)中没有看到的类RKClientOAuth。引用的维基页面确实提供了一个完整的解决方案。 – 2014-03-28 08:39:28