Permalink
Browse files

Finished pass one of OAuth Consumer Sample

  • Loading branch information...
1 parent ea12bca commit 01a7839373711e34d9344140f0721f86e6ad10e8 Owen Evans committed Feb 23, 2009
Oops, something went wrong.
@@ -14,15 +14,13 @@
@interface AccessTokenViewController : ManagingViewController {
IBOutlet NSTextField *requestTokenSecret;
IBOutlet NSTextField *requestTokenKey;
- IBOutlet NSTextField *consumerKey;
- IBOutlet NSTextField *consumerSecret;
IBOutlet NSTextField *accessTokenKey;
IBOutlet NSTextField *accessTokenSecret;
}
-(IBAction) getAccessToken:(id)sender;
-(void)accessTokenTicket:(OAServiceTicket *)ticket
didFailWithError:(NSError *) error;
-- (void)accessTokenTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data;
+-(void)accessTokenTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data;
-(IBAction) validateAccessToken:(id)sender;
-
+-(IBAction) goToRequestToken:(id)sender;
@end
@@ -7,7 +7,7 @@
//
#import "AccessTokenViewController.h"
-
+#import "ApplicationController.h"
@implementation AccessTokenViewController
-(id) init
@@ -25,37 +25,33 @@ -(void) loadView
[super loadView];
NSString *consumerKeyValue = [parent getSharedValue:OACConsumerKey];
NSLog(@"Loaded Key from store %@",consumerKeyValue);
- [consumerKey setStringValue:[parent getSharedValue:OACConsumerKey]];
- [consumerSecret setStringValue:[parent getSharedValue:OACConsumerSecret]];
[requestTokenKey setStringValue:[parent getSharedValue:OACRequestTokenKey]];
[requestTokenSecret setStringValue:[parent getSharedValue:OACRequestTokenSecret]];
- [consumerKey setEditable:FALSE];
- [consumerKey setSelectable:FALSE];
- [consumerSecret setEditable:FALSE];
- [consumerSecret setSelectable:FALSE];
[requestTokenKey setEditable:FALSE];
[requestTokenSecret setSelectable:FALSE];
[accessTokenKey setEditable:FALSE];
[accessTokenSecret setSelectable:FALSE];
}
-(IBAction) getAccessToken:(id)sender
{
- NSString *consumerKeyValue = [consumerKey stringValue];
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
+ NSString *consumerKeyValue = [defaults valueForKey:OACConsumerKey];
+ NSString *consumerSecretValue = [defaults valueForKey:OACConsumerSecret];
NSLog(@"Loaded consumer key from screen %@",consumerKeyValue);
- NSString *consumerSecretValue = [consumerSecret stringValue];
NSLog(@"Loaded consumer secret from screen %@",consumerSecretValue);
OAConsumer *consumer = [[OAConsumer alloc] initWithKey:consumerKeyValue secret:consumerSecretValue];
OAToken *requestToken = [[OAToken alloc] initWithKey:[requestTokenKey stringValue] secret:[requestTokenSecret stringValue]];
NSLog(@"created token");
- NSURL *requestUrl = [NSURL URLWithString:@"http://172.19.105.240/oauth/AccessToken"];
+ NSURL *requestUrl = [NSURL URLWithString:[defaults valueForKey:OACAccessTokenUrl]];
NSLog(@"Created URL");
OAMutableURLRequest *request = [[OAMutableURLRequest alloc]initWithURL:requestUrl
consumer:consumer
token:requestToken
realm:nil
signatureProvider:nil];
NSLog(@"Created Mutable URL Request");
- [request setHTTPMethod:@"POST"];
+ [request setHTTPMethod:@"GET"];
NSLog(@"Created Request");
OADataFetcher *fetcher = [[OADataFetcher alloc]init];
NSLog(@"Created fetcher");
@@ -96,9 +92,16 @@ -(void) accessTokenTicket: (OAServiceTicket *) ticket
}
-(IBAction) validateAccessToken:(id)sender
{
- NSString *urlString = [NSString stringWithFormat:@"http://172.19.105.240/Account/AuthoriseRequestToken?oauth_token=%@",[requestTokenKey stringValue]];
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+
+ NSString *urlString = [NSString stringWithFormat:[defaults valueForKey: OACRequestTokenAuthUrl],[requestTokenKey stringValue]];
NSURL *url = [NSURL URLWithString:urlString];
[[NSWorkspace sharedWorkspace] openURL:url];
}
+-(IBAction) goToRequestToken:(id)sender
+{
+
+ [parent setViewName:@"GetRequestToken"];
+}
@end
@@ -9,6 +9,14 @@
#import <Cocoa/Cocoa.h>
#import "PreferenceController.h"
+extern NSString * const OACConsumerKey;
+extern NSString * const OACConsumerSecret;
+extern NSString * const OACRequestTokenKey;
+extern NSString * const OACRequestTokenSecret;
+extern NSString * const OACRequestTokenUrl;
+extern NSString * const OACRequestTokenAuthUrl;
+extern NSString * const OACAccessTokenUrl;
+
@interface ApplicationController : NSObject {
PreferenceController *preferenceController;
@@ -8,14 +8,42 @@
#import "ApplicationController.h"
+NSString * const OACConsumerKey = @"ConsumerKey";
+NSString * const OACConsumerSecret = @"ConsumerSecret";
+NSString * const OACRequestTokenKey = @"RequestTokenKey";
+NSString * const OACRequestTokenSecret = @"RequestTokenSecret";
+NSString * const OACRequestTokenUrl = @"RequestTokenURL";
+NSString * const OACRequestTokenAuthUrl = @"RequestTokenAuthURL";
+NSString * const OACAccessTokenUrl = @"AccessTokenURL";
@implementation ApplicationController
++(void) initialize
+{
+ NSMutableDictionary *defaultValues =[NSMutableDictionary dictionary];
+
+ NSString *requestTokenUrl = @"http://term.ie/oauth/example/request_token.php";
+ NSString *accessTokenUrl = @"http://term.ie/oauth/example/access_token.php";
+ NSString *requestTokenAuthUrl = @"http://term.ie/oauth/example";
+ NSString *consumerKey = @"key";
+ NSString *consumerSecret = @"secret";
+
+ [defaultValues setObject:requestTokenUrl forKey:OACRequestTokenUrl];
+ [defaultValues setObject:accessTokenUrl forKey:OACAccessTokenUrl];
+ [defaultValues setObject:requestTokenAuthUrl forKey:OACRequestTokenAuthUrl];
+ [defaultValues setObject:consumerKey forKey:OACConsumerKey];
+ [defaultValues setObject:consumerSecret forKey:OACConsumerSecret];
+
+ [[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
+
+}
+
+
-(IBAction) showPreferenceController:(id)sender
{
if(!preferenceController){
preferenceController = [[PreferenceController alloc]init];
}
- [preferenceController showWindow:preferenceController];
+ [preferenceController showWindow:self];
}
@end
@@ -8,7 +8,7 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="100023"/>
+ <integer value="100026"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -46,50 +46,12 @@
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSBox" id="766977174">
+ <object class="NSCustomView" id="417140068">
<reference key="NSNextResponder" ref="568628114"/>
- <int key="NSvFlags">18</int>
- <object class="NSMutableArray" key="NSSubviews">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSView" id="111986555">
- <reference key="NSNextResponder" ref="766977174"/>
- <int key="NSvFlags">256</int>
- <string key="NSFrame">{{2, 2}, {616, 605}}</string>
- <reference key="NSSuperview" ref="766977174"/>
- </object>
- </object>
- <string key="NSFrame">{{4, 5}, {620, 625}}</string>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrameSize">{630, 636}</string>
<reference key="NSSuperview" ref="568628114"/>
- <string key="NSOffsets">{0, 0}</string>
- <object class="NSTextFieldCell" key="NSTitleCell">
- <int key="NSCellFlags">67239424</int>
- <int key="NSCellFlags2">0</int>
- <string key="NSContents"/>
- <object class="NSFont" key="NSSupport">
- <string key="NSName">LucidaGrande</string>
- <double key="NSSize">1.100000e+01</double>
- <int key="NSfFlags">3100</int>
- </object>
- <object class="NSColor" key="NSBackgroundColor">
- <int key="NSColorSpace">6</int>
- <string key="NSCatalogName">System</string>
- <string key="NSColorName">textBackgroundColor</string>
- <object class="NSColor" key="NSColor">
- <int key="NSColorSpace">3</int>
- <bytes key="NSWhite">MQA</bytes>
- </object>
- </object>
- <object class="NSColor" key="NSTextColor">
- <int key="NSColorSpace">3</int>
- <bytes key="NSWhite">MCAwLjgwMDAwMDAxAA</bytes>
- </object>
- </object>
- <reference key="NSContentView" ref="111986555"/>
- <int key="NSBorderType">3</int>
- <int key="NSBoxType">0</int>
- <int key="NSTitlePosition">3</int>
- <bool key="NSTransparent">NO</bool>
- <real value="0.000000e+00" key="NSBorderWidth2"/>
+ <string key="NSClassName">NSView</string>
</object>
</object>
<string key="NSFrameSize">{630, 636}</string>
@@ -124,11 +86,11 @@
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
- <string key="label">box</string>
+ <string key="label">view</string>
<reference key="source" ref="512844837"/>
- <reference key="destination" ref="766977174"/>
+ <reference key="destination" ref="417140068"/>
</object>
- <int key="connectionID">100024</int>
+ <int key="connectionID">100027</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
@@ -169,7 +131,7 @@
<reference key="object" ref="568628114"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="766977174"/>
+ <reference ref="417140068"/>
</object>
<reference key="parent" ref="275939982"/>
</object>
@@ -180,8 +142,8 @@
<string key="objectName">Application</string>
</object>
<object class="IBObjectRecord">
- <int key="objectID">100023</int>
- <reference key="object" ref="766977174"/>
+ <int key="objectID">100026</int>
+ <reference key="object" ref="417140068"/>
<reference key="parent" ref="568628114"/>
</object>
</object>
@@ -193,7 +155,7 @@
<string>-1.IBPluginDependency</string>
<string>-2.IBPluginDependency</string>
<string>-3.IBPluginDependency</string>
- <string>100023.IBPluginDependency</string>
+ <string>100026.IBPluginDependency</string>
<string>5.IBEditorWindowLastContentRect</string>
<string>5.IBWindowTemplateEditedContentRect</string>
<string>5.ImportedFromIB2</string>
@@ -209,8 +171,8 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{243, 120}, {630, 636}}</string>
- <string>{{243, 120}, {630, 636}}</string>
+ <string>{{436, 128}, {630, 636}}</string>
+ <string>{{436, 128}, {630, 636}}</string>
<integer value="1" id="5"/>
<string>{{201, 387}, {507, 413}}</string>
<reference ref="5"/>
@@ -239,7 +201,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">100024</int>
+ <int key="maxID">100027</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -252,8 +214,8 @@
<string key="NS.object.0">id</string>
</object>
<object class="NSMutableDictionary" key="outlets">
- <string key="NS.key.0">box</string>
- <string key="NS.object.0">NSBox</string>
+ <string key="NS.key.0">view</string>
+ <string key="NS.object.0">NSView</string>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
@@ -7,10 +7,7 @@
//
#import "ManagingViewController.h"
-NSString * const OACConsumerKey = @"ConsumerKey";
-NSString * const OACConsumerSecret = @"ConsumerSecret";
-NSString * const OACRequestTokenKey = @"RequestTokenKey";
-NSString * const OACRequestTokenSecret = @"RequestTokenSecret";
+
@implementation ManagingViewController
@synthesize managedObjectContext;
@@ -12,7 +12,7 @@
#import "ViewParent.h"
@interface MyDocument : NSPersistentDocument<ViewParent>
{
- IBOutlet NSBox *box;
+ IBOutlet NSView *view;
NSMutableArray *viewControllers;
NSMutableDictionary *sharedValueDictionary;
}
@@ -49,7 +49,7 @@ - (NSString *)windowNibName
-(void) windowControllerDidLoadNib:(NSWindowController *)wc
{
[super windowControllerDidLoadNib:wc];
- [self setView:@"GetRequestToken"];
+ [self setViewName:@"GetRequestToken"];
}
- (void) dealloc
{
@@ -61,7 +61,7 @@ - (void) dealloc
-(void)displayViewController:(ManagingViewController *)vc
{
//try to end editing
- NSWindow *w = [box window];
+ NSWindow *w = [view window];
BOOL ended = [w makeFirstResponder:w];
if(!ended)
{
@@ -70,8 +70,9 @@ -(void)displayViewController:(ManagingViewController *)vc
}
//put the view in the box
NSView *v = [vc view];
- [box setContentView:nil];
- [box setContentView:v];
+ view = v;
+ [w setContentView:nil];
+ [w setContentView:v];
@@ -83,7 +84,7 @@ -(IBAction) changeViewController:(id)sender
[self displayViewController:vc];
}
--(void) setView:(NSString *) viewName
+-(void) setViewName:(NSString *) viewName
{
if([viewName isEqualToString: @"GetRequestToken"])
@@ -7,7 +7,7 @@
//
#import "PreferenceController.h"
-
+#import "ApplicationController.h"
@implementation PreferenceController
@@ -20,13 +20,29 @@ -(id)init
return self;
}
+-(void) windowDidLoad
+{
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ [requestTokenUrl setStringValue:[defaults valueForKey:OACRequestTokenUrl]];
+ [requestAuthUrl setStringValue:[defaults valueForKey:OACRequestTokenAuthUrl]];
+ [accessTokenUrl setStringValue:[defaults valueForKey:OACAccessTokenUrl]];
+ [consumerKey setStringValue:[defaults valueForKey:OACConsumerKey]];
+ [consumerSecret setStringValue:[defaults valueForKey:OACConsumerSecret]];
+}
+
-(IBAction) cancel:(id)sender
{
[self close];
}
+
-(IBAction) savePreferences:(id)sender
{
-
-
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ [defaults setObject:[requestTokenUrl stringValue] forKey:OACRequestTokenUrl];
+ [defaults setObject:[requestAuthUrl stringValue] forKey:OACRequestTokenAuthUrl];
+ [defaults setObject:[accessTokenUrl stringValue] forKey:OACAccessTokenUrl];
+ [defaults setObject:[consumerKey stringValue] forKey:OACConsumerKey];
+ [defaults setObject:[consumerSecret stringValue] forKey:OACConsumerSecret];
+ [self close];
}
@end
Oops, something went wrong.

0 comments on commit 01a7839

Please sign in to comment.