Permalink
Browse files

adding sample oauth consumer in cocoa

  • Loading branch information...
1 parent 60eae83 commit 72b08a19ae4a2692d1c1dc0167902311263757c8 Owen Evans committed Feb 20, 2009
Showing with 6,466 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +805 −0 oauth-sample-consumer-cocoa/AccessTokenView.xib
  3. +28 −0 oauth-sample-consumer-cocoa/AccessTokenViewController.h
  4. +104 −0 oauth-sample-consumer-cocoa/AccessTokenViewController.m
  5. +17 −0 oauth-sample-consumer-cocoa/ApplicationController.h
  6. +21 −0 oauth-sample-consumer-cocoa/ApplicationController.m
  7. +29 −0 oauth-sample-consumer-cocoa/English.lproj/Credits.rtf
  8. BIN oauth-sample-consumer-cocoa/English.lproj/InfoPlist.strings
  9. +474 −0 oauth-sample-consumer-cocoa/English.lproj/MainMenu.xib
  10. +269 −0 oauth-sample-consumer-cocoa/English.lproj/MyDocument.xib
  11. +49 −0 oauth-sample-consumer-cocoa/Info.plist
  12. +25 −0 oauth-sample-consumer-cocoa/ManagingViewController.h
  13. +23 −0 oauth-sample-consumer-cocoa/ManagingViewController.m
  14. +21 −0 oauth-sample-consumer-cocoa/MyDocument.h
  15. +112 −0 oauth-sample-consumer-cocoa/MyDocument.m
  16. +1 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Headers
  17. +1 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/OAuthConsumer
  18. +1 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Resources
  19. +35 −0 ...sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Headers/NSMutableURLRequest+Parameters.h
  20. +34 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Headers/NSString+URLEncoding.h
  21. +34 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Headers/NSURL+Base.h
  22. +40 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Headers/OAConsumer.h
  23. +45 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Headers/OADataFetcher.h
  24. +32 −0 ...h-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Headers/OAHMAC_SHA1SignatureProvider.h
  25. +65 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Headers/OAMutableURLRequest.h
  26. +31 −0 ...h-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Headers/OAPlaintextSignatureProvider.h
  27. +45 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Headers/OARequestParameter.h
  28. +43 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Headers/OAServiceTicket.h
  29. +34 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Headers/OASignatureProviding.h
  30. +41 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Headers/OAToken.h
  31. +19 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Headers/OAToken_KeychainExtensions.h
  32. +38 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Headers/OAuthConsumer.h
  33. BIN oauth-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/OAuthConsumer
  34. BIN ...ample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Resources/English.lproj/InfoPlist.strings
  35. +22 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Versions/A/Resources/Info.plist
  36. +1 −0 oauth-sample-consumer-cocoa/OAuthConsumer.framework/Versions/Current
  37. +16 −0 oauth-sample-consumer-cocoa/PreferenceController.h
  38. +14 −0 oauth-sample-consumer-cocoa/PreferenceController.m
  39. +169 −0 oauth-sample-consumer-cocoa/Preferences.xib
  40. +653 −0 oauth-sample-consumer-cocoa/RequestTokenView.xib
  41. +26 −0 oauth-sample-consumer-cocoa/RequestTokenViewController.h
  42. +90 −0 oauth-sample-consumer-cocoa/RequestTokenViewController.m
  43. +15 −0 oauth-sample-consumer-cocoa/ViewParent.h
  44. +14 −0 oauth-sample-consumer-cocoa/ViewParent.m
  45. +14 −0 oauth-sample-consumer-cocoa/main.m
  46. BIN oauth-sample-consumer-cocoa/oauth-sample-consumer.xcodeproj/TemplateIcon.icns
  47. +1,467 −0 oauth-sample-consumer-cocoa/oauth-sample-consumer.xcodeproj/owen.mode1v3
  48. +1,064 −0 oauth-sample-consumer-cocoa/oauth-sample-consumer.xcodeproj/owen.pbxuser
  49. +377 −0 oauth-sample-consumer-cocoa/oauth-sample-consumer.xcodeproj/project.pbxproj
  50. +7 −0 oauth-sample-consumer-cocoa/oauth-sample-consumer_Prefix.pch
View
@@ -5,3 +5,4 @@
bin
obj
*.user
+build

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,28 @@
+//
+// AccessTokenViewController.h
+// oauth-sample-consumer
+//
+// Created by Owen Evans on 20/02/2009.
+// Copyright 2009 Xero.com. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+#import <OAuthConsumer/OAuthConsumer.h>
+#import "ManagingViewController.h"
+
+
+@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;
+-(IBAction) validateAccessToken:(id)sender;
+
+@end
@@ -0,0 +1,104 @@
+//
+// AccessTokenViewController.m
+// oauth-sample-consumer
+//
+// Created by Owen Evans on 20/02/2009.
+// Copyright 2009 Xero.com. All rights reserved.
+//
+
+#import "AccessTokenViewController.h"
+
+
+@implementation AccessTokenViewController
+-(id) init
+{
+ if(![super initWithNibName:@"AccessTokenView" bundle:nil])
+ {
+ return nil;
+ }
+ [self setTitle:@"Get Access Token"];
+
+ return self;
+}
+-(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];
+ 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"];
+ 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"];
+ NSLog(@"Created Request");
+ OADataFetcher *fetcher = [[OADataFetcher alloc]init];
+ NSLog(@"Created fetcher");
+ [fetcher fetchDataWithRequest:request
+ delegate:self
+ didFinishSelector:@selector(accessTokenTicket:didFinishWithData:)
+ didFailSelector:@selector(accessTokenTicket:didFailWithError:)];
+ NSLog(@"initialised fetcher");
+ [fetcher release];
+ [request release];
+ [consumer release];
+}
+-(void) accessTokenTicket: (OAServiceTicket *) ticket
+didFinishWithData:(NSData *)data
+{
+ NSLog(@"Got Access ticket");
+ if(ticket.didSucceed)
+ {
+ NSLog(@"Ticket succeeded");
+ NSString *responseBody = [[NSString alloc] initWithData:data
+ encoding:NSUTF8StringEncoding];
+ OAToken *accessToken = [[OAToken alloc] initWithHTTPResponseBody:responseBody];
+ NSLog(@"Got Ticket Key %@ and secret %@",[accessToken key],[accessToken secret]);
+ [accessTokenKey setStringValue:[accessToken key]];
+ [accessTokenSecret setStringValue:[accessToken secret]];
+ }
+ else
+ {
+ NSLog(@"Ticket didn't succeed");
+ }
+}
+-(void) accessTokenTicket: (OAServiceTicket *) ticket
+ didFailWithError:(NSError *)error
+{
+ NSLog(@"Access token request returned error");
+ NSLog(@"Error = %@",[error localizedDescription]);
+
+}
+-(IBAction) validateAccessToken:(id)sender
+{
+ NSString *urlString = [NSString stringWithFormat:@"http://172.19.105.240/Account/AuthoriseRequestToken?oauth_token=%@",[requestTokenKey stringValue]];
+ NSURL *url = [NSURL URLWithString:urlString];
+ [[NSWorkspace sharedWorkspace] openURL:url];
+
+}
+@end
@@ -0,0 +1,17 @@
+//
+// ApplicationController.h
+// oauth-sample-consumer
+//
+// Created by Owen Evans on 20/02/2009.
+// Copyright 2009 Xero.com. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+#import "PreferenceController.h"
+
+@interface ApplicationController : NSObject {
+ PreferenceController *preferenceController;
+
+}
+-(IBAction) showPreferenceController:(id)sender;
+@end
@@ -0,0 +1,21 @@
+//
+// ApplicationController.m
+// oauth-sample-consumer
+//
+// Created by Owen Evans on 20/02/2009.
+// Copyright 2009 Xero.com. All rights reserved.
+//
+
+#import "ApplicationController.h"
+
+
+@implementation ApplicationController
+
+-(IBAction) showPreferenceController:(id)sender
+{
+ if(!preferenceController){
+ preferenceController = [[PreferenceController alloc]init];
+ }
+ [preferenceController showWindow:self];
+}
+@end
@@ -0,0 +1,29 @@
+{\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;}
+{\colortbl;\red255\green255\blue255;}
+\paperw9840\paperh8400
+\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
+
+\f0\b\fs24 \cf0 Engineering:
+\b0 \
+ Some people\
+\
+
+\b Human Interface Design:
+\b0 \
+ Some other people\
+\
+
+\b Testing:
+\b0 \
+ Hopefully not nobody\
+\
+
+\b Documentation:
+\b0 \
+ Whoever\
+\
+
+\b With special thanks to:
+\b0 \
+ Mom\
+}
Binary file not shown.
Oops, something went wrong.

0 comments on commit 72b08a1

Please sign in to comment.