From a2c1d561395dd2a9a8f588a242d4b686de213826 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Tue, 18 Apr 2017 16:46:47 -0700 Subject: [PATCH 1/3] Start properly versioning the plugin Since we are currently at version 1, I will lazily start versioning our native plugins so that we have a better sense of how we are making changes --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index f4507ce..9a99e6a 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,7 +1,7 @@ + version="1.0.0"> ServerComm Abstraction for communication settings, and for making both GET From 9cdfbf55c7375336889ea4234e13dfa4485e7bf3 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Wed, 19 Apr 2017 23:13:40 -0700 Subject: [PATCH 2/3] Switch the header file names and locations Including the headers as part of this project leads to compile errors caused by duplicate definitions. This fixes it. See https://github.com/google/gtm-session-fetcher/issues/82 for more details --- src/ios/BEMCommunicationHelper.h | 2 +- src/ios/BEMCommunicationHelper.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ios/BEMCommunicationHelper.h b/src/ios/BEMCommunicationHelper.h index 16e8430..e8dba88 100644 --- a/src/ios/BEMCommunicationHelper.h +++ b/src/ios/BEMCommunicationHelper.h @@ -7,7 +7,7 @@ // #import -#import "GTMSessionFetcherService.h" +#import @interface CommunicationHelper : NSObject // Wrappers for our specific functionality diff --git a/src/ios/BEMCommunicationHelper.m b/src/ios/BEMCommunicationHelper.m index 1659e35..a1a6b54 100644 --- a/src/ios/BEMCommunicationHelper.m +++ b/src/ios/BEMCommunicationHelper.m @@ -14,7 +14,7 @@ #import "BEMConnectionSettings.h" #import "BEMConstants.h" #import "LocalNotificationManager.h" -#import "GTMSessionFetcher.h" +#import // This is the base URL // We need to append the username to it, and then we need to authenticate the user as well From c3406417f268e8ab377ba46a51215c29e5516562 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Thu, 20 Apr 2017 12:35:40 -0700 Subject: [PATCH 3/3] Use the new form of the AuthCompletionHandler This changes the communicationhelper to use the new form of the `AuthCompletionHandler` (change in https://github.com/e-mission/cordova-jwt-auth/pull/13/commits/cfa54573fb611d1c82feeeecf1ec6ca8720450ad) Also removes the obsolete callbacks which are not invoked any more --- src/ios/BEMCommunicationHelper.m | 52 ++++---------------------------- 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/src/ios/BEMCommunicationHelper.m b/src/ios/BEMCommunicationHelper.m index a1a6b54..99b04b1 100644 --- a/src/ios/BEMCommunicationHelper.m +++ b/src/ios/BEMCommunicationHelper.m @@ -10,11 +10,11 @@ // #import "BEMCommunicationHelper.h" -#import "AuthCompletionHandler.h" #import "BEMConnectionSettings.h" #import "BEMConstants.h" #import "LocalNotificationManager.h" #import +#import "AuthCompletionHandler.h" // This is the base URL // We need to append the username to it, and then we need to authenticate the user as well @@ -34,10 +34,6 @@ return aBool? @"YES" : @"NO"; } -@interface CommunicationHelper() { -} -@end - @implementation CommunicationHelper +(void)getCustomSettings:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler { @@ -143,18 +139,17 @@ -(void)execute { return; } - [[AuthCompletionHandler sharedInstance] getValidAuth:^(GTMOAuth2Authentication *auth,NSError* error) { + [[AuthCompletionHandler sharedInstance] getValidAuth:^(GIDGoogleUser *user,NSError* error) { if (error != NULL) { self.mCompletionHandler(jsonData, NULL, error); } else { - // TODO: have postToHost take the auth token as input instead of re-reading it - [self postToHost]; + [self postToHost:user.authentication.idToken]; } - } forceRefresh:FALSE]; + }]; } -- (void)postToHost { +- (void)postToHost:(NSString*)idToken { [LocalNotificationManager addNotification:[NSString stringWithFormat: @"postToHost called with url = %@", self.mUrl] showUI:FALSE]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] @@ -164,7 +159,7 @@ - (void)postToHost { [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; - NSString *userToken = [AuthCompletionHandler sharedInstance].getIdToken; + NSString *userToken = idToken; // At this point, we assume that all the authentication is done correctly // Should I try to verify making a remote call or add that to a debug screen? [self.mJsonDict setObject:userToken forKey:@"user"]; @@ -204,39 +199,4 @@ - (void)postToHost { } } -- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error usingController:(UIViewController *)viewController { - NSLog(@"CommunicationHelper.finishedWithAuth called with auth = %@ and error = %@", auth, error); - if (error != NULL) { - NSLog(@"Got error %@ while authenticating", error); - self.mCompletionHandler(NULL, NULL, error); - // modify some kind of error count and notify that user needs to sign in again - } else { - [[AuthCompletionHandler sharedInstance] unregisterFinishDelegate:self]; - [self postToHost]; - } -} - -- (void)finishRefreshSelector:(GTMOAuth2Authentication *)auth - request:(NSMutableURLRequest *)request - finishedWithError:(NSError *)error { - [LocalNotificationManager addNotification:[NSString stringWithFormat: - @"CommunicationHelper.finishRefreshSelector called with auth = %@, request = %@, error = %@", auth, request, error] showUI:FALSE]; - - if (error != NULL) { - self.mCompletionHandler(NULL, NULL, error); - } else { - BOOL stillExpired = ([auth.expirationDate compare:[NSDate date]] == NSOrderedAscending); - if (stillExpired) { - [LocalNotificationManager addNotification:[NSString stringWithFormat: - @"No more methods to try, I GIVE UP!"] showUI:TRUE]; - } else { - // Check to see whether the sharedInstance auth token has been updated - [LocalNotificationManager addNotification:[NSString stringWithFormat: - @"Auth token in the shared instance is %@, posting to host", [AuthCompletionHandler sharedInstance].currAuth] showUI:FALSE]; - [self postToHost]; - } - } - -} - @end