From 050145b769c4348db9e69753b9137805f1c41b9e Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Wed, 11 Aug 2021 14:42:49 -0300 Subject: [PATCH 1/9] Drops unneeded logout check --- Simperium/Simperium.m | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Simperium/Simperium.m b/Simperium/Simperium.m index 372e5c05..e0918229 100644 --- a/Simperium/Simperium.m +++ b/Simperium/Simperium.m @@ -587,12 +587,7 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende #pragma mark ==================================================================================== - (void)signOutAndRemoveLocalData:(BOOL)remove completion:(SimperiumSignoutCompletion)completion { - - // Don't proceed, if the user isn't logged in - if (!self.user.authenticated) { - return; - } - + if (self.logoutInProgress) { SPLogError(@"Error: Simperium is already logging out"); return; From 82109fbb40c7ce131c28885dbd7a0dac5953785c Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Sat, 14 Aug 2021 01:24:19 -0300 Subject: [PATCH 2/9] Restores Authenticated check on Logout --- Simperium/Simperium.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Simperium/Simperium.m b/Simperium/Simperium.m index e0918229..f4a7a77a 100644 --- a/Simperium/Simperium.m +++ b/Simperium/Simperium.m @@ -587,7 +587,12 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende #pragma mark ==================================================================================== - (void)signOutAndRemoveLocalData:(BOOL)remove completion:(SimperiumSignoutCompletion)completion { - + + // Don't proceed, if the user isn't logged in + if (!self.user.authenticated) { + return; + } + if (self.logoutInProgress) { SPLogError(@"Error: Simperium is already logging out"); return; From 79204f3087dd24fde24e1b6aee011b5120a0e6d7 Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Sat, 14 Aug 2021 01:25:00 -0300 Subject: [PATCH 3/9] Extracts resetAuthToken --- Simperium/Simperium.m | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Simperium/Simperium.m b/Simperium/Simperium.m index f4a7a77a..0ae50e80 100644 --- a/Simperium/Simperium.m +++ b/Simperium/Simperium.m @@ -604,9 +604,8 @@ - (void)signOutAndRemoveLocalData:(BOOL)remove completion:(SimperiumSignoutCompl [self stopNetworkManagers]; // Clear the token and user - [self.authenticator reset]; - self.user = nil; - + [self resetAuthToken]; + // Reset the network manager and processors; any enqueued tasks will get skipped self.logoutInProgress = YES; @@ -813,8 +812,7 @@ - (void)authenticationDidCreateAccount - (void)authenticationDidCancel { [self stopNetworkManagers]; - [self.authenticator reset]; - self.user.authToken = nil; + [self resetAuthToken]; [self closeAuthViewControllerAnimated:YES]; if ([self.delegate respondsToSelector:@selector(simperiumDidCancelLogin:)]) { @@ -840,6 +838,11 @@ - (void)authenticationDidFail { [self scheduleOpenAuthViewController]; } +- (void)resetAuthToken { + [self.authenticator reset]; + self.user = nil; +} + - (BOOL)authenticateIfNecessary { if (!self.networkEnabled || !self.authenticationEnabled || !self.appID) { return NO; From 966f2fd9bb3889ff2cc6d9d7edc6cd436d94bc3a Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Sat, 14 Aug 2021 01:25:19 -0300 Subject: [PATCH 4/9] Renames SPAuthenticationDidFail > SPAuthenticationTokenInvalid --- Simperium/SPNetworkInterface.h | 2 +- Simperium/SPNetworkInterface.m | 2 +- Simperium/SPWebSocketChannel.m | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Simperium/SPNetworkInterface.h b/Simperium/SPNetworkInterface.h index 401d68a6..68f268f2 100644 --- a/Simperium/SPNetworkInterface.h +++ b/Simperium/SPNetworkInterface.h @@ -36,4 +36,4 @@ typedef void (^SPNetworkInterfaceResetCompletion)(void); @end -extern NSString * const SPAuthenticationDidFail; +extern NSString * const SPAuthenticationTokenInvalid; diff --git a/Simperium/SPNetworkInterface.m b/Simperium/SPNetworkInterface.m index 4372aea9..d82f0362 100644 --- a/Simperium/SPNetworkInterface.m +++ b/Simperium/SPNetworkInterface.m @@ -1,3 +1,3 @@ #import "SPNetworkInterface.h" -NSString * const SPAuthenticationDidFail = @"SPAuthenticationDidFail"; +NSString * const SPAuthenticationTokenInvalid = @"SPAuthenticationTokenInvalid"; diff --git a/Simperium/SPWebSocketChannel.m b/Simperium/SPWebSocketChannel.m index b268d661..37a51046 100644 --- a/Simperium/SPWebSocketChannel.m +++ b/Simperium/SPWebSocketChannel.m @@ -280,7 +280,7 @@ - (void)handleAuthResponse:(NSString *)responseString bucket:(SPBucket *)bucket if ([authPayload isKindOfClass:[NSDictionary class]]) { NSInteger errorCode = [authPayload[SPWebsocketErrorCodeKey] integerValue]; if (errorCode == SPWebsocketAuthErrorTokenMalformed || errorCode == SPWebsocketAuthErrorTokenInvalid) { - [[NSNotificationCenter defaultCenter] postNotificationName:SPAuthenticationDidFail object:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:SPAuthenticationTokenInvalid object:self]; } } return; From 0cbc9259ec52c0560ca772ade6d84e2277287ba2 Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Sat, 14 Aug 2021 01:25:29 -0300 Subject: [PATCH 5/9] New TokenInvalid Handler --- Simperium/Simperium.m | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Simperium/Simperium.m b/Simperium/Simperium.m index 0ae50e80..b8ab252e 100644 --- a/Simperium/Simperium.m +++ b/Simperium/Simperium.m @@ -129,8 +129,8 @@ - (void)setupNotifications { #endif NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - [nc addObserver:self selector:@selector(authenticationDidFail) name:SPAuthenticationDidFail object:nil]; - [nc addObserver:self selector:@selector(handleNetworkChange:) name:kSPReachabilityChangedNotification object:nil]; + [nc addObserver:self selector:@selector(handleTokenInvalid:) name:SPAuthenticationTokenInvalid object:nil]; + [nc addObserver:self selector:@selector(handleNetworkChange:) name:kSPReachabilityChangedNotification object:nil]; } - (void)setupCoreDataWithModel:(NSManagedObjectModel *)model @@ -242,6 +242,14 @@ - (void)handleNetworkChange:(NSNotification *)notification { } } +- (void)handleTokenInvalid:(NSNotification *)notification { + // Clear the token and user + [self resetAuthToken]; + + // Notify Delegate / Trigger reauth flow + [self authenticationDidFail]; +} + - (void)setNetworkEnabled:(BOOL)enabled { if (self.networkEnabled == enabled) { return; From 3a1486bfea3e47146d39fce8971e80d83fd4292f Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Mon, 16 Aug 2021 10:52:08 -0300 Subject: [PATCH 6/9] Revert "New TokenInvalid Handler" This reverts commit 0cbc9259ec52c0560ca772ade6d84e2277287ba2. --- Simperium/Simperium.m | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Simperium/Simperium.m b/Simperium/Simperium.m index b8ab252e..0ae50e80 100644 --- a/Simperium/Simperium.m +++ b/Simperium/Simperium.m @@ -129,8 +129,8 @@ - (void)setupNotifications { #endif NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - [nc addObserver:self selector:@selector(handleTokenInvalid:) name:SPAuthenticationTokenInvalid object:nil]; - [nc addObserver:self selector:@selector(handleNetworkChange:) name:kSPReachabilityChangedNotification object:nil]; + [nc addObserver:self selector:@selector(authenticationDidFail) name:SPAuthenticationDidFail object:nil]; + [nc addObserver:self selector:@selector(handleNetworkChange:) name:kSPReachabilityChangedNotification object:nil]; } - (void)setupCoreDataWithModel:(NSManagedObjectModel *)model @@ -242,14 +242,6 @@ - (void)handleNetworkChange:(NSNotification *)notification { } } -- (void)handleTokenInvalid:(NSNotification *)notification { - // Clear the token and user - [self resetAuthToken]; - - // Notify Delegate / Trigger reauth flow - [self authenticationDidFail]; -} - - (void)setNetworkEnabled:(BOOL)enabled { if (self.networkEnabled == enabled) { return; From bf1bd0cd8591238db204abc35f54830beb226e44 Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Mon, 16 Aug 2021 10:52:11 -0300 Subject: [PATCH 7/9] Revert "Renames SPAuthenticationDidFail > SPAuthenticationTokenInvalid" This reverts commit 966f2fd9bb3889ff2cc6d9d7edc6cd436d94bc3a. --- Simperium/SPNetworkInterface.h | 2 +- Simperium/SPNetworkInterface.m | 2 +- Simperium/SPWebSocketChannel.m | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Simperium/SPNetworkInterface.h b/Simperium/SPNetworkInterface.h index 68f268f2..401d68a6 100644 --- a/Simperium/SPNetworkInterface.h +++ b/Simperium/SPNetworkInterface.h @@ -36,4 +36,4 @@ typedef void (^SPNetworkInterfaceResetCompletion)(void); @end -extern NSString * const SPAuthenticationTokenInvalid; +extern NSString * const SPAuthenticationDidFail; diff --git a/Simperium/SPNetworkInterface.m b/Simperium/SPNetworkInterface.m index d82f0362..4372aea9 100644 --- a/Simperium/SPNetworkInterface.m +++ b/Simperium/SPNetworkInterface.m @@ -1,3 +1,3 @@ #import "SPNetworkInterface.h" -NSString * const SPAuthenticationTokenInvalid = @"SPAuthenticationTokenInvalid"; +NSString * const SPAuthenticationDidFail = @"SPAuthenticationDidFail"; diff --git a/Simperium/SPWebSocketChannel.m b/Simperium/SPWebSocketChannel.m index 37a51046..b268d661 100644 --- a/Simperium/SPWebSocketChannel.m +++ b/Simperium/SPWebSocketChannel.m @@ -280,7 +280,7 @@ - (void)handleAuthResponse:(NSString *)responseString bucket:(SPBucket *)bucket if ([authPayload isKindOfClass:[NSDictionary class]]) { NSInteger errorCode = [authPayload[SPWebsocketErrorCodeKey] integerValue]; if (errorCode == SPWebsocketAuthErrorTokenMalformed || errorCode == SPWebsocketAuthErrorTokenInvalid) { - [[NSNotificationCenter defaultCenter] postNotificationName:SPAuthenticationTokenInvalid object:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:SPAuthenticationDidFail object:self]; } } return; From fbc72a3eb1c717b7fb12b1438a22b50becc21add Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Mon, 16 Aug 2021 10:52:14 -0300 Subject: [PATCH 8/9] Revert "Extracts resetAuthToken" This reverts commit 79204f3087dd24fde24e1b6aee011b5120a0e6d7. --- Simperium/Simperium.m | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Simperium/Simperium.m b/Simperium/Simperium.m index 0ae50e80..f4a7a77a 100644 --- a/Simperium/Simperium.m +++ b/Simperium/Simperium.m @@ -604,8 +604,9 @@ - (void)signOutAndRemoveLocalData:(BOOL)remove completion:(SimperiumSignoutCompl [self stopNetworkManagers]; // Clear the token and user - [self resetAuthToken]; - + [self.authenticator reset]; + self.user = nil; + // Reset the network manager and processors; any enqueued tasks will get skipped self.logoutInProgress = YES; @@ -812,7 +813,8 @@ - (void)authenticationDidCreateAccount - (void)authenticationDidCancel { [self stopNetworkManagers]; - [self resetAuthToken]; + [self.authenticator reset]; + self.user.authToken = nil; [self closeAuthViewControllerAnimated:YES]; if ([self.delegate respondsToSelector:@selector(simperiumDidCancelLogin:)]) { @@ -838,11 +840,6 @@ - (void)authenticationDidFail { [self scheduleOpenAuthViewController]; } -- (void)resetAuthToken { - [self.authenticator reset]; - self.user = nil; -} - - (BOOL)authenticateIfNecessary { if (!self.networkEnabled || !self.authenticationEnabled || !self.appID) { return NO; From f3a6b32714e32c68eae0dd915217eb4c20a23158 Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Mon, 16 Aug 2021 10:52:18 -0300 Subject: [PATCH 9/9] Revert "Restores Authenticated check on Logout" This reverts commit 82109fbb40c7ce131c28885dbd7a0dac5953785c. --- Simperium/Simperium.m | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Simperium/Simperium.m b/Simperium/Simperium.m index f4a7a77a..e0918229 100644 --- a/Simperium/Simperium.m +++ b/Simperium/Simperium.m @@ -587,12 +587,7 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende #pragma mark ==================================================================================== - (void)signOutAndRemoveLocalData:(BOOL)remove completion:(SimperiumSignoutCompletion)completion { - - // Don't proceed, if the user isn't logged in - if (!self.user.authenticated) { - return; - } - + if (self.logoutInProgress) { SPLogError(@"Error: Simperium is already logging out"); return;