secret
Created

OpenID Simple Openid

  • Download Gist
Login.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
package controllers;
 
import java.util.HashMap;
import java.util.Map;
 
import org.codehaus.jackson.node.ObjectNode;
 
import play.libs.F.Promise;
import play.libs.Json;
import play.libs.OpenID;
import play.libs.OpenID.UserInfo;
import play.mvc.Controller;
import play.mvc.Result;
 
public class Login extends Controller {
@SuppressWarnings("serial")
public static final Map<String, String> identifiers = new HashMap<String, String>() {
{
put("google", "https://www.google.com/accounts/o8/id");
}
};
public static Result getProvider( String providerId ) {
String providerUrl = identifiers.get(providerId);
String returnToUrl = "http://localhost:9000/login/verify";
if (providerUrl == null)
return badRequest("Could not find provider " + providerId);
Promise<String> redirectUrl = OpenID.redirectURL(providerUrl, returnToUrl);
ObjectNode node = Json.newObject();
node.put("url", redirectUrl.get());
//The page is going to be redicted using javascript
return ok(node);
}
public static Result verifyLogin() {
Promise<UserInfo> userInfoPromise = OpenID.verifiedId();
UserInfo userInfo = userInfoPromise.get();
return ok(Json.toJson(userInfo));
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.