https://github.com/dkhamsing/githuboauthcontroller
:octocat: Simple GitHub OAuth Controller for iOS
https://github.com/dkhamsing/githuboauthcontroller
Last synced: about 1 year ago
JSON representation
:octocat: Simple GitHub OAuth Controller for iOS
- Host: GitHub
- URL: https://github.com/dkhamsing/githuboauthcontroller
- Owner: dkhamsing
- License: mit
- Created: 2015-04-30T20:53:30.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-03-26T03:11:15.000Z (about 10 years ago)
- Last Synced: 2025-04-13T03:52:40.072Z (about 1 year ago)
- Language: Objective-C
- Homepage:
- Size: 6.1 MB
- Stars: 12
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# GitHubOAuthController
Simple GitHub OAuth Controller for iOS
[](https://travis-ci.org/dkhamsing/GitHubOAuthController)
[](https://cocoapods.org/pods/GitHubOAuthController)
[](http://cocoadocs.org/docsets/GitHubOAuthController)
[](http://cocoadocs.org/docsets/GitHubOAuthController)

# Installation
## [CocoaPods](https://cocoapods.org/)
``` ruby
platform :ios, '9.0'
pod 'GitHubOAuthController'
```
## Manual
Add the files in the GitHubOAuthController folder to your project.
## Usage
### OAuth with Safari View Controller
- Set url scheme in `.plist`

```
CFBundleURLTypes
CFBundleURLName
com.dkhamsing.GitHubOAuthDemo
CFBundleURLSchemes
githuboauthdemo
```
- Set *Authorization callback URL* in GitHub app https://github.com/settings/developers, i.e. `githuboauthdemo://`
``` objc
// 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 *)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;
}
```
### Traditional in app OAuth
``` objc
#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];
```
# Demo
GitHubOAuthController includes a demo project.
# Thanks
This project was inspired by Caleb Davenport's [SimpleAuth](https://github.com/calebd/SimpleAuth).
# Contact
- [github.com/dkhamsing](https://github.com/dkhamsing)
- [twitter.com/dkhamsing](https://twitter.com/dkhamsing)
# License
GitHubOAuthController is available under the MIT license. See the [LICENSE](LICENSE) file for more info.