Skip to content

Commit

Permalink
Merge pull request #17 from shankari/switch_to_new_auth
Browse files Browse the repository at this point in the history
Changes to support switch to general auth infrastructure
  • Loading branch information
shankari authored Aug 20, 2017
2 parents 7d8a03c + 8bd2c0c commit ace1ed3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/android/CommunicationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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()));

Expand Down Expand Up @@ -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();
}
}
6 changes: 3 additions & 3 deletions src/ios/BEMCommunicationHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#import "BEMConstants.h"
#import "LocalNotificationManager.h"
#import <GTMSessionFetcher/GTMSessionFetcherService.h>
#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
Expand Down Expand Up @@ -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];
}
}];
}
Expand Down

0 comments on commit ace1ed3

Please sign in to comment.