-
Notifications
You must be signed in to change notification settings - Fork 26
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
Showing
4 changed files
with
141 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 @@ | ||
XAuthTwitterEngineDemo/build/* | ||
*.pbxuser | ||
*.perspectivev3 |
26 changes: 26 additions & 0 deletions
26
XAuthTwitterEngineDemo/Libraries & Headers/ExchangeCredentialsOperation.h
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,26 @@ | ||
// | ||
// ExchangeCredentialsOperation.h | ||
// XAuthTwitterEngineDemo | ||
// | ||
// Created by Aral Balkan on 10/03/2010. | ||
// Copyright 2010 Naklab. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "ExchangeCredentialsOperationDelegate.h" | ||
|
||
@class OAConsumer; | ||
|
||
@interface ExchangeCredentialsOperation : NSOperation { | ||
OAConsumer *_consumer; | ||
NSString *_username; | ||
NSString *_password; | ||
|
||
id <ExchangeCredentialsOperationDelegate> _delegate; | ||
} | ||
|
||
@property (nonatomic, retain) OAConsumer *consumer; | ||
@property (nonatomic, retain) NSString *username, *password; | ||
@property (nonatomic, assign) id <ExchangeCredentialsOperationDelegate> delegate; | ||
|
||
@end |
104 changes: 104 additions & 0 deletions
104
XAuthTwitterEngineDemo/Libraries & Headers/ExchangeCredentialsOperation.m
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,104 @@ | ||
// | ||
// ExchangeCredentialsOperation.m | ||
// XAuthTwitterEngineDemo | ||
// | ||
// Created by Aral Balkan on 10/03/2010. | ||
// Copyright 2010 Naklab. All rights reserved. | ||
// | ||
|
||
#import "ExchangeCredentialsOperation.h" | ||
#import "OAMutableURLRequest.h" | ||
#import "OARequestParameter.h" | ||
#import "OADataFetcher.h" | ||
|
||
@implementation ExchangeCredentialsOperation | ||
|
||
@synthesize consumer = _consumer; | ||
@synthesize username = _username, password = _password; | ||
@synthesize delegate = _delegate; | ||
|
||
- (void)main | ||
{ | ||
// This is running in its own thread: create an autorelease pool. | ||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||
|
||
|
||
// | ||
// Modified from http://github.com/norio-nomura/ntlniph/commit/5ce25d68916cd45254c7ff2ba9b91de4f324899a | ||
// Courtesy of Norio Nomura (@norio_nomura) via Steve Reynolds (@SteveReynolds) | ||
// | ||
// Carry out the xAuth, using the OAuthConsumer library directly. | ||
// | ||
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"]; | ||
|
||
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url | ||
consumer:self.consumer | ||
token:nil // we don't have a Token yet | ||
realm:nil // our service provider doesn't specify a realm | ||
signatureProvider:nil] ; // use the default method, HMAC-SHA1 | ||
|
||
[request setHTTPMethod:@"POST"]; | ||
[request setParameters:[NSArray arrayWithObjects: | ||
[OARequestParameter requestParameterWithName:@"x_auth_mode" value:@"client_auth"], | ||
[OARequestParameter requestParameterWithName:@"x_auth_username" value:self.username], | ||
[OARequestParameter requestParameterWithName:@"x_auth_password" value:self.password], | ||
nil]]; | ||
|
||
|
||
OADataFetcher *dataFetcher = [[OADataFetcher alloc] init]; | ||
DLog(@"HERE HERE HERE"); | ||
[dataFetcher fetchDataWithRequest:request delegate:self didFinishSelector:@selector(setAccessToken:withData:) didFailSelector:@selector(accessTokenTicket:didFailWithError:)]; | ||
[dataFetcher release]; | ||
DLog(@"HERE HERE HERE"); | ||
|
||
[request release]; | ||
DLog(@"HERE HERE HERE"); | ||
|
||
[pool drain]; | ||
DLog(@"HERE HERE HERE"); | ||
} | ||
|
||
// | ||
// Access token fetch failed. | ||
// | ||
- (void) accessTokenTicket:(OAServiceTicket *)ticket didFailWithError:(NSError *) error { | ||
NSLog(@"access token did fail ***************"); | ||
|
||
[self performSelectorOnMainThread:@selector(callDelegateOnMainThreadWithAccessTokenTicket:didFailWithError:) withObject:error waitUntilDone:[NSThread isMainThread]]; | ||
} | ||
|
||
- (void) callDelegateOnMainThreadWithAccessTokenTicket:(OAServiceTicket *)ticket didFailWithError:(NSError *) error { | ||
[self.delegate accessTokenTicket:ticket didFailWithError:error]; | ||
} | ||
|
||
// | ||
// access token callback | ||
// when twitter sends us an access token this callback will fire | ||
// we store it in our ivar as well as writing it to the keychain | ||
// | ||
|
||
- (void) setAccessToken: (OAServiceTicket *) ticket withData: (NSData *) data { | ||
NSLog(@"£$@£$£@$@£$£@"); | ||
if (!ticket.didSucceed || !data) | ||
{ | ||
[self accessTokenTicket:ticket didFailWithError:nil]; | ||
return; | ||
} | ||
|
||
NSString *dataString = [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease]; | ||
if (!dataString) | ||
{ | ||
[self accessTokenTicket:ticket didFailWithError:nil]; | ||
return; | ||
} | ||
|
||
[self performSelectorOnMainThread:@selector(callDelegateOnMainThreadWithSetAccessTokenFromTokenString:) withObject:dataString waitUntilDone:[NSThread isMainThread]]; | ||
} | ||
|
||
- (void) callDelegateOnMainThreadWithSetAccessTokenFromTokenString: (NSString *)tokenString | ||
{ | ||
[self.delegate setAccessTokenFromTokenString:tokenString]; | ||
} | ||
|
||
|
||
@end |
8 changes: 8 additions & 0 deletions
8
XAuthTwitterEngineDemo/Libraries & Headers/ExchangeCredentialsOperationDelegate.h
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,8 @@ | ||
@class OAServiceTicket; | ||
|
||
@protocol ExchangeCredentialsOperationDelegate | ||
|
||
- (void) setAccessTokenFromTokenString:(NSString *)tokenString; | ||
- (void) accessTokenTicket:(OAServiceTicket *)ticket didFailWithError:(NSError *) error; | ||
|
||
@end |