Skip to content

Commit

Permalink
Merge pull request #252 from ParsePlatform/nlutsenko.authDelegate
Browse files Browse the repository at this point in the history
Cleanup third party authentication methods in PFUser.
  • Loading branch information
nlutsenko committed Sep 14, 2015
2 parents 7e463ff + f179c77 commit f5e1546
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 185 deletions.
12 changes: 6 additions & 6 deletions Parse.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
810ECC7E1B573D28002944D4 /* PFTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 810ECC791B573D28002944D4 /* PFTestCase.m */; };
810ECC7F1B573D28002944D4 /* PFUnitTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 810ECC7C1B573D28002944D4 /* PFUnitTestCase.m */; };
810ECC801B573D28002944D4 /* PFUnitTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 810ECC7C1B573D28002944D4 /* PFUnitTestCase.m */; };
811083F21BA2580100FC7F65 /* PFAuthenticationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 811083F11BA2580100FC7F65 /* PFAuthenticationProvider.h */; settings = {ATTRIBUTES = (Public, ); }; };
811083F31BA2580100FC7F65 /* PFAuthenticationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 811083F11BA2580100FC7F65 /* PFAuthenticationProvider.h */; settings = {ATTRIBUTES = (Public, ); }; };
811083F21BA2580100FC7F65 /* PFUserAuthenticationDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 811083F11BA2580100FC7F65 /* PFUserAuthenticationDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
811083F31BA2580100FC7F65 /* PFUserAuthenticationDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 811083F11BA2580100FC7F65 /* PFUserAuthenticationDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
811214731B3E1CF10052741B /* PFObjectBatchController.h in Headers */ = {isa = PBXBuildFile; fileRef = 811214711B3E1CF10052741B /* PFObjectBatchController.h */; };
811214741B3E1CF10052741B /* PFObjectBatchController.h in Headers */ = {isa = PBXBuildFile; fileRef = 811214711B3E1CF10052741B /* PFObjectBatchController.h */; };
811214751B3E1CF10052741B /* PFObjectBatchController.m in Sources */ = {isa = PBXBuildFile; fileRef = 811214721B3E1CF10052741B /* PFObjectBatchController.m */; };
Expand Down Expand Up @@ -1098,7 +1098,7 @@
810ECC791B573D28002944D4 /* PFTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFTestCase.m; sourceTree = "<group>"; };
810ECC7B1B573D28002944D4 /* PFUnitTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFUnitTestCase.h; sourceTree = "<group>"; };
810ECC7C1B573D28002944D4 /* PFUnitTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFUnitTestCase.m; sourceTree = "<group>"; };
811083F11BA2580100FC7F65 /* PFAuthenticationProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFAuthenticationProvider.h; sourceTree = "<group>"; };
811083F11BA2580100FC7F65 /* PFUserAuthenticationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFUserAuthenticationDelegate.h; sourceTree = "<group>"; };
811214711B3E1CF10052741B /* PFObjectBatchController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFObjectBatchController.h; sourceTree = "<group>"; };
811214721B3E1CF10052741B /* PFObjectBatchController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFObjectBatchController.m; sourceTree = "<group>"; };
81146C7C1A785203001F8473 /* PFRESTObjectCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFRESTObjectCommand.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1610,7 +1610,6 @@
9739513916B9D28E0010B884 /* PFAnalytics.m */,
638CBBB415191435004F54E4 /* PFAnonymousUtils.h */,
638CBBB515191435004F54E4 /* PFAnonymousUtils.m */,
811083F11BA2580100FC7F65 /* PFAuthenticationProvider.h */,
805D3D9F15E31241007E8D10 /* PFCloud.h */,
805D3DA015E31241007E8D10 /* PFCloud.m */,
81EB6632198A7FA600851598 /* PFConfig.h */,
Expand Down Expand Up @@ -1641,6 +1640,7 @@
812145761AA4A4C1000B23F5 /* PFSession.m */,
0925ABF513D791770095FEFA /* PFUser.h */,
0925ABF613D791770095FEFA /* PFUser.m */,
811083F11BA2580100FC7F65 /* PFUserAuthenticationDelegate.h */,
E9BBE98E16D18E5800CD7B52 /* PFObject+Subclass.h */,
E9E81E8316EEF93E001D034F /* PFSubclassing.h */,
816F97101A93FAC400CADE60 /* PFNullability.h */,
Expand Down Expand Up @@ -3138,7 +3138,7 @@
810749AE1B74662B00682EEB /* PFURLSessionFileDownloadTaskDelegate.h in Headers */,
F5B0B2FC1B449F1D00F3EBC4 /* PFInternalUtils.h in Headers */,
F5B0B2FD1B449F1D00F3EBC4 /* PFKeychainStore.h in Headers */,
811083F21BA2580100FC7F65 /* PFAuthenticationProvider.h in Headers */,
811083F21BA2580100FC7F65 /* PFUserAuthenticationDelegate.h in Headers */,
818D58731B5DAAFE00813989 /* PFCommandRunningConstants.h in Headers */,
F5B0B2FF1B449F1D00F3EBC4 /* PFMulticastDelegate.h in Headers */,
81C6BDF41B4DD32700553A83 /* PFCurrentObjectControlling.h in Headers */,
Expand Down Expand Up @@ -3363,7 +3363,7 @@
F5B0B3461B44A33200F3EBC4 /* PFPushState.h in Headers */,
F5B0B3471B44A33200F3EBC4 /* PFPushState_Private.h in Headers */,
812B63011B5F30D3009CEAA9 /* PFObjectFileCoder.h in Headers */,
811083F31BA2580100FC7F65 /* PFAuthenticationProvider.h in Headers */,
811083F31BA2580100FC7F65 /* PFUserAuthenticationDelegate.h in Headers */,
F5B0B3481B44A33200F3EBC4 /* PFMutablePushState.h in Headers */,
F5B0B3491B44A33200F3EBC4 /* PFPushController.h in Headers */,
F5B0B34A1B44A33200F3EBC4 /* PFPushChannelsController.h in Headers */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import <Foundation/Foundation.h>

#import <Parse/PFConstants.h>
#import <Parse/PFAuthenticationProvider.h>
#import <Parse/PFUserAuthenticationDelegate.h>

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -23,19 +23,18 @@ NS_ASSUME_NONNULL_BEGIN
/// @name Authentication Providers
///--------------------------------------

- (void)registerAuthenticationProvider:(id<PFAuthenticationProvider>)provider;
- (void)unregisterAuthenticationProvider:(id<PFAuthenticationProvider>)provider;
- (void)registerAuthenticationDelegate:(id<PFUserAuthenticationDelegate>)delegate forAuthType:(NSString *)authType;
- (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType;

- (id<PFAuthenticationProvider>)authenticationProviderForAuthType:(NSString *)authType;
- (id<PFUserAuthenticationDelegate>)authenticationDelegateForAuthType:(NSString *)authType;

///--------------------------------------
/// @name Authentication
///--------------------------------------

- (BFTask *)deauthenticateAsyncWithProviderForAuthType:(NSString *)authType;

- (BFTask *)restoreAuthenticationAsyncWithAuthData:(nullable NSDictionary *)authData
forProviderWithAuthType:(NSString *)authType;
- (BFTask PF_GENERIC(NSNumber *) *)restoreAuthenticationAsyncWithAuthData:(nullable NSDictionary *)authData
forProviderWithAuthType:(NSString *)authType;
- (BFTask PF_GENERIC(NSNumber *) *)deauthenticateAsyncWithProviderForAuthType:(NSString *)authType;

///--------------------------------------
/// @name Log In
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ - (instancetype)init {
#pragma mark - Authentication Providers
///--------------------------------------

- (void)registerAuthenticationProvider:(id<PFAuthenticationProvider>)provider {
PFParameterAssert(provider, @"Authentication provider can't be `nil`.");

NSString *authType = [[provider class] authType];
- (void)registerAuthenticationDelegate:(id<PFUserAuthenticationDelegate>)delegate forAuthType:(NSString *)authType {
PFParameterAssert(delegate, @"Authentication delegate can't be `nil`.");
PFParameterAssert(authType, @"Authentication provider's `authType` can't be `nil`.");
PFConsistencyAssert(![self authenticationProviderForAuthType:authType],
PFConsistencyAssert(![self authenticationDelegateForAuthType:authType],
@"Authentication provider already registered for authType `%@`.", authType);

dispatch_sync(_dataAccessQueue, ^{
_authenticationProviders[authType] = provider;
_authenticationProviders[authType] = delegate;
});

// TODO: (nlutsenko) Decouple this further.
Expand All @@ -63,8 +61,7 @@ - (void)registerAuthenticationProvider:(id<PFAuthenticationProvider>)provider {
}
}

- (void)unregisterAuthenticationProvider:(id<PFAuthenticationProvider>)provider {
NSString *authType = [[provider class] authType];
- (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType {
if (!authType) {
return;
}
Expand All @@ -73,12 +70,12 @@ - (void)unregisterAuthenticationProvider:(id<PFAuthenticationProvider>)provider
});
}

- (id<PFAuthenticationProvider>)authenticationProviderForAuthType:(NSString *)authType {
- (id<PFUserAuthenticationDelegate>)authenticationDelegateForAuthType:(NSString *)authType {
if (!authType) {
return nil;
}

__block id<PFAuthenticationProvider> provider = nil;
__block id<PFUserAuthenticationDelegate> provider = nil;
dispatch_sync(_dataAccessQueue, ^{
provider = _authenticationProviders[authType];
});
Expand All @@ -89,21 +86,19 @@ - (void)unregisterAuthenticationProvider:(id<PFAuthenticationProvider>)provider
#pragma mark - Authentication
///--------------------------------------

- (BFTask *)deauthenticateAsyncWithProviderForAuthType:(NSString *)authType {
id<PFAuthenticationProvider> provider = [self authenticationProviderForAuthType:authType];
if (provider) {
return [provider deauthenticateInBackground];
}
return [BFTask taskWithResult:nil];
- (BFTask PF_GENERIC(NSNumber *)*)deauthenticateAsyncWithProviderForAuthType:(NSString *)authType {
return [self restoreAuthenticationAsyncWithAuthData:nil forProviderWithAuthType:authType];
}

- (BFTask *)restoreAuthenticationAsyncWithAuthData:(nullable NSDictionary *)authData
forProviderWithAuthType:(NSString *)authType {
id<PFAuthenticationProvider> provider = [self authenticationProviderForAuthType:authType];
- (BFTask PF_GENERIC(NSNumber *)*)restoreAuthenticationAsyncWithAuthData:(nullable NSDictionary *)authData
forProviderWithAuthType:(NSString *)authType {
id<PFUserAuthenticationDelegate> provider = [self authenticationDelegateForAuthType:authType];
if (!provider) {
return [BFTask taskWithResult:nil];
return [BFTask taskWithResult:@YES];
}
return [provider restoreAuthenticationInBackgroundWithAuthData:authData];
return [BFTask taskFromExecutor:[BFExecutor defaultPriorityBackgroundExecutor] withBlock:^id {
return [BFTask taskWithResult:@([provider restoreAuthenticationWithAuthData:authData])];
}];
}

///--------------------------------------
Expand All @@ -119,8 +114,8 @@ - (BFTask *)logInUserAsyncWithAuthType:(NSString *)authType authData:(NSDictiona
PFUser *user = currentUser;
BFTask *resolveLaziness = nil;
NSDictionary *oldAnonymousData = nil;
@synchronized (user.lock) {
oldAnonymousData = user.authData[[PFAnonymousAuthenticationProvider authType]];
@synchronized(user.lock) {
oldAnonymousData = user.authData[PFUserAnonymousAuthenticationType];

// Replace any anonymity with the new linked authData
[user stripAnonymity];
Expand Down Expand Up @@ -163,7 +158,6 @@ - (BFTask *)logInUserAsyncWithAuthType:(NSString *)authType authData:(NSDictiona
return [[PFUser userController] logInCurrentUserAsyncWithAuthType:authType
authData:authData
revocableSession:[PFUser _isRevocableSessionEnabled]];

}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

#import <Foundation/Foundation.h>

#import "PFAuthenticationProvider.h"
#import <Parse/PFUserAuthenticationDelegate.h>

NS_ASSUME_NONNULL_BEGIN

@interface PFAnonymousAuthenticationProvider : NSObject <PFAuthenticationProvider>
extern NSString *const PFUserAnonymousAuthenticationType;

@interface PFAnonymousAuthenticationProvider : NSObject <PFUserAuthenticationDelegate>

/*!
Gets auth data with a fresh UUID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,16 @@

#import <Bolts/BFTask.h>

NSString *const PFUserAnonymousAuthenticationType = @"anonymous";

@implementation PFAnonymousAuthenticationProvider

///--------------------------------------
#pragma mark - PFAuthenticationProvider
#pragma mark - PFAnonymousAuthenticationProvider
///--------------------------------------

+ (NSString *)authType {
return @"anonymous";
}

- (BFTask *)deauthenticateInBackground {
return [BFTask taskWithResult:nil];
}

- (BFTask *)restoreAuthenticationInBackgroundWithAuthData:(NSDictionary *)authData {
return [BFTask taskWithResult:nil];
- (BOOL)restoreAuthenticationWithAuthData:(NSDictionary *)authData {
return YES;
}

///--------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Parse/Internal/User/PFUserPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ extern NSString *const PFUserCurrentUserKeychainItemName;
/// @name Third-party Authentication (Private)
///--------------------------------------

+ (void)_unregisterAuthenticationProvider:(id<PFAuthenticationProvider>)provider;
+ (void)_unregisterAuthenticationDelegateForAuthType:(NSString *)authType;

@end
11 changes: 5 additions & 6 deletions Parse/PFAnonymousUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ @implementation PFAnonymousUtils

+ (BFTask *)logInInBackground {
PFAnonymousAuthenticationProvider *provider = [self _authenticationProvider];
NSString *authType = [[provider class] authType];
return [PFUser logInWithAuthTypeInBackground:authType authData:provider.authData];
return [PFUser logInWithAuthTypeInBackground:PFUserAnonymousAuthenticationType authData:provider.authData];
}

+ (void)logInWithBlock:(PFUserResultBlock)block {
Expand All @@ -42,7 +41,7 @@ + (void)logInWithTarget:(id)target selector:(SEL)selector {
///--------------------------------------

+ (BOOL)isLinkedWithUser:(PFUser *)user {
return [user isLinkedWithAuthType:[[[self _authenticationProvider] class] authType]];
return [user isLinkedWithAuthType:PFUserAnonymousAuthenticationType];
}

///--------------------------------------
Expand All @@ -66,15 +65,15 @@ + (PFAnonymousAuthenticationProvider *)_authenticationProvider {
provider = authenticationProvider_;
if (!provider) {
provider = [[PFAnonymousAuthenticationProvider alloc] init];
[PFUser registerAuthenticationProvider:provider];
[PFUser registerAuthenticationDelegate:provider forAuthType:PFUserAnonymousAuthenticationType];
authenticationProvider_ = provider;
}
});
return provider;
}

+ (void)_clearAuthenticationProvider {
[PFUser _unregisterAuthenticationProvider:authenticationProvider_];
[PFUser _unregisterAuthenticationDelegateForAuthType:PFUserAnonymousAuthenticationType];
dispatch_sync([self _providerAccessQueue], ^{
authenticationProvider_ = nil;
});
Expand All @@ -86,7 +85,7 @@ + (void)_clearAuthenticationProvider {

+ (PFUser *)_lazyLogIn {
PFAnonymousAuthenticationProvider *provider = [self _authenticationProvider];
return [PFUser logInLazyUserWithAuthType:[[provider class] authType] authData:provider.authData];
return [PFUser logInLazyUserWithAuthType:PFUserAnonymousAuthenticationType authData:provider.authData];
}

@end
46 changes: 0 additions & 46 deletions Parse/PFAuthenticationProvider.h

This file was deleted.

0 comments on commit f5e1546

Please sign in to comment.