From f311677d612c5e111ba6dbaa469c5b876dc31091 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Sat, 19 Aug 2017 17:52:21 -0700 Subject: [PATCH 1/2] Changes to support switch to general auth infrastructure Changes corresponding to to dismiss://github.com/e-mission/cordova-jwt-auth/pull/18 In particular, changes https://github.com/e-mission/cordova-jwt-auth/pull/18/commits/c84b93efc3e68d253e018e80edffc159246f0e94 and https://github.com/e-mission/cordova-jwt-auth/pull/18/commits/eddfe9bd2bedf5f932f30ee2fcbc9de7bbecf497 --- src/android/CommunicationHelper.java | 10 ++++++---- src/ios/BEMCommunicationHelper.m | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/android/CommunicationHelper.java b/src/android/CommunicationHelper.java index 263a4ad..dc1ee28 100644 --- a/src/android/CommunicationHelper.java +++ b/src/android/CommunicationHelper.java @@ -32,8 +32,7 @@ public class CommunicationHelper { public static String readResults(Context ctxt, String cacheControlProperty) throws MalformedURLException, IOException { final String result_url = ConnectionSettings.getConnectURL(ctxt)+"/compare"; - final String userName = UserProfile.getInstance(ctxt).getUserEmail(); - final String userToken = GoogleAccountManagerAuth.getServerToken(ctxt, userName); + final String userToken = CommunicationHelper.getTokenSync(ctxt); final URL url = new URL(result_url); final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); @@ -86,8 +85,7 @@ public static String pushGetJSON(Context ctxt, String fullURL, msg.setHeader("Content-Type", "application/json"); // Fill in the object - final String userName = UserProfile.getInstance(ctxt).getUserEmail(); - final String userToken = GoogleAccountManagerAuth.getServerToken(ctxt, userName); + final String userToken = CommunicationHelper.getTokenSync(ctxt); filledJsonObject.put("user", userToken); msg.setEntity(new StringEntity(filledJsonObject.toString())); @@ -181,4 +179,8 @@ public static String getUserPersonalData(Context ctxt, String fullURL, String us connection.close(); return result; } + + private static String getTokenSync(Context ctxt) { + return new GoogleAccountManagerAuth(ctxt).getServerToken().await().getToken(); + } } diff --git a/src/ios/BEMCommunicationHelper.m b/src/ios/BEMCommunicationHelper.m index 99b04b1..7086742 100644 --- a/src/ios/BEMCommunicationHelper.m +++ b/src/ios/BEMCommunicationHelper.m @@ -139,11 +139,11 @@ -(void)execute { return; } - [[AuthCompletionHandler sharedInstance] getValidAuth:^(GIDGoogleUser *user,NSError* error) { + [[AuthCompletionHandler sharedInstance] getJWT:^(NSString *token, NSError *error) { if (error != NULL) { self.mCompletionHandler(jsonData, NULL, error); } else { - [self postToHost:user.authentication.idToken]; + [self postToHost:token]; } }]; } From 8bd2c0cbeb2680bd668ef31e719e27cac79557a1 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Sat, 19 Aug 2017 22:10:54 -0700 Subject: [PATCH 2/2] Switch to the new factory interface Instead of hardcoding the auth method. Related iOS change https://github.com/e-mission/cordova-jwt-auth/pull/18/commits/268d52e46bc206ddf2b11be0f671da0c268c56e1 and android change https://github.com/e-mission/cordova-jwt-auth/pull/18/commits/847905deba2480df36d741e1a47f84af96bde3f7 --- src/android/CommunicationHelper.java | 5 ++--- src/ios/BEMCommunicationHelper.m | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/android/CommunicationHelper.java b/src/android/CommunicationHelper.java index dc1ee28..af4cf2d 100644 --- a/src/android/CommunicationHelper.java +++ b/src/android/CommunicationHelper.java @@ -20,8 +20,7 @@ import java.net.URL; import edu.berkeley.eecs.emission.cordova.connectionsettings.ConnectionSettings; -import edu.berkeley.eecs.emission.cordova.jwtauth.GoogleAccountManagerAuth; -import edu.berkeley.eecs.emission.cordova.jwtauth.UserProfile; +import edu.berkeley.eecs.emission.cordova.jwtauth.AuthTokenCreationFactory; import edu.berkeley.eecs.emission.cordova.unifiedlogger.Log; import edu.berkeley.eecs.emission.R; @@ -181,6 +180,6 @@ public static String getUserPersonalData(Context ctxt, String fullURL, String us } private static String getTokenSync(Context ctxt) { - return new GoogleAccountManagerAuth(ctxt).getServerToken().await().getToken(); + return AuthTokenCreationFactory.getInstance(ctxt).getServerToken().await().getToken(); } } diff --git a/src/ios/BEMCommunicationHelper.m b/src/ios/BEMCommunicationHelper.m index 7086742..8aac9e3 100644 --- a/src/ios/BEMCommunicationHelper.m +++ b/src/ios/BEMCommunicationHelper.m @@ -14,7 +14,7 @@ #import "BEMConstants.h" #import "LocalNotificationManager.h" #import -#import "AuthCompletionHandler.h" +#import "AuthTokenCreationFactory.h" // This is the base URL // We need to append the username to it, and then we need to authenticate the user as well @@ -139,7 +139,7 @@ -(void)execute { return; } - [[AuthCompletionHandler sharedInstance] getJWT:^(NSString *token, NSError *error) { + [[AuthTokenCreationFactory getInstance] getJWT:^(NSString *token, NSError *error) { if (error != NULL) { self.mCompletionHandler(jsonData, NULL, error); } else {