GROAuth2SessionManager is an extension for AFNetworking that greatly simplifies the process of authenticating against an OAuth 2 provider. It is based in the AFOAuth2Client, but with some changes to support AFNetworking 2.
NSURL *url = [NSURL URLWithString:@"http://example.com/"];
GROAuth2SessionManager *sessionManager = [GROAuth2SessionManager managerWithBaseURL:url clientID:kClientID secret:kClientSecret];
[sessionManager authenticateUsingOAuthWithPath:@"/oauth/token"
username:@"username"
password:@"password"
scope:@"email"
success:^(AFOAuthCredential *credential) {
NSLog(@"I have a token! %@", credential.accessToken);
[AFOAuthCredential storeCredential:credential withIdentifier:oauthClient.serviceProviderIdentifier];
}
failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
Documentation for all releases of GROAuth2SessionManager, including the latest, are available on CocoaDocs.
Gabriel Rinaldi
- https://github.com/gabrielrinaldi
- http://twitter.com/gabriel_rinaldi
- [email protected]
Mattt Thompson
GROAuth2SessionManager is available under the MIT license. See the LICENSE file for more info.