diff --git a/ActiveStack.podspec b/ActiveStack.podspec index 17b8307..1028cc5 100644 --- a/ActiveStack.podspec +++ b/ActiveStack.podspec @@ -2,19 +2,21 @@ 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' 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 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 7e568ec..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; @@ -70,4 +71,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..8957e0e 100644 --- a/client-library/sync/PFClient.m +++ b/client-library/sync/PFClient.m @@ -563,4 +563,73 @@ - (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