Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RestKit OAuth 2 Password Authentication Flow

Tags:

ios

restkit

I am using RestKit with an own OAuth2 Provider. I try to authenticate via Resource Owner Password Credentials.

Could anyone provide some example code and best practices for requesting protected resources via RestKit in general and authenticating via credentials to get an access token in specific?

Probably ResKit itself is not the best choice?

like image 217
pex Avatar asked Mar 28 '12 16:03

pex


1 Answers

You should check out this link: https://github.com/RestKit/RestKit/wiki/OAuth-Support-on-RestKit

You can try something like this (I do it in my app delegate):

RKObjectManager *manager = [RKObjectManager objectManagerWithBaseURLString:@"http://www.yourdomain.com"];
[manager setSerializationMIMEType:RKMIMETypeJSON];

[[RKClient sharedClient] setAuthenticationType:RKRequestAuthenticationTypeOAuth2];
[[RKClient sharedClient] setUsername:@"username"];
[[RKClient sharedClient] setPassword:@"password"];

Note: I haven't tested it because I use AuthenticationTypeHTTPBasic instead

Hope this helps!

Edit:

I found this code example that can help you more: https://github.com/rodchile/RestKit-OAuth2-Client-Example

like image 78
Luciano Tolfo Avatar answered Oct 13 '22 00:10

Luciano Tolfo