TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Mar 2016 |
Maintained by Daniel Khamsing.
Simple GitHub OAuth Controller for iOS
Add the files in the GitHubOAuthController folder to your project.
.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.dkhamsing.GitHubOAuthDemo</string>
<key>CFBundleURLSchemes</key>
<array>
<string>githuboauthdemo</string>
</array>
</dict>
</array>
githuboauthdemo://
// configure (get redirectUri from plist)
[[GitHubOAuthController sharedInstance] configureForSafariViewControllerWithClientId:kClientId clientSecret:kClientSecret redirectUri:redirectUri scope:kScope];
// show login
[[GitHubOAuthController sharedInstance] presentOAuthSafariLoginFromController:self];
// get access token
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
NSString *source = options[UIApplicationOpenURLOptionsSourceApplicationKey];
if ([source isEqualToString:gh_safariViewService]) {
[[GitHubOAuthController sharedInstance] handleOpenUrl:url options:options success:^(NSString *accessToken, NSDictionary *raw) {
NSLog(@"oauth with safari view controller: retrieved access token: %@ \nraw: %@", accessToken, raw);
} failure:nil];
};
return NO;
}
#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];
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.