Created
August 7, 2012 00:11
-
-
Save brandoncordell/3279827 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// BCOAuthController.h | |
// | |
// BCOAuthController.h | |
// Bivy | |
// | |
// Created by Brandon Cordell on 8/1/12. | |
// Copyright (c) 2012 lead&rock. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import <WebKit/WebKit.h> | |
static NSString *const kKeychainItemName = @"Basecamp Next OAuth2"; | |
static NSString *const kOAuthClientID = @"8128a3859e0c15a0a7a08c54ef3f10ba2cada31b"; | |
static NSString *const kOAuthClientSecret = @"c85168bdda9660833b576c6f7c785335b597a309"; | |
static NSString *const oAuthAuthorizationBaseURL = @"https://launchpad.37signals.com/authorization/new"; | |
static NSString *const oAuthTokenURL = @"https://launchpad.37signals.com/authorization/token"; | |
static NSString *const oAuthRedirectURL = @"http://soyg.heroku.com"; | |
@interface BCOAuthController : NSWindowController | |
@property (weak) IBOutlet WebView *webView; | |
@property (weak) IBOutlet NSProgressIndicator *loadProgress; | |
- (void)visitOAuthAuthorizationURL; | |
@end | |
// BCOAuthController.m | |
// | |
// BCOAuthController.m | |
// Bivy | |
// | |
// Created by Brandon Cordell on 8/1/12. | |
// Copyright (c) 2012 lead&rock. All rights reserved. | |
// | |
#import "BCOAuthController.h" | |
@implementation BCOAuthController | |
@synthesize webView, loadProgress; | |
- (void)visitOAuthAuthorizationURL | |
{ | |
NSString *oAuthAuthorizationURL = [NSString stringWithFormat:@"%@?client_id=%@&redirect_uri=%@&type=web_server", | |
oAuthAuthorizationBaseURL, | |
kOAuthClientID, | |
oAuthRedirectURL]; | |
[webView setMainFrameURL:oAuthAuthorizationURL]; | |
} | |
#pragma mark - WebFrameLoadDelgate Methods | |
- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame { | |
NSLog(@"%@", loadProgress); | |
[loadProgress startAnimation:nil]; // works here | |
} | |
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame | |
{ | |
[loadProgress stopAnimation:nil]; // NO LONGER NULL HERE!! WOOHOO \o/ | |
NSRange range = | |
[[sender mainFrameURL] rangeOfString:oAuthRedirectURL]; | |
if (range.length > 0) { | |
NSString *oAuthRedirectURLWithRequestParameter = | |
[oAuthRedirectURL stringByAppendingString:@"/?code="]; | |
NSString *verificationCode = [[sender mainFrameURL] | |
stringByReplacingOccurrencesOfString:oAuthRedirectURLWithRequestParameter | |
withString:@""]; | |
NSLog(@"Token is: %@", verificationCode); | |
} | |
} | |
- (void)webView:(WebView *)sender | |
didFailProvisionalLoadWithError:(NSError *)error | |
forFrame:(WebFrame *)frame | |
{ | |
NSLog(@"Error: %@", error); | |
} | |
- (void)webView:(WebView *)sender | |
didFailLoadWithError:(NSError *)error | |
forFrame:(WebFrame *)frame | |
{ | |
NSLog(@"Error: %@", error); | |
} | |
#pragma mark - Object Methods | |
- (void)awakeFromNib { | |
[self visitOAuthAuthorizationURL]; | |
} | |
@end | |
// BCAppDelegate.h | |
// | |
// BCAppDelegate.h | |
// Bivy | |
// | |
// Created by Brandon Cordell on 7/30/12. | |
// Copyright (c) 2012 lead&rock. All rights reserved. | |
// | |
#import <Cocoa/Cocoa.h> | |
#import <WebKit/WebKit.h> | |
#import "INAppStoreWindow.h" | |
#import "BCBasecampAPIClient.h" | |
#import "BCOAuthController.h" | |
@interface BCAppDelegate : NSObject <NSApplicationDelegate> | |
@property (assign) IBOutlet INAppStoreWindow *window; | |
@property (weak) IBOutlet NSView *titleView; | |
@property (weak) IBOutlet NSImageView *avatar; | |
- (IBAction)openSheet:(id)sender; | |
@end | |
// BCAppDelegate.m | |
// | |
// BCAppDelegate.m | |
// Bivy | |
// | |
// Created by Brandon Cordell on 7/30/12. | |
// Copyright (c) 2012 lead&rock. All rights reserved. | |
// | |
#import "BCAppDelegate.h" | |
@implementation BCAppDelegate | |
@synthesize window, titleView, avatar; | |
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification | |
{ | |
self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenPrimary; | |
self.window.titleBarHeight = 45.0; | |
self.window.centerFullScreenButton = YES; | |
self.window.centerTrafficLightButtons = YES; | |
self.window.fullScreenButtonRightMargin = 7.0; | |
self.window.trafficLightButtonsLeftMargin = 7.0; | |
// self.titleView is a an IBOutlet to an NSView that has been configured in IB with everything you want in the title bar | |
self.titleView.frame = self.window.titleBarView.bounds; | |
self.titleView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; | |
[self.window.titleBarView addSubview:self.titleView]; | |
NSImage *_avatar; | |
NSURL *avatarUrl = [NSURL URLWithString:@"http://asset0.37img.com/global/76fe2e59c667a1cb64a34bf0e6d711e5e4f3ead280d5aade4fff272a8b20011f847b16cbc2a1d7e8611345c0c755a0299fb8e6bb5cc7f2cbd8e04f4965f64beb4b63ca68a3a96aa64e7777cfb207d6d8/avatar.gif?r=3"]; | |
_avatar = [[NSImage alloc] initWithContentsOfURL:avatarUrl]; | |
[avatar setImage:_avatar]; | |
} | |
- (IBAction)openSheet:(id)sender { | |
BCOAuthController *oAuthController = [[BCOAuthController alloc] | |
initWithWindowNibName:@"OAuthSheetView"]; | |
[NSApp beginSheet:[oAuthController window] | |
modalForWindow:window | |
modalDelegate:self | |
didEndSelector:nil | |
contextInfo:nil]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment