adium-1.4 3521:272bc5ce6c12: Allow any characters for facebook I...
commits at adium.im
commits at adium.im
Fri Jun 24 20:39:01 UTC 2011
details: http://hg.adium.im/adium-1.4/rev/272bc5ce6c12
revision: 3521:272bc5ce6c12
branch: facebook-xmpp
author: Evan Schoenberg
date: Fri Jun 24 14:24:56 2011 -0500
Allow any characters for facebook IDs, which are just email addresses. Better yet would be the email-acceptable-characters regexp, but I don't particularly care to handhold that much. Exercise for the reader if desired.
Subject: adium-1.4 3522:59b9cde2a3a4: If allowing all characters, permit returning nil rather than requiring concoction of an awkward character set. Similarly, if ignoring no characters, return nil.
details: http://hg.adium.im/adium-1.4/rev/59b9cde2a3a4
revision: 3522:59b9cde2a3a4
branch: facebook-xmpp
author: Evan Schoenberg
date: Fri Jun 24 14:37:47 2011 -0500
If allowing all characters, permit returning nil rather than requiring concoction of an awkward character set. Similarly, if ignoring no characters, return nil.
Subject: adium-1.4 3523:a93161a17e5c: Noticed a logic error in passwordReturnedForConnect:returnCode:context: - we want to check the boolValue, not the presence of any NSNumber, on Connecting
details: http://hg.adium.im/adium-1.4/rev/a93161a17e5c
revision: 3523:a93161a17e5c
branch: facebook-xmpp
author: Evan Schoenberg
date: Fri Jun 24 15:00:16 2011 -0500
Noticed a logic error in passwordReturnedForConnect:returnCode:context: - we want to check the boolValue, not the presence of any NSNumber, on Connecting
Subject: adium-1.4 3524:72840c154304: Properly prompt for auth when coming from the setup wizard, and autofill as indicated. Added commented-out code which uses the keychain to store the session secret, which we don't use since it doesn't actually work for authorization.
details: http://hg.adium.im/adium-1.4/rev/72840c154304
revision: 3524:72840c154304
branch: facebook-xmpp
author: Evan Schoenberg
date: Fri Jun 24 15:38:55 2011 -0500
Properly prompt for auth when coming from the setup wizard, and autofill as indicated. Added commented-out code which uses the keychain to store the session secret, which we don't use since it doesn't actually work for authorization.
diffs (292 lines):
diff -r da2a143f9168 -r 72840c154304 Frameworks/Adium Framework/Source/AIAbstractAccount.m
--- a/Frameworks/Adium Framework/Source/AIAbstractAccount.m Fri Jun 24 14:20:49 2011 -0500
+++ b/Frameworks/Adium Framework/Source/AIAbstractAccount.m Fri Jun 24 15:38:55 2011 -0500
@@ -767,7 +767,7 @@
forProperty:@"Prompt For Password On Next Connect"
notify:NotifyNever];
- if (![self boolValueForProperty:@"Online"] && ![self valueForProperty:@"Connecting"]) {
+ if (![self boolValueForProperty:@"Online"] && ![self boolValueForProperty:@"Connecting"]) {
[self setPasswordTemporarily:inPassword];
//Time to connect!
diff -r da2a143f9168 -r 72840c154304 Frameworks/Adium Framework/Source/AIService.m
--- a/Frameworks/Adium Framework/Source/AIService.m Fri Jun 24 14:20:49 2011 -0500
+++ b/Frameworks/Adium Framework/Source/AIService.m Fri Jun 24 15:38:55 2011 -0500
@@ -284,7 +284,8 @@
* Offers further distinction of allowed characters, for situations where certain characters are allowed
* for our account name only, or characters which are allowed in user names are forbidden in our own account name.
* If this distinction is not made, do not subclass this methods and instead subclass allowedCharacters.
- * @return NSCharacterSet of allowed characters
+ *
+ * @return NSCharacterSet of allowed characters, or nil if all characters are allowed
*/
- (NSCharacterSet *)allowedCharactersForUIDs
{
@@ -297,11 +298,12 @@
* Ignored characters for user names on this service. Ignored characters are stripped from account and contact names
* before they are used, but the user is free to type them and they may be used by the service code. For instance,
* spaces are allowed in AIM usernames, but "ad am" is treated as equal to "adam" because space is an ignored character.
- * @return NSCharacterSet of ignored characters
+ *
+ * @return NSCharacterSet of ignored characters, or nil if no characters are ignored
*/
- (NSCharacterSet *)ignoredCharacters
{
- return [NSCharacterSet characterSetWithCharactersInString:@""];
+ return nil;
}
/*!
@@ -475,6 +477,11 @@
NSCharacterSet *allowedCharacters = [self allowedCharactersForUIDs];
NSCharacterSet *ignoredCharacters = [self ignoredCharacters];
+ /* If all characters are allowed, and we're either not removing ignored characters OR there are none, no change
+ * needed. */
+ if (!allowedCharacters && (!removeIgnored || !ignoredCharacters))
+ return [[inUID copy] autorelease];
+
//Prepare a little buffer for our filtered UID
unsigned destLength = 0;
unsigned workingStringLength = [workingString length];
diff -r da2a143f9168 -r 72840c154304 Plugins/Purple Service/AIFacebookXMPPAccount.h
--- a/Plugins/Purple Service/AIFacebookXMPPAccount.h Fri Jun 24 14:20:49 2011 -0500
+++ b/Plugins/Purple Service/AIFacebookXMPPAccount.h Fri Jun 24 15:38:55 2011 -0500
@@ -10,9 +10,11 @@
@class AIFacebookXMPPOAuthWebViewWindowController;
-#define APP_ID "164063256994618"
-#define API_KEY "add7b04ecedcd84645f3c32e7884682d"
-#define APP_SECRET "bb9d2d9771790e69a0e943771ddf33c8"
+#define ADIUM_APP_ID "164063256994618"
+#define ADIUM_API_KEY "add7b04ecedcd84645f3c32e7884682d"
+
+/* deprecated? This is called the 'App Secret' on Facebook's developer page. */
+#define ADIUM_API_SECRET "bb9d2d9771790e69a0e943771ddf33c8"
@interface AIFacebookXMPPAccount : CBPurpleAccount {
AIFacebookXMPPOAuthWebViewWindowController *oAuthWC;
diff -r da2a143f9168 -r 72840c154304 Plugins/Purple Service/AIFacebookXMPPAccount.m
--- a/Plugins/Purple Service/AIFacebookXMPPAccount.m Fri Jun 24 14:20:49 2011 -0500
+++ b/Plugins/Purple Service/AIFacebookXMPPAccount.m Fri Jun 24 15:38:55 2011 -0500
@@ -16,6 +16,8 @@
#import "auth_fb.h"
#import "auth.h"
+#import <AIUtilities/AIKeychain.h>
+
#import "AIFacebookXMPPOAuthWebViewWindowController.h"
#import "JSONKit.h"
@@ -51,6 +53,25 @@
@synthesize oAuthToken;
@synthesize networkState, connection, connectionResponse, connectionData;
++ (BOOL)uidIsValidForFacebook:(NSString *)inUID
+{
+ return ((inUID.length > 0) &&
+ [inUID stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]].length == 0);
+}
+
+- (id)initWithUID:(NSString *)inUID internalObjectID:(NSString *)inInternalObjectID service:(AIService *)inService
+{
+ if ((self = [super initWithUID:inUID internalObjectID:inInternalObjectID service:inService])) {
+ if (![[self class] uidIsValidForFacebook:self.UID]) {
+ [self setValue:[NSNumber numberWithBool:YES]
+ forProperty:@"Prompt For Password On Next Connect"
+ notify:NotifyNever];
+ }
+ }
+
+ return self;
+}
+
- (void)dealloc
{
[oAuthWC release];
@@ -81,16 +102,29 @@
return @"chat.facebook.com";
}
+- (NSString *)apiSecretAccountName
+{
+ return [NSString stringWithFormat:@"Adium.FB.%@", [self internalObjectID]];
+}
+
- (void)configurePurpleAccount
{
[super configurePurpleAccount];
purple_account_set_username(account, self.purpleAccountName);
purple_account_set_string(account, "connection_security", "");
- purple_account_set_string(account, "fb_api_key", API_KEY);
- purple_account_set_string(account, "fb_api_secret", APP_SECRET
-
- /*[[self preferenceForKey:@"FBSessionSecret" group:GROUP_ACCOUNT_STATUS] UTF8String]*/);
+ purple_account_set_string(account, "fb_api_key", ADIUM_API_KEY);
+
+/*
+ //Uncomment along with storage code in promoteSessionDidFinishLoading::: to use the session secret.
+ NSString *apiSecret = [[AIKeychain defaultKeychain_error:NULL] findGenericPasswordForService:self.service.serviceID
+ account:self.apiSecretAccountName
+ keychainItem:NULL
+ error:NULL];
+ purple_account_set_string(account, "fb_api_secret", [apiSecret UTF8String]);
+*/
+
+ purple_account_set_string(account, "fb_api_secret", ADIUM_API_SECRET);
}
- (const char *)purpleAccountName
@@ -98,7 +132,8 @@
NSString *userNameWithHost = nil, *completeUserName = nil;
BOOL serverAppendedToUID;
- serverAppendedToUID = ([UID rangeOfString:@"@"].location != NSNotFound);
+ serverAppendedToUID = ([UID rangeOfString:[self serverSuffix]
+ options:(NSCaseInsensitiveSearch | NSBackwardsSearch | NSAnchoredSearch)].location != NSNotFound);
if (serverAppendedToUID) {
userNameWithHost = UID;
@@ -130,6 +165,7 @@
{
if ((returnCode == AIPasswordPromptOKReturn) && (inPassword.length == 0)) {
/* No password retrieved from the keychain */
+ AILog(@"No password for %@; requesting auth");
[self requestFacebookAuthorization];
} else {
@@ -209,11 +245,19 @@
{
self.oAuthWC = [[[AIFacebookXMPPOAuthWebViewWindowController alloc] init] autorelease];
self.oAuthWC.account = self;
-
+
+ NSLog(@"Requesting facebook auth for %@; UID %@; password %@", self, self.UID, [adium.accountController passwordForAccount:self]);
+
if (self.migratingAccount) {
+ /* We're migrating from an entirely separate AIAccount (an old, http-based Facebook account) to this one */
self.oAuthWC.autoFillUsername = self.migratingAccount.UID;
self.oAuthWC.autoFillPassword = [adium.accountController passwordForAccount:self.migratingAccount];
[self.oAuthWC.window setTitle:[NSString stringWithFormat:AILocalizedString(@"Migrating %@", nil), self.migratingAccount.UID]];
+
+ } else if (![[self class] uidIsValidForFacebook:self.UID]) {
+ /* We have a UID which isn't a Facebook numeric username. That can come from the setup wizard, for example. */
+ self.oAuthWC.autoFillUsername = self.UID;
+ self.oAuthWC.autoFillPassword = [adium.accountController passwordForAccount:self];
}
[self.oAuthWC showWindow:self];
@@ -271,21 +315,36 @@
return;
}
- NSString *secret = [[[NSString alloc] initWithData:secretData encoding:NSUTF8StringEncoding] autorelease];
- secret = [secret substringWithRange:NSMakeRange(1, [secret length] - 2)]; // strip off the quotes
NSString *sessionKey = [[[self oAuthToken] componentsSeparatedByString:@"|"] objectAtIndex:1];
[[adium accountController] setPassword:sessionKey forAccount:self];
- [self setPasswordTemporarily:sessionKey];
-
- [self setPreference:secret
- forKey:@"FBSessionSecret"
- group:GROUP_ACCOUNT_STATUS];
-
+
+ /* Uncomment the below to store the Session Secret in the keychain. It doesn't seem to be used.
+
+ NSString *secret = [[[NSString alloc] initWithData:secretData encoding:NSUTF8StringEncoding] autorelease];
+ secret = [secret substringWithRange:NSMakeRange(1, [secret length] - 2)]; // strip off the quotes
+
+
+ //Delete before adding; otherwise we'll just get errSecDuplicateItem
+ [[AIKeychain defaultKeychain_error:NULL] deleteGenericPasswordForService:self.service.serviceID
+ account:self.apiSecretAccountName
+ error:NULL];
+ [[AIKeychain defaultKeychain_error:NULL] addGenericPassword:secret
+ forService:self.service.serviceID
+ account:self.apiSecretAccountName
+ keychainItem:NULL
+ error:NULL];
+ */
self.oAuthWC = nil;
self.oAuthToken = nil;
/* When we're newly authorized, connect! */
+ [self passwordReturnedForConnect:sessionKey
+ returnCode:AIPasswordPromptOKReturn
+ context:nil];
+
+ /* Restart the connect process; we're currently considered 'connecting', so passwordReturnedForConnect:::
+ * isn't going to restart it for us. */
[self connect];
if (self.migratingAccount) {
@@ -393,3 +452,4 @@
}
@end
+
\ No newline at end of file
diff -r da2a143f9168 -r 72840c154304 Plugins/Purple Service/AIFacebookXMPPAccountViewController.m
--- a/Plugins/Purple Service/AIFacebookXMPPAccountViewController.m Fri Jun 24 14:20:49 2011 -0500
+++ b/Plugins/Purple Service/AIFacebookXMPPAccountViewController.m Fri Jun 24 15:38:55 2011 -0500
@@ -10,6 +10,7 @@
#import "AIFacebookXMPPAccountViewController.h"
#import <Adium/AIAccount.h>
#import <Adium/AIAccountControllerProtocol.h>
+#import <AIUtilities/AIStringAdditions.h>
@implementation AIFacebookXMPPAccountViewController
@synthesize view_migration, textField_migrationStatus, button_migrationHelp, button_migrationOAuthStart, migrationSpinner;
@@ -50,7 +51,8 @@
{
[super configureForAccount:inAccount];
- if (account.UID && [[adium.accountController passwordForAccount:account] length]) {
+ if ([[AIFacebookXMPPAccount class] uidIsValidForFacebook:account.UID] &&
+ [adium.accountController passwordForAccount:account].length) {
[textField_OAuthStatus setStringValue:AILocalizedString(@"Adium currently has access to your account.", nil)];
[button_OAuthStart setEnabled:NO];
}
@@ -65,6 +67,8 @@
{
if (sender == button_OAuthStart || sender == button_migrationOAuthStart) {
[(AIFacebookXMPPAccount *)account requestFacebookAuthorization];
+ [textField_OAuthStatus setStringValue:[AILocalizedString(@"Requesting authorization", nil) stringByAppendingEllipsis]];
+
} else if (sender == button_migrationHelp) {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://trac.adium.im/wiki/FacebookChat"]];
} else
diff -r da2a143f9168 -r 72840c154304 Plugins/Purple Service/AIFacebookXMPPOAuthWebViewWindowController.m
--- a/Plugins/Purple Service/AIFacebookXMPPOAuthWebViewWindowController.m Fri Jun 24 14:20:49 2011 -0500
+++ b/Plugins/Purple Service/AIFacebookXMPPOAuthWebViewWindowController.m Fri Jun 24 15:38:55 2011 -0500
@@ -54,7 +54,7 @@
[super showWindow:sender];
[webView setMainFrameURL:@"https://graph.facebook.com/oauth/authorize?"
- @"client_id=" APP_ID "&"
+ @"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&"
diff -r da2a143f9168 -r 72840c154304 Plugins/Purple Service/AIFacebookXMPPService.m
--- a/Plugins/Purple Service/AIFacebookXMPPService.m Fri Jun 24 14:20:49 2011 -0500
+++ b/Plugins/Purple Service/AIFacebookXMPPService.m Fri Jun 24 15:38:55 2011 -0500
@@ -77,12 +77,9 @@
return AILocalizedString(@"Email",nil);
}
+/* Allow any characters; technically this should be the email-acceptable-characters regexp. */
- (NSCharacterSet *)allowedCharacters{
- return [NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_ "];
-}
-
-- (NSCharacterSet *)allowedCharactersForUIDs{
- return [NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"];
+ return nil;
}
- (AIServiceImportance)serviceImportance
More information about the commits
mailing list