Skip to content

Repository files navigation

AFOAuth2Manager

AFOAuth2Manager is an extension for AFNetworking that simplifies the process of authenticating against an OAuth 2 provider.

Example Usage

Authentication

NSURL *baseURL = [NSURLURLWithString:@"http://example.com/"];
AFOAuth2Manager *OAuth2Manager =
[[AFOAuth2Manager alloc] initWithBaseURL:baseURL
clientID:kClientIDsecret:kClientSecret];
[OAuth2Manager authenticateUsingOAuthWithURLString:@"/oauth/token"username:@"username"password:@"password"scope:@"email"success:^(AFOAuthCredential *credential) {
NSLog(@"Token: %@", credential.accessToken);
}
failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];

Authorizing Requests

AFHTTPRequestOperationManager *manager =
[[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseURL];
[manager.requestSerializer setAuthorizationHeaderFieldWithCredential:credential];
[manager GET:@"/path/to/protected/resource"parameters:nilsuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: %@", responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure: %@", error);
}];

Storing Credentials

[AFOAuthCredential storeCredential:credential
withIdentifier:serviceProviderIdentifier];

Retrieving Credentials

AFOAuthCredential *credential =
[AFOAuthCredential retrieveCredentialWithIdentifier:serviceProviderIdentifier];

Documentation

Documentation for all releases of AFOAuth2Manager are available on CocoaDocs.

Contact

Mattt Thompson

License

AFOAuth2Manager is available under the MIT license. See the LICENSE file for more info.

About

AFNetworking Extension for OAuth 2 Authentication

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages