-
-
Save Nican/dcd9140eceb8f406f05a to your computer and use it in GitHub Desktop.
OpenID Simple Openid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment