adium 4210:8d53bf7fc249: Retrieving the auth_token now works for...

commits at adium.im commits at adium.im
Thu Sep 15 09:42:51 UTC 2011


details:	http://hg.adium.im/adium/rev/8d53bf7fc249
revision:	4210:8d53bf7fc249
branch:		MSN-XMPP
author:		Thijs Alkemade <thijsalkemade at gmail.com>
date:		Thu Sep 15 11:42:43 2011 +0200

Retrieving the auth_token now works for MSN.

diffs (169 lines):

diff -r 0a6571895693 -r 8d53bf7fc249 Plugins/Purple Service/AIFacebookXMPPAccount.m
--- a/Plugins/Purple Service/AIFacebookXMPPAccount.m	Thu Sep 15 11:19:25 2011 +0200
+++ b/Plugins/Purple Service/AIFacebookXMPPAccount.m	Thu Sep 15 11:42:43 2011 +0200
@@ -409,4 +409,38 @@
     }    
 }
 
+- (NSString *)oAuthURL
+{
+	return @"https://graph.facebook.com/oauth/authorize?"
+	@"client_id=" ADIUM_APP_ID "&"
+	@"redirect_uri=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html&"
+	@"scope=xmpp_login,offline_access&"
+	@"type=user_agent&"
+	@"display=popup";
+}
+
+- (NSDictionary*)parseURLParams:(NSString *)query {
+	NSArray *pairs = [query componentsSeparatedByString:@"&"];
+	NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease];
+	for (NSString *pair in pairs) {
+		NSArray *kv = [pair componentsSeparatedByString:@"="];
+		NSString *val = [[kv objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+		
+		[params setObject:val forKey:[kv objectAtIndex:0]];
+	}
+	return params;
+}
+
+- (NSString *)tokenFromURL:(NSURL *)url
+{
+	if ([[url host] isEqual:@"www.facebook.com"] && [[url path] isEqual:@"/connect/login_success.html"]) {
+		NSDictionary *urlParamDict = [self parseURLParams:[url fragment]];
+		NSString *token = [urlParamDict objectForKey:@"access_token"];
+		
+		return token ?: @"";
+	}
+	
+	return nil;
+}
+
 @end
diff -r 0a6571895693 -r 8d53bf7fc249 Plugins/Purple Service/AIFacebookXMPPOAuthWebViewWindowController.m
--- a/Plugins/Purple Service/AIFacebookXMPPOAuthWebViewWindowController.m	Thu Sep 15 11:19:25 2011 +0200
+++ b/Plugins/Purple Service/AIFacebookXMPPOAuthWebViewWindowController.m	Thu Sep 15 11:42:43 2011 +0200
@@ -54,12 +54,7 @@
 {
     [super showWindow:sender];
 
-    [webView setMainFrameURL:@"https://graph.facebook.com/oauth/authorize?"
-     @"client_id=" ADIUM_APP_ID "&"
-     @"redirect_uri=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html&"
-	 @"scope=xmpp_login,offline_access&"
-     @"type=user_agent&"
-     @"display=popup"];
+    [webView setMainFrameURL:[account oAuthURL]];
 	
 	[spinner startAnimation:self];
     
@@ -75,19 +70,6 @@
         [self.account oAuthWebViewControllerDidFail:self];
 }
 
-- (NSDictionary*)parseURLParams:(NSString *)query {
-	NSArray *pairs = [query componentsSeparatedByString:@"&"];
-	NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease];
-	for (NSString *pair in pairs) {
-		NSArray *kv = [pair componentsSeparatedByString:@"="];
-		NSString *val = [[kv objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-		
-		[params setObject:val forKey:[kv objectAtIndex:0]];
-	}
-	return params;
-}
-
-
 - (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
 {
 	[spinner startAnimation:self];
@@ -133,17 +115,16 @@
     [mutableRequest setHTTPShouldHandleCookies:NO];
     [self addCookiesToRequest:mutableRequest];
 	
-    if ([[[mutableRequest URL] host] isEqual:@"www.facebook.com"] && [[[mutableRequest URL] path] isEqual:@"/connect/login_success.html"]) {
-		NSDictionary *urlParamDict = [self parseURLParams:[[mutableRequest URL] fragment]];
+	NSString *token = [account tokenFromURL:[mutableRequest URL]];
+	
+//    if ([[[mutableRequest URL] host] isEqual:@"www.facebook.com"] && [[[mutableRequest URL] path] isEqual:@"/connect/login_success.html"]) {
+	if (token) {
 		
-		NSString *token = [urlParamDict objectForKey:@"access_token"];
-		if (token && ![token isEqualToString:@""]) {
-    		[self.account oAuthWebViewController:self didSucceedWithToken:token];
+		if ([token isEqualToString:@""]) {
+			[self.account oAuthWebViewControllerDidFail:self];
 		} else {
-			/* Got a bad token, or the user canceled */
-			[self.account oAuthWebViewControllerDidFail:self];
-
-		}		
+			[self.account oAuthWebViewController:self didSucceedWithToken:token];
+		}
 
         notifiedAccount = YES;
 		[self closeWindow:nil];
diff -r 0a6571895693 -r 8d53bf7fc249 Plugins/Purple Service/AIOAuth2XMPPAccount.h
--- a/Plugins/Purple Service/AIOAuth2XMPPAccount.h	Thu Sep 15 11:19:25 2011 +0200
+++ b/Plugins/Purple Service/AIOAuth2XMPPAccount.h	Thu Sep 15 11:42:43 2011 +0200
@@ -34,6 +34,8 @@
 }
 
 - (void)requestAuthorization;
+- (NSString *)oAuthURL;
+- (NSString *)tokenFromURL:(NSURL *)url;
 
 @property (nonatomic, retain) AIFacebookXMPPOAuthWebViewWindowController *oAuthWC;
 @property (nonatomic, copy) NSString *oAuthToken;
diff -r 0a6571895693 -r 8d53bf7fc249 Plugins/Purple Service/AIXMPPMSNAccount.m
--- a/Plugins/Purple Service/AIXMPPMSNAccount.m	Thu Sep 15 11:19:25 2011 +0200
+++ b/Plugins/Purple Service/AIXMPPMSNAccount.m	Thu Sep 15 11:42:43 2011 +0200
@@ -16,6 +16,9 @@
 
 #import "AIXMPPMSNAccount.h"
 
+// Should probably be temporary, registered by me (Thijs)
+#define ADIUM_MSN_OAUTH2_APP_ID @"0000000040068F8C"
+
 @implementation AIXMPPMSNAccount
 
 - (id)init
@@ -28,4 +31,38 @@
     return self;
 }
 
+- (NSString *)oAuthURL
+{
+	return @"https://oauth.live.com/authorize?client_id=" ADIUM_MSN_OAUTH2_APP_ID
+	@"&scope=wl.messenger"
+	@"&response_type=token"
+	@"&redirect_uri=http://oauth.live.com/desktop";
+}
+
+- (NSDictionary*)parseURLParams:(NSString *)query {
+	NSArray *pairs = [query componentsSeparatedByString:@"&"];
+	NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease];
+	for (NSString *pair in pairs) {
+		NSArray *kv = [pair componentsSeparatedByString:@"="];
+		NSString *val = [[kv objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+		
+		[params setObject:val forKey:[kv objectAtIndex:0]];
+	}
+	return params;
+}
+
+- (NSString *)tokenFromURL:(NSURL *)url
+{
+	if ([[url host] isEqual:@"oauth.live.com"] && [[url path] isEqual:@"/desktop"]) {
+		NSDictionary *urlParamDict = [self parseURLParams:[url fragment]];
+		NSString *token = [urlParamDict objectForKey:@"access_token"];
+		
+		AILogWithSignature(@"Got token: %@", token);
+		
+		return token ?: @"";
+	}
+	
+	return nil;
+}
+
 @end




More information about the commits mailing list