Skip to content

Commit d8ed91b

Browse files
committed
Merge pull request #260 from ParsePlatform/nlutsenko.cleanup
Cleanup PFUser third party authentication.
2 parents 5c5c887 + f0c0c90 commit d8ed91b

File tree

7 files changed

+36
-38
lines changed

7 files changed

+36
-38
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ NS_ASSUME_NONNULL_BEGIN
3333
///--------------------------------------
3434

3535
- (BFTask PF_GENERIC(NSNumber *) *)restoreAuthenticationAsyncWithAuthData:(nullable NSDictionary *)authData
36-
forProviderWithAuthType:(NSString *)authType;
37-
- (BFTask PF_GENERIC(NSNumber *) *)deauthenticateAsyncWithProviderForAuthType:(NSString *)authType;
36+
forAuthType:(NSString *)authType;
37+
- (BFTask PF_GENERIC(NSNumber *) *)deauthenticateAsyncWithAuthType:(NSString *)authType;
3838

3939
///--------------------------------------
4040
/// @name Log In

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
@interface PFUserAuthenticationController () {
2222
dispatch_queue_t _dataAccessQueue;
23-
NSMutableDictionary *_authenticationProviders;
23+
NSMutableDictionary PF_GENERIC(NSString *, id<PFUserAuthenticationDelegate>) *_authenticationDelegates;
2424
}
2525

2626
@end
@@ -36,7 +36,7 @@ - (instancetype)init {
3636
if (!self) return nil;
3737

3838
_dataAccessQueue = dispatch_queue_create("com.parse.user.authenticationManager", DISPATCH_QUEUE_SERIAL);
39-
_authenticationProviders = [NSMutableDictionary dictionary];
39+
_authenticationDelegates = [NSMutableDictionary dictionary];
4040

4141
return self;
4242
}
@@ -47,16 +47,16 @@ - (instancetype)init {
4747

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

5454
dispatch_sync(_dataAccessQueue, ^{
55-
_authenticationProviders[authType] = delegate;
55+
_authenticationDelegates[authType] = delegate;
5656
});
5757

5858
// TODO: (nlutsenko) Decouple this further.
59-
if (![authType isEqualToString:@"anonymous"]) {
59+
if (![authType isEqualToString:PFAnonymousUserAuthenticationType]) {
6060
[[PFUser currentUser] synchronizeAuthDataWithAuthType:authType];
6161
}
6262
}
@@ -66,7 +66,7 @@ - (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType {
6666
return;
6767
}
6868
dispatch_sync(_dataAccessQueue, ^{
69-
[_authenticationProviders removeObjectForKey:authType];
69+
[_authenticationDelegates removeObjectForKey:authType];
7070
});
7171
}
7272

@@ -75,23 +75,19 @@ - (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType {
7575
return nil;
7676
}
7777

78-
__block id<PFUserAuthenticationDelegate> provider = nil;
78+
__block id<PFUserAuthenticationDelegate> delegate = nil;
7979
dispatch_sync(_dataAccessQueue, ^{
80-
provider = _authenticationProviders[authType];
80+
delegate = _authenticationDelegates[authType];
8181
});
82-
return provider;
82+
return delegate;
8383
}
8484

8585
///--------------------------------------
8686
#pragma mark - Authentication
8787
///--------------------------------------
8888

89-
- (BFTask PF_GENERIC(NSNumber *)*)deauthenticateAsyncWithProviderForAuthType:(NSString *)authType {
90-
return [self restoreAuthenticationAsyncWithAuthData:nil forProviderWithAuthType:authType];
91-
}
92-
9389
- (BFTask PF_GENERIC(NSNumber *)*)restoreAuthenticationAsyncWithAuthData:(nullable NSDictionary *)authData
94-
forProviderWithAuthType:(NSString *)authType {
90+
forAuthType:(NSString *)authType {
9591
id<PFUserAuthenticationDelegate> provider = [self authenticationDelegateForAuthType:authType];
9692
if (!provider) {
9793
return [BFTask taskWithResult:@YES];
@@ -101,6 +97,10 @@ - (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType {
10197
}];
10298
}
10399

100+
- (BFTask PF_GENERIC(NSNumber *)*)deauthenticateAsyncWithAuthType:(NSString *)authType {
101+
return [self restoreAuthenticationAsyncWithAuthData:nil forAuthType:authType];
102+
}
103+
104104
///--------------------------------------
105105
#pragma mark - Log In
106106
///--------------------------------------
@@ -115,7 +115,7 @@ - (BFTask *)logInUserAsyncWithAuthType:(NSString *)authType authData:(NSDictiona
115115
BFTask *resolveLaziness = nil;
116116
NSDictionary *oldAnonymousData = nil;
117117
@synchronized(user.lock) {
118-
oldAnonymousData = user.authData[PFUserAnonymousAuthenticationType];
118+
oldAnonymousData = user.authData[PFAnonymousUserAuthenticationType];
119119

120120
// Replace any anonymity with the new linked authData
121121
[user stripAnonymity];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
NS_ASSUME_NONNULL_BEGIN
1515

16-
extern NSString *const PFUserAnonymousAuthenticationType;
16+
extern NSString *const PFAnonymousUserAuthenticationType;
1717

1818
@interface PFAnonymousAuthenticationProvider : NSObject <PFUserAuthenticationDelegate>
1919

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#import <Bolts/BFTask.h>
1313

14-
NSString *const PFUserAnonymousAuthenticationType = @"anonymous";
14+
NSString *const PFAnonymousUserAuthenticationType = @"anonymous";
1515

1616
@implementation PFAnonymousAuthenticationProvider
1717

Parse/PFAnonymousUtils.m

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

2424
+ (BFTask *)logInInBackground {
2525
PFAnonymousAuthenticationProvider *provider = [self _authenticationProvider];
26-
return [PFUser logInWithAuthTypeInBackground:PFUserAnonymousAuthenticationType authData:provider.authData];
26+
return [PFUser logInWithAuthTypeInBackground:PFAnonymousUserAuthenticationType authData:provider.authData];
2727
}
2828

2929
+ (void)logInWithBlock:(PFUserResultBlock)block {
@@ -41,7 +41,7 @@ + (void)logInWithTarget:(id)target selector:(SEL)selector {
4141
///--------------------------------------
4242

4343
+ (BOOL)isLinkedWithUser:(PFUser *)user {
44-
return [user isLinkedWithAuthType:PFUserAnonymousAuthenticationType];
44+
return [user isLinkedWithAuthType:PFAnonymousUserAuthenticationType];
4545
}
4646

4747
///--------------------------------------
@@ -65,15 +65,15 @@ + (PFAnonymousAuthenticationProvider *)_authenticationProvider {
6565
provider = authenticationProvider_;
6666
if (!provider) {
6767
provider = [[PFAnonymousAuthenticationProvider alloc] init];
68-
[PFUser registerAuthenticationDelegate:provider forAuthType:PFUserAnonymousAuthenticationType];
68+
[PFUser registerAuthenticationDelegate:provider forAuthType:PFAnonymousUserAuthenticationType];
6969
authenticationProvider_ = provider;
7070
}
7171
});
7272
return provider;
7373
}
7474

7575
+ (void)_clearAuthenticationProvider {
76-
[PFUser _unregisterAuthenticationDelegateForAuthType:PFUserAnonymousAuthenticationType];
76+
[PFUser _unregisterAuthenticationDelegateForAuthType:PFAnonymousUserAuthenticationType];
7777
dispatch_sync([self _providerAccessQueue], ^{
7878
authenticationProvider_ = nil;
7979
});
@@ -85,7 +85,7 @@ + (void)_clearAuthenticationProvider {
8585

8686
+ (PFUser *)_lazyLogIn {
8787
PFAnonymousAuthenticationProvider *provider = [self _authenticationProvider];
88-
return [PFUser logInLazyUserWithAuthType:PFUserAnonymousAuthenticationType authData:provider.authData];
88+
return [PFUser logInLazyUserWithAuthType:PFAnonymousUserAuthenticationType authData:provider.authData];
8989
}
9090

9191
@end

Parse/PFUser.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ - (void)cleanUpAuthData {
269269
[self.linkedServiceNames removeObject:key];
270270

271271
[[[[self class] authenticationController] restoreAuthenticationAsyncWithAuthData:nil
272-
forProviderWithAuthType:key] waitForResult:nil withMainThreadWarning:NO];
272+
forAuthType:key] waitForResult:nil withMainThreadWarning:NO];
273273
}
274274
}
275275
}
@@ -366,7 +366,7 @@ - (void)synchronizeAuthDataWithAuthType:(NSString *)authType {
366366

367367
NSDictionary *data = self.authData[authType];
368368
BFTask *restoreTask = [[[self class] authenticationController] restoreAuthenticationAsyncWithAuthData:data
369-
forProviderWithAuthType:authType];
369+
forAuthType:authType];
370370
[restoreTask waitForResult:nil withMainThreadWarning:NO];
371371
if (restoreTask.faulted || ![restoreTask.result boolValue]) { // TODO: (nlutsenko) Maybe chain this method?
372372
[self unlinkWithAuthTypeInBackground:authType];
@@ -432,7 +432,7 @@ - (BFTask *)resolveLazinessAsync:(BFTask *)toAwait {
432432
}
433433

434434
- (BFTask *)_logOutAsyncWithAuthType:(NSString *)authType {
435-
return [[[self class] authenticationController] deauthenticateAsyncWithProviderForAuthType:authType];
435+
return [[[self class] authenticationController] deauthenticateAsyncWithAuthType:authType];
436436
}
437437

438438
+ (instancetype)logInLazyUserWithAuthType:(NSString *)authType authData:(NSDictionary *)authData {
@@ -454,7 +454,7 @@ - (BFTask *)signUpAsync:(BFTask *)toAwait {
454454
// For anonymous users, there may be an objectId. Setting the userName
455455
// will have removed the anonymous link and set the value in the authData
456456
// object to [NSNull null], so we can just treat it like a save operation.
457-
if (self.authData[PFUserAnonymousAuthenticationType] == [NSNull null]) {
457+
if (self.authData[PFAnonymousUserAuthenticationType] == [NSNull null]) {
458458
return [self saveAsync:toAwait];
459459
}
460460

@@ -483,7 +483,7 @@ - (BFTask *)signUpAsync:(BFTask *)toAwait {
483483
@synchronized ([currentUser lock]) {
484484
NSString *oldUsername = [currentUser.username copy];
485485
NSString *oldPassword = [currentUser.password copy];
486-
NSArray *oldAnonymousData = currentUser.authData[PFUserAnonymousAuthenticationType];
486+
NSArray *oldAnonymousData = currentUser.authData[PFAnonymousUserAuthenticationType];
487487

488488
[currentUser checkForChangesToMutableContainers];
489489

@@ -553,7 +553,7 @@ - (BFTask *)signUpAsync:(BFTask *)toAwait {
553553
- (void)stripAnonymity {
554554
@synchronized ([self lock]) {
555555
if ([PFAnonymousUtils isLinkedWithUser:self]) {
556-
NSString *authType = PFUserAnonymousAuthenticationType;
556+
NSString *authType = PFAnonymousUserAuthenticationType;
557557

558558
[self.linkedServiceNames removeObject:authType];
559559

@@ -570,7 +570,7 @@ - (void)stripAnonymity {
570570
- (void)restoreAnonymity:(id)anonymousData {
571571
@synchronized ([self lock]) {
572572
if (anonymousData && anonymousData != [NSNull null]) {
573-
NSString *authType = PFUserAnonymousAuthenticationType;
573+
NSString *authType = PFAnonymousUserAuthenticationType;
574574
[self.linkedServiceNames addObject:authType];
575575
self.authData[authType] = anonymousData;
576576
}
@@ -852,7 +852,7 @@ - (BFTask *)linkWithAuthTypeInBackground:(NSString *)authType authData:(NSDictio
852852
self.authData[authType] = newAuthData;
853853
[self.linkedServiceNames addObject:authType];
854854

855-
oldAnonymousData = self.authData[PFUserAnonymousAuthenticationType];
855+
oldAnonymousData = self.authData[PFAnonymousUserAuthenticationType];
856856
[self stripAnonymity];
857857

858858
dirty = YES;
@@ -1177,7 +1177,7 @@ - (void)signUpInBackgroundWithBlock:(PFBooleanResultBlock)block {
11771177
// For anonymous users, there may be an objectId. Setting the userName
11781178
// will have removed the anonymous link and set the value in the authData
11791179
// object to [NSNull null], so we can just treat it like a save operation.
1180-
if (authData[PFUserAnonymousAuthenticationType] == [NSNull null]) {
1180+
if (authData[PFAnonymousUserAuthenticationType] == [NSNull null]) {
11811181
[self saveInBackgroundWithBlock:block];
11821182
return;
11831183
}
@@ -1207,7 +1207,7 @@ + (PFObjectState *)_newObjectStateWithParseClassName:(NSString *)className
12071207
- (BFTask *)_validateSaveEventuallyAsync {
12081208
if ([self isDirtyForKey:PFUserPasswordRESTKey]) {
12091209
NSError *error = [PFErrorUtilities errorWithCode:kPFErrorOperationForbidden
1210-
message:@"Unable to saveEventually a PFUser with dirty password."];
1210+
message:@"Unable to saveEventually a PFUser with dirty password."];
12111211
return [BFTask taskWithError:error];
12121212
}
12131213
return [BFTask taskWithResult:nil];

Parse/PFUserAuthenticationDelegate.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
#import <Foundation/Foundation.h>
1111

12-
#import <Bolts/BFTask.h>
13-
1412
#import <Parse/PFConstants.h>
1513

1614
PF_ASSUME_NONNULL_BEGIN
@@ -31,7 +29,7 @@ PF_ASSUME_NONNULL_BEGIN
3129
@returns `YES` - if the `authData` was succesfully synchronized,
3230
or `NO` if user should not longer be associated because of bad `authData`.
3331
*/
34-
- (BOOL)restoreAuthenticationWithAuthData:(PF_NULLABLE NSDictionary PF_GENERIC(NSString *,NSString *) *)authData;
32+
- (BOOL)restoreAuthenticationWithAuthData:(PF_NULLABLE NSDictionary PF_GENERIC(NSString *, NSString *) *)authData;
3533

3634
@end
3735

0 commit comments

Comments
 (0)