Skip to content

Instantly share code, notes, and snippets.

@ennioma
Created March 6, 2015 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ennioma/598215f02b695cc520c1 to your computer and use it in GitHub Desktop.
Save ennioma/598215f02b695cc520c1 to your computer and use it in GitHub Desktop.
OAuth2 using doorkeeper + AFOAuth2Manager
/*
https://github.com/gottfrois/doorkeeper-provider-app
curl -i http://localhost:5100/oauth/token -F grant_type="password" -F username="john.smith@myapp.com" -F password="please" -F client_id="5c13e1fdd1007229121176ec372e5d9cda2698f37f243a3965c1176bce1ecd01" -F client_secret=","
*/
NSString *kClientID = @"5c13e1fdd1007229121176ec372e5d9cda2698f37f243a3965c1176bce1ecd01";
NSString *kClientSecret = @"40dfdc7edad96c219a8c948c228eda262a561774be74b8fc0996d9e57f62b771";
NSURL *baseURL = [NSURL URLWithString:@"http://localhost:5100"];
AFOAuth2Manager *OAuth2Manager =
[[AFOAuth2Manager alloc] initWithBaseURL:baseURL
clientID:kClientID
secret:kClientSecret];
NSDictionary *params = @{@"grant_type":@"password", @"username":@"john.smith@myapp.com", @"password":@"please"};
[OAuth2Manager authenticateUsingOAuthWithURLString:@"/oauth/token"
parameters:params
success:^(AFOAuthCredential *credential) {
NSLog(@"Token: %@", credential.accessToken);
}
failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment