Skip to content

Commit f5e1546

Browse files
committed
Merge pull request #252 from ParsePlatform/nlutsenko.authDelegate
Cleanup third party authentication methods in PFUser.
2 parents 7e463ff + f179c77 commit f5e1546

14 files changed

+136
-185
lines changed

Parse.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
810ECC7E1B573D28002944D4 /* PFTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 810ECC791B573D28002944D4 /* PFTestCase.m */; };
3535
810ECC7F1B573D28002944D4 /* PFUnitTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 810ECC7C1B573D28002944D4 /* PFUnitTestCase.m */; };
3636
810ECC801B573D28002944D4 /* PFUnitTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 810ECC7C1B573D28002944D4 /* PFUnitTestCase.m */; };
37-
811083F21BA2580100FC7F65 /* PFAuthenticationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 811083F11BA2580100FC7F65 /* PFAuthenticationProvider.h */; settings = {ATTRIBUTES = (Public, ); }; };
38-
811083F31BA2580100FC7F65 /* PFAuthenticationProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 811083F11BA2580100FC7F65 /* PFAuthenticationProvider.h */; settings = {ATTRIBUTES = (Public, ); }; };
37+
811083F21BA2580100FC7F65 /* PFUserAuthenticationDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 811083F11BA2580100FC7F65 /* PFUserAuthenticationDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
38+
811083F31BA2580100FC7F65 /* PFUserAuthenticationDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 811083F11BA2580100FC7F65 /* PFUserAuthenticationDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
3939
811214731B3E1CF10052741B /* PFObjectBatchController.h in Headers */ = {isa = PBXBuildFile; fileRef = 811214711B3E1CF10052741B /* PFObjectBatchController.h */; };
4040
811214741B3E1CF10052741B /* PFObjectBatchController.h in Headers */ = {isa = PBXBuildFile; fileRef = 811214711B3E1CF10052741B /* PFObjectBatchController.h */; };
4141
811214751B3E1CF10052741B /* PFObjectBatchController.m in Sources */ = {isa = PBXBuildFile; fileRef = 811214721B3E1CF10052741B /* PFObjectBatchController.m */; };
@@ -1098,7 +1098,7 @@
10981098
810ECC791B573D28002944D4 /* PFTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFTestCase.m; sourceTree = "<group>"; };
10991099
810ECC7B1B573D28002944D4 /* PFUnitTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFUnitTestCase.h; sourceTree = "<group>"; };
11001100
810ECC7C1B573D28002944D4 /* PFUnitTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFUnitTestCase.m; sourceTree = "<group>"; };
1101-
811083F11BA2580100FC7F65 /* PFAuthenticationProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFAuthenticationProvider.h; sourceTree = "<group>"; };
1101+
811083F11BA2580100FC7F65 /* PFUserAuthenticationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFUserAuthenticationDelegate.h; sourceTree = "<group>"; };
11021102
811214711B3E1CF10052741B /* PFObjectBatchController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFObjectBatchController.h; sourceTree = "<group>"; };
11031103
811214721B3E1CF10052741B /* PFObjectBatchController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFObjectBatchController.m; sourceTree = "<group>"; };
11041104
81146C7C1A785203001F8473 /* PFRESTObjectCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFRESTObjectCommand.h; sourceTree = "<group>"; };
@@ -1610,7 +1610,6 @@
16101610
9739513916B9D28E0010B884 /* PFAnalytics.m */,
16111611
638CBBB415191435004F54E4 /* PFAnonymousUtils.h */,
16121612
638CBBB515191435004F54E4 /* PFAnonymousUtils.m */,
1613-
811083F11BA2580100FC7F65 /* PFAuthenticationProvider.h */,
16141613
805D3D9F15E31241007E8D10 /* PFCloud.h */,
16151614
805D3DA015E31241007E8D10 /* PFCloud.m */,
16161615
81EB6632198A7FA600851598 /* PFConfig.h */,
@@ -1641,6 +1640,7 @@
16411640
812145761AA4A4C1000B23F5 /* PFSession.m */,
16421641
0925ABF513D791770095FEFA /* PFUser.h */,
16431642
0925ABF613D791770095FEFA /* PFUser.m */,
1643+
811083F11BA2580100FC7F65 /* PFUserAuthenticationDelegate.h */,
16441644
E9BBE98E16D18E5800CD7B52 /* PFObject+Subclass.h */,
16451645
E9E81E8316EEF93E001D034F /* PFSubclassing.h */,
16461646
816F97101A93FAC400CADE60 /* PFNullability.h */,
@@ -3138,7 +3138,7 @@
31383138
810749AE1B74662B00682EEB /* PFURLSessionFileDownloadTaskDelegate.h in Headers */,
31393139
F5B0B2FC1B449F1D00F3EBC4 /* PFInternalUtils.h in Headers */,
31403140
F5B0B2FD1B449F1D00F3EBC4 /* PFKeychainStore.h in Headers */,
3141-
811083F21BA2580100FC7F65 /* PFAuthenticationProvider.h in Headers */,
3141+
811083F21BA2580100FC7F65 /* PFUserAuthenticationDelegate.h in Headers */,
31423142
818D58731B5DAAFE00813989 /* PFCommandRunningConstants.h in Headers */,
31433143
F5B0B2FF1B449F1D00F3EBC4 /* PFMulticastDelegate.h in Headers */,
31443144
81C6BDF41B4DD32700553A83 /* PFCurrentObjectControlling.h in Headers */,
@@ -3363,7 +3363,7 @@
33633363
F5B0B3461B44A33200F3EBC4 /* PFPushState.h in Headers */,
33643364
F5B0B3471B44A33200F3EBC4 /* PFPushState_Private.h in Headers */,
33653365
812B63011B5F30D3009CEAA9 /* PFObjectFileCoder.h in Headers */,
3366-
811083F31BA2580100FC7F65 /* PFAuthenticationProvider.h in Headers */,
3366+
811083F31BA2580100FC7F65 /* PFUserAuthenticationDelegate.h in Headers */,
33673367
F5B0B3481B44A33200F3EBC4 /* PFMutablePushState.h in Headers */,
33683368
F5B0B3491B44A33200F3EBC4 /* PFPushController.h in Headers */,
33693369
F5B0B34A1B44A33200F3EBC4 /* PFPushChannelsController.h in Headers */,

Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#import <Foundation/Foundation.h>
1111

1212
#import <Parse/PFConstants.h>
13-
#import <Parse/PFAuthenticationProvider.h>
13+
#import <Parse/PFUserAuthenticationDelegate.h>
1414

1515
NS_ASSUME_NONNULL_BEGIN
1616

@@ -23,19 +23,18 @@ NS_ASSUME_NONNULL_BEGIN
2323
/// @name Authentication Providers
2424
///--------------------------------------
2525

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

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

3131
///--------------------------------------
3232
/// @name Authentication
3333
///--------------------------------------
3434

35-
- (BFTask *)deauthenticateAsyncWithProviderForAuthType:(NSString *)authType;
36-
37-
- (BFTask *)restoreAuthenticationAsyncWithAuthData:(nullable NSDictionary *)authData
38-
forProviderWithAuthType:(NSString *)authType;
35+
- (BFTask PF_GENERIC(NSNumber *) *)restoreAuthenticationAsyncWithAuthData:(nullable NSDictionary *)authData
36+
forProviderWithAuthType:(NSString *)authType;
37+
- (BFTask PF_GENERIC(NSNumber *) *)deauthenticateAsyncWithProviderForAuthType:(NSString *)authType;
3938

4039
///--------------------------------------
4140
/// @name Log In

Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.m

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,14 @@ - (instancetype)init {
4545
#pragma mark - Authentication Providers
4646
///--------------------------------------
4747

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

5654
dispatch_sync(_dataAccessQueue, ^{
57-
_authenticationProviders[authType] = provider;
55+
_authenticationProviders[authType] = delegate;
5856
});
5957

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

66-
- (void)unregisterAuthenticationProvider:(id<PFAuthenticationProvider>)provider {
67-
NSString *authType = [[provider class] authType];
64+
- (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType {
6865
if (!authType) {
6966
return;
7067
}
@@ -73,12 +70,12 @@ - (void)unregisterAuthenticationProvider:(id<PFAuthenticationProvider>)provider
7370
});
7471
}
7572

76-
- (id<PFAuthenticationProvider>)authenticationProviderForAuthType:(NSString *)authType {
73+
- (id<PFUserAuthenticationDelegate>)authenticationDelegateForAuthType:(NSString *)authType {
7774
if (!authType) {
7875
return nil;
7976
}
8077

81-
__block id<PFAuthenticationProvider> provider = nil;
78+
__block id<PFUserAuthenticationDelegate> provider = nil;
8279
dispatch_sync(_dataAccessQueue, ^{
8380
provider = _authenticationProviders[authType];
8481
});
@@ -89,21 +86,19 @@ - (void)unregisterAuthenticationProvider:(id<PFAuthenticationProvider>)provider
8986
#pragma mark - Authentication
9087
///--------------------------------------
9188

92-
- (BFTask *)deauthenticateAsyncWithProviderForAuthType:(NSString *)authType {
93-
id<PFAuthenticationProvider> provider = [self authenticationProviderForAuthType:authType];
94-
if (provider) {
95-
return [provider deauthenticateInBackground];
96-
}
97-
return [BFTask taskWithResult:nil];
89+
- (BFTask PF_GENERIC(NSNumber *)*)deauthenticateAsyncWithProviderForAuthType:(NSString *)authType {
90+
return [self restoreAuthenticationAsyncWithAuthData:nil forProviderWithAuthType:authType];
9891
}
9992

100-
- (BFTask *)restoreAuthenticationAsyncWithAuthData:(nullable NSDictionary *)authData
101-
forProviderWithAuthType:(NSString *)authType {
102-
id<PFAuthenticationProvider> provider = [self authenticationProviderForAuthType:authType];
93+
- (BFTask PF_GENERIC(NSNumber *)*)restoreAuthenticationAsyncWithAuthData:(nullable NSDictionary *)authData
94+
forProviderWithAuthType:(NSString *)authType {
95+
id<PFUserAuthenticationDelegate> provider = [self authenticationDelegateForAuthType:authType];
10396
if (!provider) {
104-
return [BFTask taskWithResult:nil];
97+
return [BFTask taskWithResult:@YES];
10598
}
106-
return [provider restoreAuthenticationInBackgroundWithAuthData:authData];
99+
return [BFTask taskFromExecutor:[BFExecutor defaultPriorityBackgroundExecutor] withBlock:^id {
100+
return [BFTask taskWithResult:@([provider restoreAuthenticationWithAuthData:authData])];
101+
}];
107102
}
108103

109104
///--------------------------------------
@@ -119,8 +114,8 @@ - (BFTask *)logInUserAsyncWithAuthType:(NSString *)authType authData:(NSDictiona
119114
PFUser *user = currentUser;
120115
BFTask *resolveLaziness = nil;
121116
NSDictionary *oldAnonymousData = nil;
122-
@synchronized (user.lock) {
123-
oldAnonymousData = user.authData[[PFAnonymousAuthenticationProvider authType]];
117+
@synchronized(user.lock) {
118+
oldAnonymousData = user.authData[PFUserAnonymousAuthenticationType];
124119

125120
// Replace any anonymity with the new linked authData
126121
[user stripAnonymity];
@@ -163,7 +158,6 @@ - (BFTask *)logInUserAsyncWithAuthType:(NSString *)authType authData:(NSDictiona
163158
return [[PFUser userController] logInCurrentUserAsyncWithAuthType:authType
164159
authData:authData
165160
revocableSession:[PFUser _isRevocableSessionEnabled]];
166-
167161
}
168162

169163
@end

Parse/Internal/User/AuthenticationProviders/Providers/Anonymous/PFAnonymousAuthenticationProvider.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
#import <Foundation/Foundation.h>
1111

12-
#import "PFAuthenticationProvider.h"
12+
#import <Parse/PFUserAuthenticationDelegate.h>
1313

1414
NS_ASSUME_NONNULL_BEGIN
1515

16-
@interface PFAnonymousAuthenticationProvider : NSObject <PFAuthenticationProvider>
16+
extern NSString *const PFUserAnonymousAuthenticationType;
17+
18+
@interface PFAnonymousAuthenticationProvider : NSObject <PFUserAuthenticationDelegate>
1719

1820
/*!
1921
Gets auth data with a fresh UUID.

Parse/Internal/User/AuthenticationProviders/Providers/Anonymous/PFAnonymousAuthenticationProvider.m

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,16 @@
1111

1212
#import <Bolts/BFTask.h>
1313

14+
NSString *const PFUserAnonymousAuthenticationType = @"anonymous";
15+
1416
@implementation PFAnonymousAuthenticationProvider
1517

1618
///--------------------------------------
17-
#pragma mark - PFAuthenticationProvider
19+
#pragma mark - PFAnonymousAuthenticationProvider
1820
///--------------------------------------
1921

20-
+ (NSString *)authType {
21-
return @"anonymous";
22-
}
23-
24-
- (BFTask *)deauthenticateInBackground {
25-
return [BFTask taskWithResult:nil];
26-
}
27-
28-
- (BFTask *)restoreAuthenticationInBackgroundWithAuthData:(NSDictionary *)authData {
29-
return [BFTask taskWithResult:nil];
22+
- (BOOL)restoreAuthenticationWithAuthData:(NSDictionary *)authData {
23+
return YES;
3024
}
3125

3226
///--------------------------------------

Parse/Internal/User/PFUserPrivate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ extern NSString *const PFUserCurrentUserKeychainItemName;
7272
/// @name Third-party Authentication (Private)
7373
///--------------------------------------
7474

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

7777
@end

Parse/PFAnonymousUtils.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ @implementation PFAnonymousUtils
2323

2424
+ (BFTask *)logInInBackground {
2525
PFAnonymousAuthenticationProvider *provider = [self _authenticationProvider];
26-
NSString *authType = [[provider class] authType];
27-
return [PFUser logInWithAuthTypeInBackground:authType authData:provider.authData];
26+
return [PFUser logInWithAuthTypeInBackground:PFUserAnonymousAuthenticationType authData:provider.authData];
2827
}
2928

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

4443
+ (BOOL)isLinkedWithUser:(PFUser *)user {
45-
return [user isLinkedWithAuthType:[[[self _authenticationProvider] class] authType]];
44+
return [user isLinkedWithAuthType:PFUserAnonymousAuthenticationType];
4645
}
4746

4847
///--------------------------------------
@@ -66,15 +65,15 @@ + (PFAnonymousAuthenticationProvider *)_authenticationProvider {
6665
provider = authenticationProvider_;
6766
if (!provider) {
6867
provider = [[PFAnonymousAuthenticationProvider alloc] init];
69-
[PFUser registerAuthenticationProvider:provider];
68+
[PFUser registerAuthenticationDelegate:provider forAuthType:PFUserAnonymousAuthenticationType];
7069
authenticationProvider_ = provider;
7170
}
7271
});
7372
return provider;
7473
}
7574

7675
+ (void)_clearAuthenticationProvider {
77-
[PFUser _unregisterAuthenticationProvider:authenticationProvider_];
76+
[PFUser _unregisterAuthenticationDelegateForAuthType:PFUserAnonymousAuthenticationType];
7877
dispatch_sync([self _providerAccessQueue], ^{
7978
authenticationProvider_ = nil;
8079
});
@@ -86,7 +85,7 @@ + (void)_clearAuthenticationProvider {
8685

8786
+ (PFUser *)_lazyLogIn {
8887
PFAnonymousAuthenticationProvider *provider = [self _authenticationProvider];
89-
return [PFUser logInLazyUserWithAuthType:[[provider class] authType] authData:provider.authData];
88+
return [PFUser logInLazyUserWithAuthType:PFUserAnonymousAuthenticationType authData:provider.authData];
9089
}
9190

9291
@end

Parse/PFAuthenticationProvider.h

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)