diff --git a/src/android/CommunicationHelper.java b/src/android/CommunicationHelper.java index 263a4ad..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; @@ -32,8 +31,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 +84,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 +178,8 @@ public static String getUserPersonalData(Context ctxt, String fullURL, String us connection.close(); return result; } + + private static String getTokenSync(Context ctxt) { + return AuthTokenCreationFactory.getInstance(ctxt).getServerToken().await().getToken(); + } } diff --git a/src/ios/BEMCommunicationHelper.m b/src/ios/BEMCommunicationHelper.m index 99b04b1..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,11 +139,11 @@ -(void)execute { return; } - [[AuthCompletionHandler sharedInstance] getValidAuth:^(GIDGoogleUser *user,NSError* error) { + [[AuthTokenCreationFactory getInstance] getJWT:^(NSString *token, NSError *error) { if (error != NULL) { self.mCompletionHandler(jsonData, NULL, error); } else { - [self postToHost:user.authentication.idToken]; + [self postToHost:token]; } }]; }