-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Conrad Kramer
committed
Jun 15, 2016
0 parents
commit b847f21
Showing
59 changed files
with
3,715 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
xcuserdata | ||
Carthage/Build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "Carthage/Checkouts/xcconfigs"] | ||
path = Carthage/Checkouts/xcconfigs | ||
url = https://github.com/jspahrsummers/xcconfigs.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github "jspahrsummers/xcconfigs" ~> 0.9 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github "jspahrsummers/xcconfigs" "0.9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// AppDelegate.h | ||
// WFOAuth2 | ||
// | ||
// Created by Conrad Kramer on 3/24/16. | ||
// Copyright © 2016 DeskConnect, Inc. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface AppDelegate : UIResponder <UIApplicationDelegate> | ||
|
||
@property (strong, nonatomic) UIWindow *window; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// AppDelegate.m | ||
// WFOAuth2 | ||
// | ||
// Created by Conrad Kramer on 3/24/16. | ||
// Copyright © 2016 DeskConnect, Inc. All rights reserved. | ||
// | ||
|
||
#import "AppDelegate.h" | ||
#import "ViewController.h" | ||
|
||
@implementation AppDelegate | ||
|
||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | ||
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | ||
self.window.rootViewController = [[ViewController alloc] init]; | ||
[self.window makeKeyAndVisible]; | ||
|
||
return YES; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM"> | ||
<dependencies> | ||
<deployment identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/> | ||
</dependencies> | ||
<scenes> | ||
<!--View Controller--> | ||
<scene sceneID="EHf-IW-A2E"> | ||
<objects> | ||
<viewController id="01J-lp-oVM" sceneMemberID="viewController"> | ||
<layoutGuides> | ||
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/> | ||
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/> | ||
</layoutGuides> | ||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3"> | ||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="53" y="375"/> | ||
</scene> | ||
</scenes> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// Demo.xcconfig | ||
// WFOAuth2 | ||
// | ||
// Created by Conrad Kramer on 3/24/16. | ||
// Copyright © 2016 DeskConnect, Inc. All rights reserved. | ||
// | ||
|
||
#include "../Carthage/Checkouts/xcconfigs/iOS/iOS-Application.xcconfig" | ||
|
||
PRODUCT_NAME = Demo | ||
INFOPLIST_FILE = Demo/Info.plist | ||
PRODUCT_BUNDLE_IDENTIFIER = com.deskconnect.WFOAuth2.demo | ||
ALWAYS_SEARCH_USER_PATHS = NO | ||
CLANG_ENABLE_MODULES = YES | ||
CLANG_ENABLE_OBJC_ARC = YES | ||
|
||
ONLY_ACTIVE_ARCH[config=Debug] = YES | ||
GCC_OPTIMIZATION_LEVEL[config=Debug] = 0 | ||
COPY_PHASE_STRIP[config=Debug] = NO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>LSRequiresIPhoneOS</key> | ||
<true/> | ||
<key>UILaunchStoryboardName</key> | ||
<string>LaunchScreen</string> | ||
<key>UIRequiredDeviceCapabilities</key> | ||
<array> | ||
<string>armv7</string> | ||
</array> | ||
<key>UISupportedInterfaceOrientations</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
<string>UIInterfaceOrientationLandscapeLeft</string> | ||
<string>UIInterfaceOrientationLandscapeRight</string> | ||
</array> | ||
<key>UISupportedInterfaceOrientations~ipad</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
<string>UIInterfaceOrientationPortraitUpsideDown</string> | ||
<string>UIInterfaceOrientationLandscapeLeft</string> | ||
<string>UIInterfaceOrientationLandscapeRight</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// LoginViewController.h | ||
// WFOAuth2 | ||
// | ||
// Created by Conrad Kramer on 3/25/16. | ||
// Copyright © 2016 DeskConnect, Inc. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import <WFOAuth2/WFOAuth2.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@class LoginViewController; | ||
|
||
@protocol LoginViewControllerDelegate <NSObject> | ||
@optional | ||
- (void)loginViewController:(LoginViewController *)loginViewController didAuthenticateWithCredential:(WFOAuth2Credential *)credential; | ||
- (void)loginViewController:(LoginViewController *)loginViewController didFailWithError:(nullable NSError *)error; | ||
- (void)loginViewControllerDidCancel:(LoginViewController *)loginViewController; | ||
@end | ||
|
||
@interface LoginViewController : UIViewController | ||
|
||
@property (nonatomic, weak) id<LoginViewControllerDelegate> delegate; | ||
|
||
- (instancetype)init NS_UNAVAILABLE; | ||
- (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil NS_UNAVAILABLE; | ||
- (instancetype)initWithSessionManager:(WFOAuth2SessionManager<WFOAuth2ProviderSessionManager> *)sessionManager scope:(nullable NSString *)scope redirectURI:(nullable NSURL *)redirectURI; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// LoginViewController.m | ||
// WFOAuth2 | ||
// | ||
// Created by Conrad Kramer on 3/25/16. | ||
// Copyright © 2016 DeskConnect, Inc. All rights reserved. | ||
// | ||
|
||
#import "LoginViewController.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface LoginViewController () | ||
|
||
@property (nonatomic, readonly, strong) WKWebView *webView; | ||
|
||
@end | ||
|
||
static void *LoginViewControllerTitleContext = &LoginViewControllerTitleContext; | ||
|
||
@implementation LoginViewController | ||
|
||
- (instancetype)initWithSessionManager:(WFOAuth2SessionManager<WFOAuth2ProviderSessionManager> *)sessionManager scope:(nullable NSString *)scope redirectURI:(nullable NSURL *)redirectURI { | ||
self = [super initWithNibName:nil bundle:nil]; | ||
if (!self) | ||
return nil; | ||
|
||
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPressed:)]; | ||
|
||
__weak __typeof__(self) weakSelf = self; | ||
_webView = [sessionManager authorizationWebViewWithScope:scope redirectURI:redirectURI completionHandler:^(WFOAuth2Credential * __nullable credential, NSError * __nullable error) { | ||
id<LoginViewControllerDelegate> delegate = weakSelf.delegate; | ||
|
||
if (credential) { | ||
if ([delegate respondsToSelector:@selector(loginViewController:didAuthenticateWithCredential:)]) { | ||
[delegate loginViewController:self didAuthenticateWithCredential:credential]; | ||
} | ||
} else { | ||
if ([delegate respondsToSelector:@selector(loginViewController:didFailWithError:)]) { | ||
[delegate loginViewController:self didFailWithError:error]; | ||
} | ||
} | ||
}]; | ||
|
||
[self addObserver:self forKeyPath:@"webView.title" options:0 context:LoginViewControllerTitleContext]; | ||
|
||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
[self addObserver:self forKeyPath:@"webView.title" options:0 context:LoginViewControllerTitleContext]; | ||
} | ||
|
||
- (void)observeValueForKeyPath:(nullable NSString *)keyPath ofObject:(nullable id)object change:(nullable NSDictionary *)change context:(nullable void *)context { | ||
if (context == LoginViewControllerTitleContext) { | ||
self.title = self.webView.title; | ||
} else { | ||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; | ||
} | ||
} | ||
|
||
- (void)loadView { | ||
[super loadView]; | ||
|
||
WKWebView *webView = self.webView; | ||
webView.frame = self.view.bounds; | ||
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); | ||
[self.view addSubview:webView]; | ||
} | ||
|
||
- (void)cancelPressed:(id)sender { | ||
if ([self.delegate respondsToSelector:@selector(loginViewControllerDidCancel:)]) | ||
[self.delegate loginViewControllerDidCancel:self]; | ||
} | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// ViewController.h | ||
// WFOAuth2 | ||
// | ||
// Created by Conrad Kramer on 3/24/16. | ||
// Copyright © 2016 DeskConnect, Inc. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface ViewController : UIViewController | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// | ||
// ViewController.m | ||
// WFOAuth2 | ||
// | ||
// Created by Conrad Kramer on 3/24/16. | ||
// Copyright © 2016 DeskConnect, Inc. All rights reserved. | ||
// | ||
|
||
#import "ViewController.h" | ||
#import "LoginViewController.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface ViewController () <LoginViewControllerDelegate> | ||
|
||
@end | ||
|
||
@implementation ViewController | ||
|
||
- (void)loadView { | ||
[super loadView]; | ||
|
||
self.view.backgroundColor = [UIColor whiteColor]; | ||
|
||
UIButton *googleButton = [UIButton buttonWithType:UIButtonTypeSystem]; | ||
googleButton.translatesAutoresizingMaskIntoConstraints = NO; | ||
[googleButton setTitle:@"Login to Google" forState:UIControlStateNormal]; | ||
[googleButton addTarget:self action:@selector(googlePressed:) forControlEvents:UIControlEventTouchUpInside]; | ||
[self.view addSubview:googleButton]; | ||
|
||
UIButton *slackButton = [UIButton buttonWithType:UIButtonTypeSystem]; | ||
slackButton.translatesAutoresizingMaskIntoConstraints = NO; | ||
[slackButton setTitle:@"Login to Slack" forState:UIControlStateNormal]; | ||
[slackButton addTarget:self action:@selector(slackPressed:) forControlEvents:UIControlEventTouchUpInside]; | ||
[self.view addSubview:slackButton]; | ||
|
||
UIButton *uberButton = [UIButton buttonWithType:UIButtonTypeSystem]; | ||
uberButton.translatesAutoresizingMaskIntoConstraints = NO; | ||
[uberButton setTitle:@"Login to Uber" forState:UIControlStateNormal]; | ||
[uberButton addTarget:self action:@selector(uberPressed:) forControlEvents:UIControlEventTouchUpInside]; | ||
[self.view addSubview:uberButton]; | ||
|
||
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:googleButton attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]]; | ||
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:googleButton attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:0.8f constant:0.0f]]; | ||
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:slackButton attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]]; | ||
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:slackButton attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f]]; | ||
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:uberButton attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]]; | ||
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:uberButton attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.2f constant:0.0f]]; | ||
} | ||
|
||
- (void)googlePressed:(nullable id)sender { | ||
WFGoogleOAuth2SessionManager *sessionManager = [[WFGoogleOAuth2SessionManager alloc] initWithClientID:@"266399808145-3avt9dudaqe71j6lr8haqigudqi91lf5.apps.googleusercontent.com" clientSecret:nil]; | ||
[self loginWithSessionManager:sessionManager scope:WFGoogleProfileScope redirectURI:[NSURL URLWithString:WFGoogleNativeRedirectURIString]]; | ||
} | ||
|
||
- (void)slackPressed:(nullable id)sender { | ||
WFSlackOAuth2SessionManager *sessionManager = [[WFSlackOAuth2SessionManager alloc] initWithClientID:@"3214730525.4155085303" clientSecret:@"bac7521cf39042b46b35978b045d5ea0"]; | ||
[self loginWithSessionManager:sessionManager scope:WFSlackChannelWriteScope redirectURI:[NSURL URLWithString:@"https://localhost"]]; | ||
} | ||
|
||
- (void)uberPressed:(nullable id)sender { | ||
WFUberOAuth2SessionManager *sessionManager = [[WFUberOAuth2SessionManager alloc] initWithClientID:@"FVZC8i9VfAn2DIi0TdBG0-I5T7RcU3_j" clientSecret:@"8mj8sI-liVAmhSe8duMGQO2SKqPAnGeMDgzuUXyB"]; | ||
[self loginWithSessionManager:sessionManager scope:WFUberUserProfileScope redirectURI:[NSURL URLWithString:@"https://localhost"]]; | ||
} | ||
|
||
- (void)loginWithSessionManager:(WFOAuth2SessionManager<WFOAuth2ProviderSessionManager> *)sessionManager scope:(nullable NSString *)scope redirectURI:(nullable NSURL *)redirectURI { | ||
LoginViewController *loginViewController = [[LoginViewController alloc] initWithSessionManager:sessionManager scope:scope redirectURI:redirectURI]; | ||
loginViewController.delegate = self; | ||
|
||
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:loginViewController]; | ||
navigationController.modalPresentationStyle = UIModalPresentationFormSheet; | ||
[self presentViewController:navigationController animated:YES completion:nil]; | ||
} | ||
|
||
- (void)loginViewController:(LoginViewController *)loginViewController didAuthenticateWithCredential:(WFOAuth2Credential *)credential { | ||
[loginViewController dismissViewControllerAnimated:YES completion:^{ | ||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Access Token" message:credential.accessToken preferredStyle:UIAlertControllerStyleAlert]; | ||
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]]; | ||
[self presentViewController:alertController animated:YES completion:nil]; | ||
}]; | ||
} | ||
|
||
- (void)loginViewController:(LoginViewController *)loginViewController didFailWithError:(nullable NSError *)error { | ||
[loginViewController dismissViewControllerAnimated:YES completion:^{ | ||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error" message:error.localizedDescription preferredStyle:UIAlertControllerStyleAlert]; | ||
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]]; | ||
[self presentViewController:alertController animated:YES completion:nil]; | ||
}]; | ||
} | ||
|
||
- (void)loginViewControllerDidCancel:(LoginViewController *)loginViewController { | ||
[loginViewController dismissViewControllerAnimated:YES completion:nil]; | ||
} | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// main.m | ||
// WFOAuth2 | ||
// | ||
// Created by Conrad Kramer on 3/24/16. | ||
// Copyright © 2016 DeskConnect, Inc. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import "AppDelegate.h" | ||
|
||
int main(int argc, char * argv[]) { | ||
@autoreleasepool { | ||
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); | ||
} | ||
} |
Oops, something went wrong.