Skip to content

Commit

Permalink
Adding missing files.
Browse files Browse the repository at this point in the history
  • Loading branch information
aral committed Mar 11, 2010
1 parent 42181ce commit d2ae1b3
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
XAuthTwitterEngineDemo/build/*
*.pbxuser
*.perspectivev3
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
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
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

0 comments on commit d2ae1b3

Please sign in to comment.