Skip to content

Instantly share code, notes, and snippets.

@aaberg
Forked from sealskej/Application.java
Created November 18, 2012 12:00
Show Gist options
  • Save aaberg/4104804 to your computer and use it in GitHub Desktop.
Save aaberg/4104804 to your computer and use it in GitHub Desktop.
Login to play20 application with google acount
GET /login/auth controllers.Security.auth()
GET /login/verify controllers.Security.verify()
@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 auth() {
Logger.debug("authenticate");
String providerId = "google";
String providerUrl = identifiers.get(providerId);
String returnToUrl = routes.Security.verify().absoluteURL(request());
if (providerUrl == null) {
return badRequest("Could not find provider " + providerId);
}
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("Email", "http://schema.openid.net/contact/email");
attributes.put("FirstName", "http://schema.openid.net/namePerson/first");
attributes.put("LastName", "http://schema.openid.net/namePerson/last");
Promise<String> redirectUrl = OpenID.redirectURL(providerUrl, returnToUrl, attributes);
return redirect(redirectUrl.get());
}
public static Result verify() {
Logger.debug("verifyLogin");
Promise<UserInfo> userInfoPromise = OpenID.verifiedId();
UserInfo userInfo = userInfoPromise.get();
JsonNode json = Json.toJson(userInfo);
return ok(json);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment