Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to support switch to general auth infrastructure #17

Merged
merged 2 commits into from
Aug 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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