GROAuth2SessionManager 是 AFNetworking 的扩展,它大大简化了对 OAuth 2 提供商的认证过程。它基于 AFOAuth2Client,但对 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);
}];
GROAuth2SessionManager 的所有版本,包括最新版本,在 CocoaDocs 上有提供。
Gabriel Rinaldi
Mattt Thompson
GROAuth2SessionManager 可在 MIT 许可下获得。有关更多信息,请参阅 LICENSE 文件。