这是一个适合 OAuth2 的 iOS 库。它支持授权使用 OAuth2 的所有网站,例如:smartthings、uber、fitbit、快递等...
https://github.com/lukeredpath/LROAuth2Client:我是基于这个库进行开发的。基本上,它覆盖了 > 80% 的工作。请分享并感谢他。
https://github.com/nicklockwood/Base64:这是我用于此库的 base64 库。
UI
授权
更多内容
要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install
。
声明 OAuthRequestController
NSMutableDictionary *dictService = [NSMutableDictionary dictionary];
[dictService setObject:@"https://www.fitbit.com/oauth2/authorize" forKey:kOAuth_AuthorizeURL];
[dictService setObject:@"https://api.fitbit.com/oauth2/token" forKey:kOAuth_TokenURL];
[dictService setObject:@"YOUR CLIENT ID" forKey:kOAuth_ClientId];
[dictService setObject:@"YOUR SECRET KEY" forKey:kOAuth_Secret];
[dictService setObject:@"YOUR CALLBACK URL" forKey:kOAuth_Callback];
[dictService setObject:@"activity heartrate location nutrition profile settings sleep social weight" forKey:kOAuth_Scope];
OAuthRequestController *oauthController = [[OAuthRequestController alloc] initWithDict:dictService];
oauthController.view.frame = self.view.frame;
oauthController.delegate = self;
[self presentViewController:oauthController animated:YES completion:^{
}];
- (void)didAuthorized:(NSDictionary *)dictResponse {
NSLog(@"%@", dictResponse);
}
OAuth2 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中:
pod "OAuth2"
OAuth2 根据 MIT 许可证提供。有关更多信息,请参阅 LICENSE 文件。