Permalink
Browse files

Added encoding WSUrlFetch.newRequest() and fixed the code for the sce…

…nario when a user requests "offline_access" and facebook does not send an expiry time.
  • Loading branch information...
1 parent af4018d commit fdb6e9c1f0368d047633efeee37560c2aca5b65e @SliMM SliMM committed Aug 10, 2011
Showing with 7 additions and 5 deletions.
  1. +7 −5 app/controllers/FBConnect.java
@@ -36,7 +36,7 @@ public static void callback() {
if(code != null){
String authUrl = fbsession.getAuthUrl(code);
WSUrlFetch ws = new WSUrlFetch();
- String response = ws.newRequest(authUrl).get().getString();
+ String response = ws.newRequest(authUrl, "UTF-8").get().getString();
String accessToken = null;
Integer expires = null;
String[] pairs = response.split("&");
@@ -53,15 +53,17 @@ public static void callback() {
}
}
}
- if (accessToken != null && expires != null) {
+ if (accessToken != null) {
try{
Class model = Class.forName(fbsession.getModel());
Method method = model.getMethod("facebookOAuthCallback", new Class[] { JsonObject.class });
if(Modifier.isStatic(method.getModifiers())){
String uri = "https://graph.facebook.com/me?access_token="+WS.encode(accessToken);
- JsonObject jsonData = ws.newRequest(uri).get().getJson().getAsJsonObject();
+ JsonObject jsonData = ws.newRequest(uri, "UTF-8").get().getJson().getAsJsonObject();
jsonData.add("accessToken", new JsonPrimitive(accessToken));
- jsonData.add("expires", new JsonPrimitive(expires));
+ if(expires != null) {
+ jsonData.add("expires", new JsonPrimitive(expires));
+ }
method.invoke(null, jsonData);
}else{
throw new UnexpectedException("Module fbconnect expects your facebookOAuthCallback method to be static");
@@ -76,7 +78,7 @@ public static void callback() {
throw new UnexpectedException("Module fbconnect encountered an error while calling your model's findForFacebookOAuth: "+e.getMessage());
}
} else {
- throw new UnexpectedException("Module fbconnect could not find access token and expires in facebook callback");
+ throw new UnexpectedException("Module fbconnect could not find access token in facebook callback");
}
}
redirect(fbsession.getLandUrl());

0 comments on commit fdb6e9c

Please sign in to comment.