From 548afecb8e3a3fd218eca60167a3cf9390dfccf8 Mon Sep 17 00:00:00 2001 From: Nitesh Meshram Date: Fri, 27 May 2016 12:51:28 +0530 Subject: [PATCH 1/4] Added method to accomplish registration functionality --- client-library/sync/PFClient.h | 3 ++ client-library/sync/PFClient.m | 63 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/client-library/sync/PFClient.h b/client-library/sync/PFClient.h index 7e568ec..5a89f82 100644 --- a/client-library/sync/PFClient.h +++ b/client-library/sync/PFClient.h @@ -70,4 +70,7 @@ + (void) logout; + (void) save; ++ (bool) registerWithAuthenticationProvider:(NSString *)authProvider credential:(NSString *)credential callbackTarget:(id)target method:(SEL)selector; ++ (AuthenticationRequest *)newRegisterRequestWithAuthenticationProvider:(NSString *)authProvider Credential:(NSString *)credential; + @end diff --git a/client-library/sync/PFClient.m b/client-library/sync/PFClient.m index 96e11a5..5eeaece 100644 --- a/client-library/sync/PFClient.m +++ b/client-library/sync/PFClient.m @@ -563,4 +563,67 @@ - (void)setReachableBlock:(NetworkReachable)reachableBlock{ - (void)setUnReachableBlock:(NetworkUnreachable)unReachableBlock{ self.reach.unreachableBlock = unReachableBlock; } + +#pragma mark - Registration Methods +/** Nitesh + * Service method to allow the client application to user Registration request using a + * custom authentication provider + */ ++ (bool) registerWithAuthenticationProvider:(NSString *)authProvider credential:(NSString *)credential callbackTarget:(id)target method:(SEL)selector { + [PFClient sharedInstance].authDelegate = target; + [[PFClient sharedInstance] startLoginTimeoutTimer]; + + AuthenticationRequest *req; + req = [self newRegisterRequestWithAuthenticationProvider:authProvider Credential:credential]; + + PFInvocation* callback = [[PFInvocation alloc] initWithTarget:[PFClient sharedInstance] method:@selector(receivedRegisterUsernamePasswordResponse:)]; + + [[PFSocketManager sharedInstance] sendEvent:@"register" data:req callback:callback]; + + return true; +} + + +/** + * Service method to make it easier for the client application to issue a registration request + */ ++ (AuthenticationRequest *)newRegisterRequestWithAuthenticationProvider:(NSString *)authProvider Credential:(NSString *)credential { + AuthenticationRequest* req = [[AuthenticationRequest alloc] init]; + req.authProvider = authProvider; + req.deviceId = [[NSUUID UUID] UUIDString]; + req.credential = credential; + return req; +} + +/** + * Callback method for when the registration response is recieved + */ +- (void) receivedRegisterUsernamePasswordResponse:(id) result{ + NSLog(@"PFClient Got auth response"); + + if ([result isMemberOfClass:[AuthenticationResponse class]]) { + AuthenticationResponse* response = (AuthenticationResponse*) result; + UserToken* userToken = response.result; + clientId = response.clientId; + self.userId = userToken.user.ID; + self.token = userToken.token; + + if (self.token.length > 0 && self.userId.length > 0 && [[(AuthenticationResponse *)result statusCode] integerValue] == 200) { + [PFClient save]; + return; + } + else { + NSString *errorMessage = [(AuthenticationResponse *)result message]; + [loginTimeOutTimer invalidate]; + NSError *error = [NSError errorWithDomain:@"com.activestack.error" code:0 userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: %@",errorMessage]}]; + [self.authDelegate authenticationDidFailWithError:error]; + return; + } + } + + [loginTimeOutTimer invalidate]; + NSError *error = [NSError errorWithDomain:@"com.activestack.error" code:0 userInfo:@{NSLocalizedDescriptionKey: @"Server did not return a token."}]; + [self.authDelegate authenticationDidFailWithError:error]; +} + @end From e1808b28fc4adb794b8fa357128640577d9ce823 Mon Sep 17 00:00:00 2001 From: Nitesh Meshram Date: Fri, 27 May 2016 16:36:24 +0530 Subject: [PATCH 2/4] Modified podspec --- ActiveStack.podspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ActiveStack.podspec b/ActiveStack.podspec index 17b8307..0eb1274 100644 --- a/ActiveStack.podspec +++ b/ActiveStack.podspec @@ -2,10 +2,10 @@ Pod::Spec.new do |s| s.name = "ActiveStack" s.version = "0.2.3" s.summary = "Active Mobile Service Layer for ActiveStack iOS Clients." - s.homepage = "https://github.com/ActiveStack/active-client-sdk-objc" + s.homepage = "https://github.com/v2Nitesh/active-client-sdk-objc.git" s.license = 'MIT' - s.author = { "Brad Anderson Smith" => "brad@theappguy.guru" } - s.source = { :git => "https://github.com/ActiveStack/active-client-sdk-objc.git", :tag => s.version.to_s } + s.author = { “Nitesh Meshram“ => “nitesh.meshram@v2solutions.com” } + s.source = { :git => "https://github.com/v2Nitesh/active-client-sdk-objc.git", :tag => s.version.to_s } s.platform = :ios, '7.0' s.requires_arc = true s.prefix_header_file = 'client-library/ActiveStack-Prefix.pch' From 2a0eea39e5bb168a5521ea7fe3cb0e5946b2e561 Mon Sep 17 00:00:00 2001 From: Nitesh Meshram Date: Tue, 31 May 2016 15:16:40 +0530 Subject: [PATCH 3/4] Modified Podspec --- ActiveStack.podspec | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ActiveStack.podspec b/ActiveStack.podspec index 0eb1274..1028cc5 100644 --- a/ActiveStack.podspec +++ b/ActiveStack.podspec @@ -4,17 +4,19 @@ Pod::Spec.new do |s| s.summary = "Active Mobile Service Layer for ActiveStack iOS Clients." s.homepage = "https://github.com/v2Nitesh/active-client-sdk-objc.git" s.license = 'MIT' - s.author = { “Nitesh Meshram“ => “nitesh.meshram@v2solutions.com” } + s.author = { "Nitesh Meshram" => "nitesh.meshram@v2solutions.com" } s.source = { :git => "https://github.com/v2Nitesh/active-client-sdk-objc.git", :tag => s.version.to_s } s.platform = :ios, '7.0' s.requires_arc = true s.prefix_header_file = 'client-library/ActiveStack-Prefix.pch' s.source_files = 'client-library/**/*' - s.dependency 'gtm-oauth2' + s.dependency 'Reachability' s.dependency 'socket.IO', '0.2.2' - + s.dependency 'gtm-oauth2' + s.description = <<-DESC - DESC +TODO: ActiveStack Private pod version 0.2.3. + DESC end From a8044e2168297bcf39d272122c260e71b6a8ebe2 Mon Sep 17 00:00:00 2001 From: Nitesh Meshram Date: Wed, 8 Jun 2016 18:27:43 +0530 Subject: [PATCH 4/4] 1. Added Registration logic PFClient & PFAuthManager ActiveStack iOS SDK 2. Tested the with local server both the Registration. --- client-library/PFAuthManager.h | 4 ++++ client-library/PFAuthManager.m | 7 +++++++ client-library/sync/PFClient.h | 1 + client-library/sync/PFClient.m | 30 ++++++++++++++++++------------ 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/client-library/PFAuthManager.h b/client-library/PFAuthManager.h index 6c43617..2eaea46 100644 --- a/client-library/PFAuthManager.h +++ b/client-library/PFAuthManager.h @@ -29,4 +29,8 @@ + (PFAuthManager *)sharedInstance; +- (void) registerWithAuthenticationProvider:(NSString *)authProvider + credential:(NSString *)credential + delegate:(id)delegate; + @end diff --git a/client-library/PFAuthManager.m b/client-library/PFAuthManager.m index 742cfe3..2771af1 100644 --- a/client-library/PFAuthManager.m +++ b/client-library/PFAuthManager.m @@ -40,6 +40,13 @@ - (void) loginWithAuthenticationProvider:(NSString *)authProvider [PFClient loginWithAuthenticationProvider:authProvider credential:credential callbackTarget:self method:@selector(providerBasedAuthenticationDidCompleteWithSuccess:)]; } +- (void) registerWithAuthenticationProvider:(NSString *)authProvider + credential:(NSString *)credential + delegate:(id)delegate { + self.isAuthenticating = true; + self.delegate = delegate; + [PFClient registerWithAuthenticationProvider:authProvider credential:credential callbackTarget:self method:@selector(providerBasedAuthenticationDidCompleteWithSuccess:)]; +} + (NSArray *)oauthProviderKeys{ diff --git a/client-library/sync/PFClient.h b/client-library/sync/PFClient.h index 5a89f82..2b64993 100644 --- a/client-library/sync/PFClient.h +++ b/client-library/sync/PFClient.h @@ -10,6 +10,7 @@ #import "PFModelObject.h" #import "IUserAnchor.h" #import "Reachability.h" +#import "AuthenticationRequest.h" @class PFSocketManager; @class PushCWUpdateRequest; diff --git a/client-library/sync/PFClient.m b/client-library/sync/PFClient.m index 5eeaece..8957e0e 100644 --- a/client-library/sync/PFClient.m +++ b/client-library/sync/PFClient.m @@ -563,31 +563,35 @@ - (void)setReachableBlock:(NetworkReachable)reachableBlock{ - (void)setUnReachableBlock:(NetworkUnreachable)unReachableBlock{ self.reach.unreachableBlock = unReachableBlock; } - #pragma mark - Registration Methods + + + /** Nitesh * Service method to allow the client application to user Registration request using a * custom authentication provider */ -+ (bool) registerWithAuthenticationProvider:(NSString *)authProvider credential:(NSString *)credential callbackTarget:(id)target method:(SEL)selector { + + + ++(bool) registerWithAuthenticationProvider:(NSString *)authProvider credential:(NSString *)credential callbackTarget:(id)target method:(SEL)selector { [PFClient sharedInstance].authDelegate = target; [[PFClient sharedInstance] startLoginTimeoutTimer]; - AuthenticationRequest *req; req = [self newRegisterRequestWithAuthenticationProvider:authProvider Credential:credential]; PFInvocation* callback = [[PFInvocation alloc] initWithTarget:[PFClient sharedInstance] method:@selector(receivedRegisterUsernamePasswordResponse:)]; - [[PFSocketManager sharedInstance] sendEvent:@"register" data:req callback:callback]; - return true; } - - /** * Service method to make it easier for the client application to issue a registration request */ -+ (AuthenticationRequest *)newRegisterRequestWithAuthenticationProvider:(NSString *)authProvider Credential:(NSString *)credential { + + + ++(AuthenticationRequest *)newRegisterRequestWithAuthenticationProvider:(NSString *)authProvider Credential:(NSString *)credential { + AuthenticationRequest* req = [[AuthenticationRequest alloc] init]; req.authProvider = authProvider; req.deviceId = [[NSUUID UUID] UUIDString]; @@ -596,18 +600,19 @@ + (AuthenticationRequest *)newRegisterRequestWithAuthenticationProvider:(NSStrin } /** - * Callback method for when the registration response is recieved + * Callback method for when the registration response is recieved */ + + + - (void) receivedRegisterUsernamePasswordResponse:(id) result{ NSLog(@"PFClient Got auth response"); - if ([result isMemberOfClass:[AuthenticationResponse class]]) { AuthenticationResponse* response = (AuthenticationResponse*) result; UserToken* userToken = response.result; clientId = response.clientId; self.userId = userToken.user.ID; self.token = userToken.token; - if (self.token.length > 0 && self.userId.length > 0 && [[(AuthenticationResponse *)result statusCode] integerValue] == 200) { [PFClient save]; return; @@ -620,10 +625,11 @@ - (void) receivedRegisterUsernamePasswordResponse:(id) result{ return; } } - [loginTimeOutTimer invalidate]; NSError *error = [NSError errorWithDomain:@"com.activestack.error" code:0 userInfo:@{NSLocalizedDescriptionKey: @"Server did not return a token."}]; [self.authDelegate authenticationDidFailWithError:error]; + + } @end