Simple GitHub OAuth Controller for iOS
platform :ios, '9.0'
pod 'GitHubOAuthController'
Add the files in the GitHubOAuthController folder to your project.
#import "GitHubOAuthController.h"
GitHubOAuthController *oAuthController = [[GitHubOAuthController alloc] initWithClientId:kClientId clientSecret:kClientSecret scope:kScope success:^(NSString *accessToken, NSDictionary *raw) {
NSLog(@"access token: %@ \nraw: %@", accessToken, raw);
} failure:nil];
[oAuthController showModalFromController:self];
- Set url scheme in
.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.dkhamsing.GitHubOAuthDemo</string>
<key>CFBundleURLSchemes</key>
<array>
<string>GitHubOAuthDemo</string>
</array>
</dict>
</array>
-
Set Authorization callback URL in GitHub app https://github.com/settings/developers, i.e.
GitHubOAuthDemo://token
-
Get token in app delegate
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
NSString *source = options[UIApplicationOpenURLOptionsSourceApplicationKey];
if ([source isEqualToString:gh_safariViewService]) {
[[NSNotificationCenter defaultCenter] postNotificationName:kCloseSafariViewController object:nil];
[[GitHubOAuthController sharedInstance] requestAccessTokenWithUrl:url success:^(NSString *accessToken, NSDictionary *raw) {
NSLog(@"oauth with safari view controller: retrieved access token: %@ \nraw: %@", accessToken, raw);
} failure:nil];
return YES;
};
return NO;
}
GitHubOAuthController includes a demo project.
This project was inspired by Caleb Davenport's SimpleAuth.
GitHubOAuthController is available under the MIT license. See the LICENSE file for more info.