Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

xAuth test

commit 5ce25d68916cd45254c7ff2ba9b91de4f324899a 1 parent aeecaa1
@norio-nomura authored
View
6 NatsuLion/app/NTLNAppDelegate.m
@@ -134,7 +134,11 @@ - (void)startup {
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
-#ifdef ENABLE_OAUTH
+#ifdef ENABLE_XAUTH
+ if (![[NTLNAccount sharedInstance] valid]) {
+ [self presentTwitterAccountSettingView];
+ }
+#elif defined(ENABLE_OAUTH)
if (! [[NTLNAccount sharedInstance] waitForOAuthCallback] &&
! [[NTLNAccount sharedInstance] valid]) {
[[NTLNOAuthConsumer sharedInstance] requestToken:tabBarController];
View
6 NatsuLion/controllers/settings/NTLNTwitterAccountViewController.m
@@ -2,6 +2,9 @@
#import "NTLNConfigurationKeys.h"
#import "NTLNAccount.h"
#import "UICTableViewCellTextInput.h"
+#ifdef ENABLE_XAUTH
+#import "NTLNOAuthConsumer.h"
+#endif
@interface NTLNTwitterAccountViewController(Private)
- (void)setupPrototypes;
@@ -78,6 +81,9 @@ - (void)viewWillDisappear:(BOOL)animated {
[self resignFirstResponderForCell:[NSIndexPath indexPathForRow:1 inSection:0]];
[[NTLNAccount sharedInstance] update];
+#ifdef ENABLE_XAUTH
+ [[NTLNOAuthConsumer sharedInstance] xAuthAccessToken];
+#endif
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
View
4 NatsuLion/controllers/tabviews/NTLNSettingViewController.m
@@ -122,7 +122,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
// for "Twitter account" cell
if ([indexPath section] == 0 && [indexPath row] == 0) {
-#ifdef ENABLE_OAUTH
+#ifdef ENABLE_XAUTH
+ [(NTLNAppDelegate*)[UIApplication sharedApplication].delegate presentTwitterAccountSettingView];
+#elif defined(ENABLE_OAUTH)
[[NTLNOAuthConsumer sharedInstance] requestToken:self.tabBarController];
#else
[(NTLNAppDelegate*)[UIApplication sharedApplication].delegate presentTwitterAccountSettingView];
View
2  NatsuLion/models/network/NTLNOAuthConsumer.h
@@ -15,6 +15,8 @@
- (BOOL)isCallbackURL:(NSURL*)url;
- (void)accessToken:(NSURL*)callbackUrl;
+- (void)xAuthAccessToken;
+
@end
#endif
View
29 NatsuLion/models/network/NTLNOAuthConsumer.m
@@ -88,6 +88,35 @@ - (void)accessToken:(NSURL*)callbackUrl {
}
+- (void)xAuthAccessToken {
+ 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
+ autorelease];
+
+ [request setHTTPMethod:@"POST"];
+
+ NSString *username = [[NTLNAccount sharedInstance] screenName];
+ NSString *password = [[NTLNAccount sharedInstance] password];
+
+ [request setParameters:[NSArray arrayWithObjects:
+ [OARequestParameter requestParameterWithName:@"x_auth_mode" value:@"client_auth"],
+ [OARequestParameter requestParameterWithName:@"x_auth_username" value:username],
+ [OARequestParameter requestParameterWithName:@"x_auth_password" value:password],
+ nil]];
+
+ OADataFetcher *fetcher = [[[OADataFetcher alloc] init] autorelease];
+
+ [fetcher fetchDataWithRequest:request
+ delegate:self
+ didFinishSelector:@selector(accessTokenTicket:didFinishWithData:)
+ didFailSelector:@selector(accessTokenTicket:didFailWithError:)];
+}
+
#pragma mark Private
- (void)dealloc {
View
6 ntlniph.xcodeproj/project.pbxproj
@@ -1327,7 +1327,11 @@
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
- GCC_PREPROCESSOR_DEFINITIONS = DEBUG;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ ENABLE_XAUTH,
+ ENABLE_OAUTH,
+ DEBUG,
+ );
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/usr/include/libxml2;
Please sign in to comment.
Something went wrong with that request. Please try again.