ios – RestKit OAuth 2密码验证流程

我使用 RestKit与自己的OAuth2提供商.我尝试通过 Resource Owner Password Credentials认证.

任何人都可以提供一些示例代码和最佳实践,通过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

希望这可以帮助!

编辑:

我发现这个代码示例可以帮助您更多:https://github.com/rodchile/RestKit-OAuth2-Client-Example

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...