-
-
Save aaberg/4104804 to your computer and use it in GitHub Desktop.
Login to play20 application with google acount
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
GET /login/auth controllers.Security.auth() | |
GET /login/verify controllers.Security.verify() |
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
@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