Plugins/Purple Service/AIFacebookXMPPAccount.m
author Thijs Alkemade <thijsalkemade@gmail.com>
Tue, 18 Sep 2012 23:06:14 +0200
branchGTalkOAuth2Support
changeset 5089 a761745f82a1
parent 4766 15b9e88f3fbc
permissions -rw-r--r--
Started working on OAuth2 support for GTalk.

Abstracted the OAuth2 support of Facebook into a separate AIPurpleOAuthJabberAccount.

Logging in on GTalk gets to the auth token.

Refs #16161
3938
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
     1
//
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
     2
//  AIFacebookXMPPAccount.m
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
     3
//  Adium
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
     4
//
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
     5
//  Created by Colin Barrett on 11/18/10.
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
     7
//
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
     8
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
     9
#import "AIFacebookXMPPAccount.h"
4025
ac7aa9e12a56 If the auth window closes, let the facebook account know that auth failed. Also, provide a bit more information when migrating accounts: 'The new version of Adium has a much more reliable Facebook Chat service. Log in to use your Facebook account with Adium.'
Evan Schoenberg
parents: 4015
diff changeset
    10
#import "AIFacebookXMPPService.h"
3938
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    11
#import <Adium/AIStatus.h>
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    12
#import <Adium/AIStatusControllerProtocol.h>
3954
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
    13
#import <Adium/AIListContact.h>
3938
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    14
#import "adiumPurpleCore.h"
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    15
#import <libpurple/jabber.h>
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    16
#import "ESPurpleJabberAccount.h"
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    17
#import "auth_fb.h"
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    18
#import "auth.h"
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    19
3983
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    20
#import <AIUtilities/AIKeychain.h>
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    21
5089
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
    22
#import "AIXMPPOAuthWebViewWindowController.h"
3958
eae6d181f858 Fixed handling of Facebook authorization failures by reprompting for authorization rather than showing a useless password prompt window. Also, reorganized related code and simplified the code path. Fixes #15039
Evan Schoenberg
parents: 3955
diff changeset
    23
eae6d181f858 Fixed handling of Facebook authorization failures by reprompting for authorization rather than showing a useless password prompt window. Also, reorganized related code and simplified the code path. Fixes #15039
Evan Schoenberg
parents: 3955
diff changeset
    24
#import <Adium/AIAccountControllerProtocol.h>
eae6d181f858 Fixed handling of Facebook authorization failures by reprompting for authorization rather than showing a useless password prompt window. Also, reorganized related code and simplified the code path. Fixes #15039
Evan Schoenberg
parents: 3955
diff changeset
    25
#import <Adium/AIPasswordPromptController.h>
3970
00653d87cf77 Migrate pidgin-facebook accounts to xmpp accounts fixes #13999. The account will start its migration on connect or when the account is being edited (I might be misusing the AIEditAccount notification for that). Users with more than one Facebook account will only get one auto-migrated.
Frank Dowsett <wixardy@adium.im>
parents: 3968
diff changeset
    26
#import <Adium/AIService.h>
00653d87cf77 Migrate pidgin-facebook accounts to xmpp accounts fixes #13999. The account will start its migration on connect or when the account is being edited (I might be misusing the AIEditAccount notification for that). Users with more than one Facebook account will only get one auto-migrated.
Frank Dowsett <wixardy@adium.im>
parents: 3968
diff changeset
    27
4766
15b9e88f3fbc Fix for a typo that prevented compilation on case-sensitive volumes.
James De Ricco <jcdericco@optonline.net>
parents: 4275
diff changeset
    28
#import <libpurple/auth.h>
4015
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
    29
#import "auth_fb.h"
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
    30
3938
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    31
@implementation AIFacebookXMPPAccount
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    32
3992
8af85a76ef99 Reworked the migration process for facebook-http to facebook-xmpp:
Evan Schoenberg
parents: 3984
diff changeset
    33
@synthesize migrationData;
3978
b1075fa1748f FBXMPP: We now make our network requests off the main thread. Woo!
Colin Barrett <colin@springsandstruts.com>
parents: 3976
diff changeset
    34
5089
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
    35
+ (BOOL)uidIsValid:(NSString *)inUID
3983
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    36
{
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    37
	return ((inUID.length > 0) &&
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    38
			[inUID stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]].length == 0);
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    39
}
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    40
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    41
- (id)initWithUID:(NSString *)inUID internalObjectID:(NSString *)inInternalObjectID service:(AIService *)inService
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    42
{
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    43
	if ((self = [super initWithUID:inUID internalObjectID:inInternalObjectID service:inService])) {
5089
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
    44
		if (![[self class] uidIsValid:self.UID]) {
3983
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    45
			[self setValue:[NSNumber numberWithBool:YES]
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    46
			   forProperty:@"Prompt For Password On Next Connect"
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    47
					notify:NotifyNever];
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    48
		}
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    49
	}
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    50
	
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    51
	return self;
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    52
}
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    53
3953
e3560542497a A little cleanup and adding #pragma marks
Evan Schoenberg
parents: 3950
diff changeset
    54
#pragma mark Connectivitiy
3938
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    55
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    56
- (const char*)protocolPlugin
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    57
{
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    58
	return "prpl-jabber";
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    59
}
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    60
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    61
- (NSString *)serverSuffix
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    62
{
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    63
	return @"@chat.facebook.com";
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    64
}
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    65
3947
6ca0e4c7cdcf Specify a host for network-reachability-code purposes
Evan Schoenberg
parents: 3946
diff changeset
    66
/* Specify a host for network-reachability-code purposes */
6ca0e4c7cdcf Specify a host for network-reachability-code purposes
Evan Schoenberg
parents: 3946
diff changeset
    67
- (NSString *)host
6ca0e4c7cdcf Specify a host for network-reachability-code purposes
Evan Schoenberg
parents: 3946
diff changeset
    68
{
6ca0e4c7cdcf Specify a host for network-reachability-code purposes
Evan Schoenberg
parents: 3946
diff changeset
    69
	return @"chat.facebook.com";
6ca0e4c7cdcf Specify a host for network-reachability-code purposes
Evan Schoenberg
parents: 3946
diff changeset
    70
}
6ca0e4c7cdcf Specify a host for network-reachability-code purposes
Evan Schoenberg
parents: 3946
diff changeset
    71
3983
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    72
- (NSString *)apiSecretAccountName
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    73
{
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    74
	return [NSString stringWithFormat:@"Adium.FB.%@", [self internalObjectID]];
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    75
}
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    76
3938
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    77
- (void)configurePurpleAccount
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    78
{
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    79
	[super configurePurpleAccount];
3946
147fda16f856 The session secret is used with each connect cycle, and it should be stable. Store it when we get it during OAuth, then retrieve it when connecting. Refs #15038 (fixing the most broken part; the account now works across restarting ADium)
Evan Schoenberg
parents: 3945
diff changeset
    80
3938
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    81
	purple_account_set_username(account, self.purpleAccountName);
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    82
	purple_account_set_string(account, "connection_security", "");
3983
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    83
    purple_account_set_string(account, "fb_api_key", ADIUM_API_KEY);
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    84
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    85
/* 
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    86
 //Uncomment along with storage code in promoteSessionDidFinishLoading::: to use the session secret. 
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    87
	NSString *apiSecret = [[AIKeychain defaultKeychain_error:NULL] findGenericPasswordForService:self.service.serviceID
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    88
																						 account:self.apiSecretAccountName
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    89
																					keychainItem:NULL
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    90
																						   error:NULL];	
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    91
	purple_account_set_string(account, "fb_api_secret", [apiSecret UTF8String]);
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    92
*/	
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    93
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
    94
    purple_account_set_string(account, "fb_api_secret", ADIUM_API_SECRET);
3938
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    95
}
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
    96
4015
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
    97
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
    98
/* Add the authentication mechanism for X-FACEBOOK-PLATFORM. Note that if the server offers it,
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
    99
 * it will be used preferentially over any other mechanism e.g. DIGEST-MD5. */
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   100
- (void)setFacebookMechEnabled:(BOOL)inEnabled
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   101
{
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   102
	static BOOL enabledFacebookMech = NO;
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   103
	if (inEnabled != enabledFacebookMech) {
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   104
		if (inEnabled)
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   105
			jabber_auth_add_mech(jabber_auth_get_fb_mech());
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   106
		else
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   107
			jabber_auth_remove_mech(jabber_auth_get_fb_mech());
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   108
		
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   109
		enabledFacebookMech = inEnabled;
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   110
	}
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   111
}
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   112
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   113
- (void)connect
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   114
{
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   115
	[self setFacebookMechEnabled:YES];
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   116
	[super connect];
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   117
}
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   118
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   119
- (void)didConnect
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   120
{
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   121
	[self setFacebookMechEnabled:NO];
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   122
	[super didConnect];	
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   123
}
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   124
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   125
- (void)didDisconnect
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   126
{
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   127
	[self setFacebookMechEnabled:NO];
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   128
	[super didDisconnect];	
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   129
}
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   130
5089
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   131
- (NSString *)graphURLForToken:(NSString *)token
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   132
{
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   133
	return [NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@", token];
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   134
}
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   135
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   136
- (NSString *)promoteURLForToken:(NSString *)token
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   137
{
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   138
	return [NSString stringWithFormat:@"https://api.facebook.com/method/auth.promoteSession?access_token=%@&format=JSON", token];
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   139
}
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   140
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   141
- (NSString *)authorizeURL
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   142
{
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   143
	return @"https://graph.facebook.com/oauth/authorize?"
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   144
	@"client_id=" ADIUM_APP_ID "&"
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   145
	@"redirect_uri=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html&"
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   146
	@"scope=xmpp_login,offline_access&"
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   147
	@"type=user_agent&"
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   148
	@"display=popup";
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   149
}
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   150
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   151
- (NSString *)frameURLHost
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   152
{
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   153
	return @"www.facebook.com";
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   154
}
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   155
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   156
- (NSString *)frameURLPath
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   157
{
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   158
	return @"/connect/login_success.html";
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   159
}
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   160
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   161
3938
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   162
- (const char *)purpleAccountName
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   163
{
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   164
	NSString	*userNameWithHost = nil, *completeUserName = nil;
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   165
	BOOL		serverAppendedToUID;
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   166
	
3983
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
   167
	serverAppendedToUID = ([UID rangeOfString:[self serverSuffix]
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
   168
									  options:(NSCaseInsensitiveSearch | NSBackwardsSearch | NSAnchoredSearch)].location != NSNotFound);
3938
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   169
	
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   170
	if (serverAppendedToUID) {
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   171
		userNameWithHost = UID;
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   172
	} else {
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   173
		userNameWithHost = [UID stringByAppendingString:[self serverSuffix]];
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   174
	}
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   175
	
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   176
	completeUserName = [NSString stringWithFormat:@"-%@/Adium" ,userNameWithHost];
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   177
	
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   178
	return [completeUserName UTF8String];
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   179
}
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   180
3968
dffff23e9918 Don't allow a Facebook account to unregister itself with the server.
Frank Dowsett <wixardy@adium.im>
parents: 3961
diff changeset
   181
- (BOOL)allowAccountUnregistrationIfSupportedByLibpurple
dffff23e9918 Don't allow a Facebook account to unregister itself with the server.
Frank Dowsett <wixardy@adium.im>
parents: 3961
diff changeset
   182
{
dffff23e9918 Don't allow a Facebook account to unregister itself with the server.
Frank Dowsett <wixardy@adium.im>
parents: 3961
diff changeset
   183
	return NO;
dffff23e9918 Don't allow a Facebook account to unregister itself with the server.
Frank Dowsett <wixardy@adium.im>
parents: 3961
diff changeset
   184
}
dffff23e9918 Don't allow a Facebook account to unregister itself with the server.
Frank Dowsett <wixardy@adium.im>
parents: 3961
diff changeset
   185
3954
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   186
#pragma mark Contacts
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   187
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   188
/*!
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   189
 * @brief Set an alias for a contact
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   190
 *
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   191
 * Normally, we consider the name a 'serverside alias' unless it matches the UID's characters
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   192
 * However, the UID in facebook should never be presented to the user if possible; it's for internal use
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   193
 * only.  We'll therefore consider any alias a formatted UID such that it will replace the UID when displayed
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   194
 * in Adium.
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   195
 */
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   196
- (void)updateContact:(AIListContact *)theContact toAlias:(NSString *)purpleAlias
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   197
{
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   198
	if (![purpleAlias isEqualToString:theContact.formattedUID] && 
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   199
		![purpleAlias isEqualToString:theContact.UID]) {
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   200
		[theContact setFormattedUID:purpleAlias
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   201
							 notify:NotifyLater];
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   202
		
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   203
		//Apply any changes
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   204
		[theContact notifyOfChangedPropertiesSilently:silentAndDelayed];
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   205
	}
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   206
}
dcbfaa8761b3 The facebook JID is not useful to 99.9% of our users. We could include the Facebook User ID in the Get Info window's info. Treat the person's name as their formatted UID so that we don't show the JID. Fixes #15040
Evan Schoenberg
parents: 3953
diff changeset
   207
3955
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   208
- (NSMutableArray *)arrayOfDictionariesFromPurpleNotifyUserInfo:(PurpleNotifyUserInfo *)user_info forContact:(AIListContact *)contact
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   209
{
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   210
	NSMutableArray *array = [super arrayOfDictionariesFromPurpleNotifyUserInfo:user_info forContact:contact];
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   211
	
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   212
	NSString *displayUID = contact.UID;
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   213
	displayUID = [displayUID stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"-"]];
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   214
	if ([displayUID hasSuffix:@"@chat.facebook.com"])
4015
4ba237756667 Enable and disable the facebook mech on the fly. This means that a previously configured XMPP account for chat.facebook.com can still conncet (unless it tries to connect concurrently with an actual Facebook service account... at which point I just can't help you, mate.) Fixes #15289
Evan Schoenberg
parents: 3993
diff changeset
   215
		displayUID = [displayUID substringToIndex:(displayUID.length - @"@chat.facebook.com".length)];
3955
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   216
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   217
	[array addObject:[NSDictionary dictionaryWithObjectsAndKeys:
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   218
					  AILocalizedString(@"Facebook ID", nil), KEY_KEY,
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   219
					  displayUID, KEY_VALUE,
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   220
					  nil]];
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   221
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   222
	return array;
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   223
}
2890658820d1 Include the Facebook ID in the get info window. Refs #15040
Evan Schoenberg
parents: 3954
diff changeset
   224
3958
eae6d181f858 Fixed handling of Facebook authorization failures by reprompting for authorization rather than showing a useless password prompt window. Also, reorganized related code and simplified the code path. Fixes #15039
Evan Schoenberg
parents: 3955
diff changeset
   225
#pragma mark Authorization
eae6d181f858 Fixed handling of Facebook authorization failures by reprompting for authorization rather than showing a useless password prompt window. Also, reorganized related code and simplified the code path. Fixes #15039
Evan Schoenberg
parents: 3955
diff changeset
   226
5089
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   227
- (void)requestAuthorization
3958
eae6d181f858 Fixed handling of Facebook authorization failures by reprompting for authorization rather than showing a useless password prompt window. Also, reorganized related code and simplified the code path. Fixes #15039
Evan Schoenberg
parents: 3955
diff changeset
   228
{
5089
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   229
	if (![[self class] uidIsValid:self.UID]) {
3992
8af85a76ef99 Reworked the migration process for facebook-http to facebook-xmpp:
Evan Schoenberg
parents: 3984
diff changeset
   230
		/* We have a UID which isn't a Facebook numeric username. That can come from:
8af85a76ef99 Reworked the migration process for facebook-http to facebook-xmpp:
Evan Schoenberg
parents: 3984
diff changeset
   231
		 *	 1. The setup wizard
8af85a76ef99 Reworked the migration process for facebook-http to facebook-xmpp:
Evan Schoenberg
parents: 3984
diff changeset
   232
		 *   2. Facebook-HTTP account from Adium <= 1.4.2
8af85a76ef99 Reworked the migration process for facebook-http to facebook-xmpp:
Evan Schoenberg
parents: 3984
diff changeset
   233
		 */
3983
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
   234
		self.oAuthWC.autoFillUsername = self.UID;
438f058cffd4 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.
Evan Schoenberg
parents: 3980
diff changeset
   235
		self.oAuthWC.autoFillPassword = [adium.accountController passwordForAccount:self];
4025
ac7aa9e12a56 If the auth window closes, let the facebook account know that auth failed. Also, provide a bit more information when migrating accounts: 'The new version of Adium has a much more reliable Facebook Chat service. Log in to use your Facebook account with Adium.'
Evan Schoenberg
parents: 4015
diff changeset
   236
		self.oAuthWC.isMigrating = ![self.service.serviceID isEqualToString:FACEBOOK_XMPP_SERVICE_ID];
5089
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   237
		
3992
8af85a76ef99 Reworked the migration process for facebook-http to facebook-xmpp:
Evan Schoenberg
parents: 3984
diff changeset
   238
		self.migrationData = [NSDictionary dictionaryWithObjectsAndKeys:
8af85a76ef99 Reworked the migration process for facebook-http to facebook-xmpp:
Evan Schoenberg
parents: 3984
diff changeset
   239
							  self.UID, @"originalUID",
8af85a76ef99 Reworked the migration process for facebook-http to facebook-xmpp:
Evan Schoenberg
parents: 3984
diff changeset
   240
							  self.service.serviceID, @"originalServiceID",
8af85a76ef99 Reworked the migration process for facebook-http to facebook-xmpp:
Evan Schoenberg
parents: 3984
diff changeset
   241
							  nil];
8af85a76ef99 Reworked the migration process for facebook-http to facebook-xmpp:
Evan Schoenberg
parents: 3984
diff changeset
   242
	}
8af85a76ef99 Reworked the migration process for facebook-http to facebook-xmpp:
Evan Schoenberg
parents: 3984
diff changeset
   243
	
5089
a761745f82a1 Started working on OAuth2 support for GTalk.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4766
diff changeset
   244
	[super requestAuthorization];
3978
b1075fa1748f FBXMPP: We now make our network requests off the main thread. Woo!
Colin Barrett <colin@springsandstruts.com>
parents: 3976
diff changeset
   245
}
b1075fa1748f FBXMPP: We now make our network requests off the main thread. Woo!
Colin Barrett <colin@springsandstruts.com>
parents: 3976
diff changeset
   246
3938
035ebbd633af First pass at Facebook XMPP. Definitely **NOT** ready for actual use, but it does connect.
Colin Barrett <colin@springsandstruts.com>
parents:
diff changeset
   247
@end