adium 4211:887d1ea665d4: Added the actual auth mech. Signing in ...
commits at adium.im
commits at adium.im
Thu Sep 15 14:23:26 UTC 2011
details: http://hg.adium.im/adium/rev/887d1ea665d4
revision: 4211:887d1ea665d4
branch: MSN-XMPP
author: Thijs Alkemade <thijsalkemade at gmail.com>
date: Thu Sep 15 16:23:06 2011 +0200
Added the actual auth mech. Signing in works, though it is still called "Facebook" everywhere.
diffs (678 lines):
diff -r 8d53bf7fc249 -r 887d1ea665d4 Adium.xcodeproj/project.pbxproj
--- a/Adium.xcodeproj/project.pbxproj Thu Sep 15 11:42:43 2011 +0200
+++ b/Adium.xcodeproj/project.pbxproj Thu Sep 15 16:23:06 2011 +0200
@@ -1422,6 +1422,8 @@
6EC1684F06C170A000F9FAD3 /* DCInviteToChatWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EC1684A06C170A000F9FAD3 /* DCInviteToChatWindowController.m */; };
6EC1685006C170A000F9FAD3 /* InviteToChatWindow.nib in Resources */ = {isa = PBXBuildFile; fileRef = 6EC1684B06C170A000F9FAD3 /* InviteToChatWindow.nib */; };
766ABAB61306D1020049FFB7 /* AIUnreadMessagesTooltip.m in Sources */ = {isa = PBXBuildFile; fileRef = 766ABAB51306D1020049FFB7 /* AIUnreadMessagesTooltip.m */; };
+ 76723D7014223EF600AB8C30 /* auth_msn.c in Sources */ = {isa = PBXBuildFile; fileRef = 76723D6F14223EF600AB8C30 /* auth_msn.c */; };
+ 76723D7214223FA400AB8C30 /* auth_msn.h in Headers */ = {isa = PBXBuildFile; fileRef = 76723D7114223FA400AB8C30 /* auth_msn.h */; };
76889DEB12D3CA17007AEF00 /* GetInfo.png in Resources */ = {isa = PBXBuildFile; fileRef = 76889DEA12D3CA17007AEF00 /* GetInfo.png */; };
76889DEF12D3CA40007AEF00 /* Personal.png in Resources */ = {isa = PBXBuildFile; fileRef = 76889DEE12D3CA40007AEF00 /* Personal.png */; };
76C1AF9C125A906A00D269A9 /* AIAdiumURLProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = 76C1AF9B125A906A00D269A9 /* AIAdiumURLProtocol.m */; };
@@ -4620,6 +4622,8 @@
6FB330A40C7235BF00B001A8 /* EKEzvOutgoingFileTransfer.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = EKEzvOutgoingFileTransfer.m; path = Plugins/Bonjour/libezv/Classes/EKEzvOutgoingFileTransfer.m; sourceTree = SOURCE_ROOT; };
766ABAB41306D1020049FFB7 /* AIUnreadMessagesTooltip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AIUnreadMessagesTooltip.h; path = Source/AIUnreadMessagesTooltip.h; sourceTree = "<group>"; };
766ABAB51306D1020049FFB7 /* AIUnreadMessagesTooltip.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AIUnreadMessagesTooltip.m; path = Source/AIUnreadMessagesTooltip.m; sourceTree = "<group>"; };
+ 76723D6F14223EF600AB8C30 /* auth_msn.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = auth_msn.c; sourceTree = "<group>"; };
+ 76723D7114223FA400AB8C30 /* auth_msn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = auth_msn.h; sourceTree = "<group>"; };
76889DEA12D3CA17007AEF00 /* GetInfo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = GetInfo.png; path = Resources/GetInfo.png; sourceTree = "<group>"; };
76889DEE12D3CA40007AEF00 /* Personal.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Personal.png; path = Resources/Personal.png; sourceTree = "<group>"; };
76C1AF9A125A906A00D269A9 /* AIAdiumURLProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AIAdiumURLProtocol.h; path = "Plugins/WebKit Message View/AIAdiumURLProtocol.h"; sourceTree = "<group>"; };
@@ -5116,6 +5120,8 @@
811033500CDE170B00EC6038 /* ssl-cdsa.c */,
11EE1B4B0CDCFAF40097F246 /* ssl-openssl.c */,
11EE1B4C0CDCFAF40097F246 /* ssl.c */,
+ 76723D6F14223EF600AB8C30 /* auth_msn.c */,
+ 76723D7114223FA400AB8C30 /* auth_msn.h */,
);
name = libpurple_extensions;
path = "Plugins/Purple Service/libpurple_extensions";
@@ -9065,6 +9071,7 @@
34D8155013B663A80022C8C4 /* fbapi.h in Headers */,
76EDA7E81421F8070074F456 /* AIXMPPMSNService.h in Headers */,
76EDA7EC1421F8EA0074F456 /* AIXMPPMSNAccount.h in Headers */,
+ 76723D7214223FA400AB8C30 /* auth_msn.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -10218,6 +10225,7 @@
34D8154F13B663A80022C8C4 /* fbapi.c in Sources */,
76EDA7E91421F8070074F456 /* AIXMPPMSNService.m in Sources */,
76EDA7ED1421F8EA0074F456 /* AIXMPPMSNAccount.m in Sources */,
+ 76723D7014223EF600AB8C30 /* auth_msn.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff -r 8d53bf7fc249 -r 887d1ea665d4 Plugins/Purple Service/AIFacebookXMPPAccount.h
--- a/Plugins/Purple Service/AIFacebookXMPPAccount.h Thu Sep 15 11:42:43 2011 +0200
+++ b/Plugins/Purple Service/AIFacebookXMPPAccount.h Thu Sep 15 16:23:06 2011 +0200
@@ -19,12 +19,6 @@
@interface AIFacebookXMPPAccount : AIOAuth2XMPPAccount {
- NSUInteger networkState;
-
- NSURLConnection *connection; // weak
- NSURLResponse *connectionResponse;
- NSMutableData *connectionData;
-
NSDictionary *migrationData;
}
diff -r 8d53bf7fc249 -r 887d1ea665d4 Plugins/Purple Service/AIFacebookXMPPAccount.m
--- a/Plugins/Purple Service/AIFacebookXMPPAccount.m Thu Sep 15 11:42:43 2011 +0200
+++ b/Plugins/Purple Service/AIFacebookXMPPAccount.m Thu Sep 15 16:23:06 2011 +0200
@@ -20,7 +20,6 @@
#import <AIUtilities/AIKeychain.h>
#import "AIFacebookXMPPOAuthWebViewWindowController.h"
-#import "JSONKit.h"
#import <Adium/AIAccountControllerProtocol.h>
#import <Adium/AIPasswordPromptController.h>
@@ -29,27 +28,9 @@
#import <Libpurple/auth.h>
#import "auth_fb.h"
-enum {
- AINoNetworkState,
- AIMeGraphAPINetworkState,
- AIPromoteSessionNetworkState
-};
-
- at interface AIFacebookXMPPAccount ()
-
- at property (nonatomic, assign) NSUInteger networkState;
- at property (nonatomic, assign) NSURLConnection *connection; // assign because NSURLConnection retains its delegate.
- at property (nonatomic, retain) NSURLResponse *connectionResponse;
- at property (nonatomic, retain) NSMutableData *connectionData;
-
-- (void)meGraphAPIDidFinishLoading:(NSData *)graphAPIData response:(NSURLResponse *)response error:(NSError *)inError;
-- (void)promoteSessionDidFinishLoading:(NSData *)secretData response:(NSURLResponse *)response error:(NSError *)inError;
- at end
-
@implementation AIFacebookXMPPAccount
@synthesize migrationData;
- at synthesize networkState, connection, connectionResponse, connectionData;
+ (BOOL)uidIsValidForFacebook:(NSString *)inUID
{
@@ -70,18 +51,6 @@
return self;
}
-- (void)dealloc
-{
- [oAuthWC release];
- [oAuthToken release];
-
- [connection cancel];
- [connectionResponse release];
- [connectionData release];
-
- [super dealloc];
-}
-
#pragma mark Connectivitiy
- (const char*)protocolPlugin
@@ -128,7 +97,7 @@
/* Add the authentication mechanism for X-FACEBOOK-PLATFORM. Note that if the server offers it,
* it will be used preferentially over any other mechanism e.g. DIGEST-MD5. */
-- (void)setFacebookMechEnabled:(BOOL)inEnabled
+- (void)setMechEnabled:(BOOL)inEnabled
{
static BOOL enabledFacebookMech = NO;
if (inEnabled != enabledFacebookMech) {
@@ -141,24 +110,6 @@
}
}
-- (void)connect
-{
- [self setFacebookMechEnabled:YES];
- [super connect];
-}
-
-- (void)didConnect
-{
- [self setFacebookMechEnabled:NO];
- [super didConnect];
-}
-
-- (void)didDisconnect
-{
- [self setFacebookMechEnabled:NO];
- [super didDisconnect];
-}
-
- (const char *)purpleAccountName
{
NSString *userNameWithHost = nil, *completeUserName = nil;
@@ -222,15 +173,6 @@
}
}
-#pragma mark Account configuration
-
-- (void)setName:(NSString *)name UID:(NSString *)inUID
-{
- [self filterAndSetUID:inUID];
-
- [self setFormattedUID:name notify:NotifyNever];
-}
-
#pragma mark Contacts
/*!
@@ -272,43 +214,6 @@
#pragma mark Authorization
-- (void)meGraphAPIDidFinishLoading:(NSData *)graphAPIData response:(NSURLResponse *)inResponse error:(NSError *)inError
-{
- if (inError) {
- NSLog(@"error loading graph API: %@", inError);
- // TODO: indicate setup failed
- return;
- }
-
- NSError *error = nil;
- NSDictionary *resp = [graphAPIData objectFromJSONDataWithParseOptions:JKParseOptionNone error:&error];
- if (!resp) {
- NSLog(@"error decoding graph API response: %@", error);
- // TODO: indicate setup failed
- return;
- }
-
- NSString *uuid = [resp objectForKey:@"id"];
- NSString *name = [resp objectForKey:@"name"];
-
- /* Passwords are keyed by UID, so we need to make this change before storing the password */
- [self setName:name UID:uuid];
-
- NSString *secretURLString = [NSString stringWithFormat:@"https://api.facebook.com/method/auth.promoteSession?access_token=%@&format=JSON", [self oAuthToken]];
- NSURL *secretURL = [NSURL URLWithString:[secretURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
- NSURLRequest *secretRequest = [NSURLRequest requestWithURL:secretURL];
-
- self.networkState = AIPromoteSessionNetworkState;
- self.connectionData = [NSMutableData data];
- self.connection = [NSURLConnection connectionWithRequest:secretRequest delegate:self];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:AIOAuth2ProgressNotification
- object:self
- userInfo:
- [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:AIOAuth2ProgressPromotingForChat]
- forKey:KEY_OAUTH2_STEP]];
-}
-
- (void)didCompleteFacebookAuthorization
{
/* Restart the connect process; we're currently considered 'connecting', so passwordReturnedForConnect:::
@@ -362,51 +267,9 @@
self.oAuthToken = nil;
}
-#pragma mark NSURLConnectionDelegate
-
-- (void)connection:(NSURLConnection *)inConnection didReceiveResponse:(NSURLResponse *)response
+- (NSString *)meURL
{
- [[self connectionData] setLength:0];
- [self setConnectionResponse:response];
-}
-
-- (void)connection:(NSURLConnection *)inConnection didReceiveData:(NSData *)data
-{
- [[self connectionData] appendData:data];
-}
-
-- (void)connection:(NSURLConnection *)inConnection didFailWithError:(NSError *)error
-{
- NSUInteger state = [self networkState];
-
- [self setNetworkState:AINoNetworkState];
- [self setConnection:nil];
- [self setConnectionResponse:nil];
- [self setConnectionData:nil];
-
- if (state == AIMeGraphAPINetworkState) {
- [self meGraphAPIDidFinishLoading:nil response:nil error:error];
- } else if (state == AIPromoteSessionNetworkState) {
- [self promoteSessionDidFinishLoading:nil response:nil error:error];
- }
-}
-
-- (void)connectionDidFinishLoading:(NSURLConnection *)inConnection
-{
- NSURLResponse *response = [[[self connectionResponse] retain] autorelease];
- NSMutableData *data = [[[self connectionData] retain] autorelease];
- NSUInteger state = [self networkState];
-
- [self setNetworkState:AINoNetworkState];
- [self setConnection:nil];
- [self setConnectionResponse:nil];
- [self setConnectionData:nil];
-
- if (state == AIMeGraphAPINetworkState) {
- [self meGraphAPIDidFinishLoading:data response:response error:nil];
- } else if (state == AIPromoteSessionNetworkState) {
- [self promoteSessionDidFinishLoading:data response:response error:nil];
- }
+ return @"https://graph.facebook.com/me?access_token=%@";
}
- (NSString *)oAuthURL
diff -r 8d53bf7fc249 -r 887d1ea665d4 Plugins/Purple Service/AIFacebookXMPPOAuthWebViewWindowController.h
--- a/Plugins/Purple Service/AIFacebookXMPPOAuthWebViewWindowController.h Thu Sep 15 11:42:43 2011 +0200
+++ b/Plugins/Purple Service/AIFacebookXMPPOAuthWebViewWindowController.h Thu Sep 15 16:23:06 2011 +0200
@@ -9,14 +9,14 @@
#import <Adium/AIWindowController.h>
#import <WebKit/WebKit.h>
- at class AIFacebookXMPPAccount;
+ at class AIOAuth2XMPPAccount;
@interface AIFacebookXMPPOAuthWebViewWindowController : AIWindowController {
IBOutlet WebView *webView;
IBOutlet NSProgressIndicator *spinner;
NSMutableSet *cookies;
- AIFacebookXMPPAccount *account;
+ AIOAuth2XMPPAccount *account;
NSString *autoFillUsername;
NSString *autoFillPassword;
@@ -29,7 +29,7 @@
@property (nonatomic, retain) IBOutlet NSProgressIndicator *spinner;
@property (nonatomic, retain) NSMutableSet *cookies;
- at property (nonatomic, retain) AIFacebookXMPPAccount *account;
+ at property (nonatomic, retain) AIOAuth2XMPPAccount *account;
@property (nonatomic, retain) NSString *autoFillUsername;
@property (nonatomic, retain) NSString *autoFillPassword;
diff -r 8d53bf7fc249 -r 887d1ea665d4 Plugins/Purple Service/AIOAuth2XMPPAccount.h
--- a/Plugins/Purple Service/AIOAuth2XMPPAccount.h Thu Sep 15 11:42:43 2011 +0200
+++ b/Plugins/Purple Service/AIOAuth2XMPPAccount.h Thu Sep 15 16:23:06 2011 +0200
@@ -31,11 +31,18 @@
@interface AIOAuth2XMPPAccount : CBPurpleAccount {
AIFacebookXMPPOAuthWebViewWindowController *oAuthWC;
NSString *oAuthToken;
+
+ NSUInteger networkState;
+
+ NSURLConnection *connection; // weak
+ NSURLResponse *connectionResponse;
+ NSMutableData *connectionData;
}
- (void)requestAuthorization;
- (NSString *)oAuthURL;
- (NSString *)tokenFromURL:(NSURL *)url;
+- (void)setMechEnabled:(BOOL)enabled;
@property (nonatomic, retain) AIFacebookXMPPOAuthWebViewWindowController *oAuthWC;
@property (nonatomic, copy) NSString *oAuthToken;
diff -r 8d53bf7fc249 -r 887d1ea665d4 Plugins/Purple Service/AIOAuth2XMPPAccount.m
--- a/Plugins/Purple Service/AIOAuth2XMPPAccount.m Thu Sep 15 11:42:43 2011 +0200
+++ b/Plugins/Purple Service/AIOAuth2XMPPAccount.m Thu Sep 15 16:23:06 2011 +0200
@@ -15,19 +15,40 @@
*/
#import "AIOAuth2XMPPAccount.h"
+#import "JSONKit.h"
+
+enum {
+ AINoNetworkState,
+ AIMeGraphAPINetworkState,
+ AIPromoteSessionNetworkState
+};
+
+ at interface AIOAuth2XMPPAccount ()
+
+ at property (nonatomic, assign) NSUInteger networkState;
+ at property (nonatomic, assign) NSURLConnection *connection; // assign because NSURLConnection retains its delegate.
+ at property (nonatomic, retain) NSURLResponse *connectionResponse;
+ at property (nonatomic, retain) NSMutableData *connectionData;
+
+- (void)meGraphAPIDidFinishLoading:(NSData *)graphAPIData response:(NSURLResponse *)response error:(NSError *)inError;
+- (void)promoteSessionDidFinishLoading:(NSData *)secretData response:(NSURLResponse *)response error:(NSError *)inError;
+ at end
@implementation AIOAuth2XMPPAccount
@synthesize oAuthWC, oAuthToken;
+ at synthesize networkState, connection, connectionResponse, connectionData;
-- (id)init
+- (void)dealloc
{
- self = [super init];
- if (self) {
- // Initialization code here.
- }
+ [oAuthWC release];
+ [oAuthToken release];
- return self;
+ [connection cancel];
+ [connectionResponse release];
+ [connectionData release];
+
+ [super dealloc];
}
- (void)requestAuthorization
@@ -63,13 +84,13 @@
{
[self setOAuthToken:token];
- NSString *urlstring = [NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@", [self oAuthToken]];
+ NSString *urlstring = [NSString stringWithFormat:[self meURL], [self oAuthToken]];
NSURL *url = [NSURL URLWithString:[urlstring stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
-// self.networkState = AIMeGraphAPINetworkState;
-// self.connectionData = [NSMutableData data];
-// self.connection = [NSURLConnection connectionWithRequest:request delegate:self];
+ self.networkState = AIMeGraphAPINetworkState;
+ self.connectionData = [NSMutableData data];
+ self.connection = [NSURLConnection connectionWithRequest:request delegate:self];
[[NSNotificationCenter defaultCenter] postNotificationName:AIOAuth2ProgressNotification
object:self
@@ -90,4 +111,123 @@
}
+#pragma mark Account configuration
+
+- (void)setName:(NSString *)name UID:(NSString *)inUID
+{
+ [self filterAndSetUID:inUID];
+
+ [self setFormattedUID:name notify:NotifyNever];
+}
+
+- (void)meGraphAPIDidFinishLoading:(NSData *)graphAPIData response:(NSURLResponse *)inResponse error:(NSError *)inError
+{
+ if (inError) {
+ NSLog(@"error loading graph API: %@", inError);
+ // TODO: indicate setup failed
+ return;
+ }
+
+ NSError *error = nil;
+ NSDictionary *resp = [graphAPIData objectFromJSONDataWithParseOptions:JKParseOptionNone error:&error];
+ if (!resp) {
+ NSLog(@"error decoding graph API response: %@", error);
+ // TODO: indicate setup failed
+ return;
+ }
+
+ NSString *uuid = [resp objectForKey:@"id"];
+ NSString *name = [resp objectForKey:@"name"];
+
+ /* Passwords are keyed by UID, so we need to make this change before storing the password */
+ [self setName:name UID:uuid];
+
+ [[adium accountController] setPassword:[self oAuthToken] forAccount:self];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:AIOAuth2ProgressNotification
+ object:self
+ userInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:AIOAuth2ProgressSuccess]
+ forKey:KEY_OAUTH2_STEP]];
+// NSString *secretURLString = [NSString stringWithFormat:@"https://api.facebook.com/method/auth.promoteSession?access_token=%@&format=JSON", [self oAuthToken]];
+// NSURL *secretURL = [NSURL URLWithString:[secretURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
+// NSURLRequest *secretRequest = [NSURLRequest requestWithURL:secretURL];
+//
+// self.networkState = AIPromoteSessionNetworkState;
+// self.connectionData = [NSMutableData data];
+// self.connection = [NSURLConnection connectionWithRequest:secretRequest delegate:self];
+//
+// [[NSNotificationCenter defaultCenter] postNotificationName:AIOAuth2ProgressNotification
+// object:self
+// userInfo:
+// [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:AIOAuth2ProgressPromotingForChat]
+// forKey:KEY_OAUTH2_STEP]];
+}
+
+#pragma mark NSURLConnectionDelegate
+
+- (void)connection:(NSURLConnection *)inConnection didReceiveResponse:(NSURLResponse *)response
+{
+ [[self connectionData] setLength:0];
+ [self setConnectionResponse:response];
+}
+
+- (void)connection:(NSURLConnection *)inConnection didReceiveData:(NSData *)data
+{
+ [[self connectionData] appendData:data];
+}
+
+- (void)connection:(NSURLConnection *)inConnection didFailWithError:(NSError *)error
+{
+ NSUInteger state = [self networkState];
+
+ [self setNetworkState:AINoNetworkState];
+ [self setConnection:nil];
+ [self setConnectionResponse:nil];
+ [self setConnectionData:nil];
+
+ if (state == AIMeGraphAPINetworkState) {
+ [self meGraphAPIDidFinishLoading:nil response:nil error:error];
+ } else if (state == AIPromoteSessionNetworkState) {
+ [self promoteSessionDidFinishLoading:nil response:nil error:error];
+ }
+}
+
+- (void)connectionDidFinishLoading:(NSURLConnection *)inConnection
+{
+ NSURLResponse *response = [[[self connectionResponse] retain] autorelease];
+ NSMutableData *data = [[[self connectionData] retain] autorelease];
+ NSUInteger state = [self networkState];
+
+ [self setNetworkState:AINoNetworkState];
+ [self setConnection:nil];
+ [self setConnectionResponse:nil];
+ [self setConnectionData:nil];
+
+ if (state == AIMeGraphAPINetworkState) {
+ [self meGraphAPIDidFinishLoading:data response:response error:nil];
+ } else if (state == AIPromoteSessionNetworkState) {
+ [self promoteSessionDidFinishLoading:data response:response error:nil];
+ }
+}
+
+
+
+- (void)connect
+{
+ [self setMechEnabled:YES];
+ [super connect];
+}
+
+- (void)didConnect
+{
+ [self setMechEnabled:NO];
+ [super didConnect];
+}
+
+- (void)didDisconnect
+{
+ [self setMechEnabled:NO];
+ [super didDisconnect];
+}
+
@end
diff -r 8d53bf7fc249 -r 887d1ea665d4 Plugins/Purple Service/AIXMPPMSNAccount.m
--- a/Plugins/Purple Service/AIXMPPMSNAccount.m Thu Sep 15 11:42:43 2011 +0200
+++ b/Plugins/Purple Service/AIXMPPMSNAccount.m Thu Sep 15 16:23:06 2011 +0200
@@ -15,6 +15,8 @@
*/
#import "AIXMPPMSNAccount.h"
+#import <libpurple/jabber.h>
+#import "auth_msn.h"
// Should probably be temporary, registered by me (Thijs)
#define ADIUM_MSN_OAUTH2_APP_ID @"0000000040068F8C"
@@ -31,6 +33,52 @@
return self;
}
+- (const char*)protocolPlugin
+{
+ return "prpl-jabber";
+}
+
+- (NSString *)serverSuffix
+{
+ return @"@messenger.live.com";
+}
+
+- (NSString *)host
+{
+ return @"messenger.live.com";
+}
+
+- (void)configurePurpleAccount
+{
+ [super configurePurpleAccount];
+
+ purple_account_set_username(account, self.purpleAccountName);
+}
+
+- (const char *)purpleAccountName
+{
+ NSString *userNameWithHost = nil, *completeUserName = nil;
+ BOOL serverAppendedToUID;
+
+ serverAppendedToUID = ([UID rangeOfString:[self serverSuffix]
+ options:(NSCaseInsensitiveSearch | NSBackwardsSearch | NSAnchoredSearch)].location != NSNotFound);
+
+ if (serverAppendedToUID) {
+ userNameWithHost = UID;
+ } else {
+ userNameWithHost = [UID stringByAppendingString:[self serverSuffix]];
+ }
+
+ completeUserName = [NSString stringWithFormat:@"%@/Adium", userNameWithHost];
+
+ return [completeUserName UTF8String];
+}
+
+- (NSString *)meURL
+{
+ return @"https://apis.live.net/v5.0/me?access_token=%@";
+}
+
- (NSString *)oAuthURL
{
return @"https://oauth.live.com/authorize?client_id=" ADIUM_MSN_OAUTH2_APP_ID
@@ -65,4 +113,17 @@
return nil;
}
+- (void)setMechEnabled:(BOOL)inEnabled
+{
+ static BOOL enabledMSNMech = NO;
+ if (inEnabled != enabledMSNMech) {
+ if (inEnabled)
+ jabber_auth_add_mech(jabber_auth_get_msn_mech());
+ else
+ jabber_auth_remove_mech(jabber_auth_get_msn_mech());
+
+ enabledMSNMech = inEnabled;
+ }
+}
+
@end
diff -r 8d53bf7fc249 -r 887d1ea665d4 Plugins/Purple Service/libpurple_extensions/auth_msn.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/Purple Service/libpurple_extensions/auth_msn.c Thu Sep 15 16:23:06 2011 +0200
@@ -0,0 +1,72 @@
+/*
+ * purple - Jabber Protocol Plugin
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here. Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ *
+ */
+#include "internal.h"
+
+#include "account.h"
+#include "debug.h"
+#include "request.h"
+#include "util.h"
+#include "xmlnode.h"
+
+#include "jabber.h"
+#include "auth.h"
+
+#define PACKAGE "pidgin"
+
+static JabberSaslState
+fb_start(JabberStream *js, xmlnode *packet, xmlnode **response, char **error)
+{
+ PurpleAccount *account;
+ const char *username;
+ const char *auth_key;
+
+ account = purple_connection_get_account(js->gc);
+ username = purple_account_get_username(account);
+ auth_key = purple_account_get_password(account);
+
+ purple_debug_error("auth_msn", "account name is %s", username);
+
+ xmlnode *auth = xmlnode_new("auth");
+ xmlnode_set_namespace(auth, "urn:ietf:params:xml:ns:xmpp-sasl");
+ xmlnode_set_attrib(auth, "mechanism", "X-MESSENGER-OAUTH2");
+ xmlnode_insert_data(auth, auth_key, strlen(auth_key));
+
+ *response = auth;
+
+ return JABBER_SASL_STATE_CONTINUE;
+}
+
+static JabberSaslMech msn_mech = {
+ 127, /* priority; gint8 (-128 to 127). higher will be tried sooner if offerred by the server */
+ "X-MESSENGER-OAUTH2", /* name */
+ fb_start,
+ NULL, /* handle_challenge */
+ NULL, /* handle_success */
+ NULL, /* handle_failure */
+ NULL /* dispose */
+};
+
+JabberSaslMech *jabber_auth_get_msn_mech(void)
+{
+ return &msn_mech;
+}
diff -r 8d53bf7fc249 -r 887d1ea665d4 Plugins/Purple Service/libpurple_extensions/auth_msn.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/Purple Service/libpurple_extensions/auth_msn.h Thu Sep 15 16:23:06 2011 +0200
@@ -0,0 +1,4 @@
+#include "jabber.h"
+#include "auth.h"
+
+JabberSaslMech *jabber_auth_get_msn_mech(void);
More information about the commits
mailing list