From 7d01d2a3c84adadc51802661b9a814df15ed3d44 Mon Sep 17 00:00:00 2001 From: Jens Alfke Date: Mon, 14 Sep 2015 16:33:59 -0700 Subject: [PATCH] Revert "Removed long-deprecated facebook/persona auth API in CBLReplication" This reverts commit 23c0dc260933e4d2bcc166150b0442897fe6d5e5. (See #833) --- Source/API/CBLReplication.h | 11 +++++++++++ Source/API/CBLReplication.m | 38 ++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Source/API/CBLReplication.h b/Source/API/CBLReplication.h index f4590fa19..b9a5c74c5 100644 --- a/Source/API/CBLReplication.h +++ b/Source/API/CBLReplication.h @@ -187,6 +187,17 @@ typedef NS_ENUM(unsigned, CBLReplicationStatus) { - (instancetype) init NS_UNAVAILABLE; +#ifdef CBL_DEPRECATED +@property (nonatomic, copy) NSString* facebookEmailAddress + __attribute__((deprecated("set authenticator property instead"))); +- (BOOL) registerFacebookToken: (NSString*)token forEmailAddress: (NSString*)email + __attribute__((deprecated("set authenticator property instead"))); +- (BOOL) registerPersonaAssertion: (NSString*)assertion + __attribute__((deprecated("set authenticator property instead"))); +@property (nonatomic, copy) NSString* personaEmailAddress + __attribute__((deprecated("set authenticator property instead"))); +#endif + @end diff --git a/Source/API/CBLReplication.m b/Source/API/CBLReplication.m index 9bd022e9d..378aff882 100644 --- a/Source/API/CBLReplication.m +++ b/Source/API/CBLReplication.m @@ -21,6 +21,8 @@ #import "CBLDatabase+Internal.h" #import "CBLManager+Internal.h" #import "CBL_Server.h" +#import "CBLPersonaAuthorizer.h" +#import "CBLFacebookAuthorizer.h" #import "CBLCookieStorage.h" #import "MYBlockUtils.h" #import "MYURLUtils.h" @@ -156,11 +158,41 @@ - (void) setCredential:(NSURLCredential *)cred { } +#ifdef CBL_DEPRECATED + +@synthesize facebookEmailAddress=_facebookEmailAddress; + +- (BOOL) registerFacebookToken: (NSString*)token forEmailAddress: (NSString*)email { + if (![CBLFacebookAuthorizer registerToken: token forEmailAddress: email forSite: self.remoteURL]) + return false; + self.facebookEmailAddress = email; + [self restart]; + return true; +} +#endif + + - (NSURL*) personaOrigin { return self.remoteURL.my_baseURL; } +#ifdef CBL_DEPRECATED +@synthesize personaEmailAddress=_personaEmailAddress; + +- (BOOL) registerPersonaAssertion: (NSString*)assertion { + NSString* email = [CBLPersonaAuthorizer registerAssertion: assertion]; + if (!email) { + Warn(@"Invalid Persona assertion: %@", assertion); + return false; + } + self.personaEmailAddress = email; + [self restart]; + return true; +} +#endif + + - (void) setCookieNamed: (NSString*)name withValue: (NSString*)value path: (NSString*)path @@ -225,9 +257,13 @@ - (NSDictionary*) properties { NSMutableDictionary* authDict = nil; if (_authenticator) { remoteURL = remoteURL.my_URLByRemovingUser; - } else if (_OAuth) { + } else if (_OAuth || _facebookEmailAddress || _personaEmailAddress) { remoteURL = remoteURL.my_URLByRemovingUser; authDict = $mdict({@"oauth", _OAuth}); + if (_facebookEmailAddress) + authDict[@"facebook"] = @{@"email": _facebookEmailAddress}; + if (_personaEmailAddress) + authDict[@"persona"] = @{@"email": _personaEmailAddress}; } NSDictionary* remote = $dict({@"url", remoteURL.absoluteString}, {@"headers", _headers},