Skip to content

Instantly share code, notes, and snippets.

@ryanswanstrom
Created December 13, 2010 21:19
Show Gist options
  • Save ryanswanstrom/739618 to your computer and use it in GitHub Desktop.
Save ryanswanstrom/739618 to your computer and use it in GitHub Desktop.
This class shows some code for the callback of a Janrain (formerly Rpx Now) login using the Play Framework
package controllers;
import com.google.gson.JsonElement;
import play.Play;
import java.util.Properties;
import play.libs.WS;
import play.libs.WS.WSRequest;
import play.mvc.Controller;
/**
* This class is for the callback of a Janrain(formerly RPXNow) login.
*/
public class Login extends Controller {
public static void tokenCallback(String token) {
Properties p = Play.configuration;
// Try the driver
String rpxApi = p.getProperty("login.rpx.apiKey");
WSRequest rpxRequest = WS.url("http://rpxnow.com/api/v2/auth_info");
// get RPX
rpxRequest.setParameter("token", token);
rpxRequest.setParameter("apiKey", rpxApi);
JsonElement rpxJson = rpxRequest.get().getJson();
JsonElement profile = rpxJson.getAsJsonObject().get("profile");
String identifier = profile.getAsJsonObject().getAsJsonPrimitive("identifier").getAsString();
welcome(identifier);
}
public static void welcome(String id) {
render(id);
}
}
@ryanswanstrom
Copy link
Author

use getAsJsonPrimitive()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment