Play framework is joining the Typesafe Stack — More information in the official announcement
Manual, tutorials & references
Get help with google
OpenID is an open and decentralized identity system. You can easily accept new users in your application without having to keep specific user information. You just have to keep track of authorized users through their OpenID.
This example provides a high-level view of how OpenID authentication can be used within a Play! application:
The OpenID functionality is provided by the play.libs.OpenID class and is build using [[http://code.google.com/p/openid4java/|OpenID4Java]].
@Before(unless={"login", "authenticate"})
static void checkAuthenticated() {
if(!session.contains("user")) {
login();
}
}
public static void index() {
render("Hello %s!", session.get("user"));
}
public static void login() {
render();
}
public static void authenticate(String user) {
if(OpenID.isAuthenticationResponse()) {
UserInfo verifiedUser = OpenID.getVerifiedID();
if(verifiedUser == null) {
flash.put("error", "Oops. Authentication has failed");
login();
}
session.put("user", verifiedUser.id);
index();
} else {
OpenID.id(user).verify(); // will redirect the user
}
}
And the login.html template :
#{if flash.error}
<h1>${flash.error}</h1>
#{/if}
<form action="@{Application.authenticate()}" method="POST">
<label for="user">What's your OpenID?</label>
<input type="text" name="user" id="user" />
<input type="submit" value="login..." />
</form>
</code>
And finally the routes definitions:
GET / Application.index
GET /login Application.login
* /authenticate Application.authenticate
Comments
Use this form to add corrections, additions and suggestions about the documentation on this page. Please ask questions on the play-framework group instead. Support requests, bug reports, and off-topic comments will be deleted without warning.