Dealing with OpenId(II)
First Page index.jsp:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello World!</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<style type="text/css">
.openid_identifier {
width:300px;
}
</style>
</head>
<body>
<div>
<fieldset>
<legend>Sample 2: using the Simple Registration extension(doc: <a href="http://code.google.com/p/openid4java/wiki/SRegHowTo">SRegHowTo</a>)</legend>
<form action="consumer" method="post">
<div>
<input type="text" name="openid_identifier" class="openid_identifier" value="https://www.google.com/accounts/o8/id"/>
<br />
<input type="checkbox" name="nickname" value="1" id="nickname" checked="checked" />
<label for="nickname">Nickname</label>
<input type="checkbox" name="email" value="1" id="email" checked="checked" />
<label for="email">Email</label>
<input type="checkbox" name="fullname" value="1" id="fullname" checked="checked" />
<label for="fullname">Fullname</label>
<input type="checkbox" name="country" value="1" id="country" checked="checked" />
<label for="country">Country</label>
<input type="checkbox" name="language" value="1" id="language" checked="checked" />
<label for="language">Language</label>
<br />
<input type="submit" name="login" value="Login" />
</div>
</form>
</fieldset>
</div>
</body>
</html>
Maybe, if it is really project, I will hide every properties, only place one openId link here.
Form redirect page, formredirection.jsp:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OpenID HTML FORM Redirection</title>
</head>
<body onload="document.forms['openid-form-redirection'].submit();">
<form name="openid-form-redirection" action="${message.OPEndpoint}" method="post" accept-charset="utf-8">
<c:forEach var="parameter" items="${message.parameterMap}">
<input type="hidden" name="${parameter.key}" value="${parameter.value}"/>
</c:forEach>
Continue...
</form>
</body>
</html>
Return page, we can see all the parameter from google server side. return.jsp:
<?xml version="1.0" encoding="UTF-8"?>
<%@page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello World!</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
</head>
<body>
<div>
Login Success!
<div>
queryString:
${pageContext.request.queryString}
</div>
<div>
<dl>
<dt>Your OpenID: ${identifier}</dt>
<dt>Nickname: ${nickname}</dt>
<dt>Email: ${email}</dt>
<dt>Fullname: ${fullname}</dt>
<dt>Country: ${country}</dt>
<dt>Language: ${language}</dt>
</dl>
</div>
<div>
<a href="logout.jsp">Logout</a>
</div>
</div>
</body>
</html>
logout page, logout.jsp:
<%
session.invalidate();
response.sendRedirect("index.jsp");
%>
We can get back many informations from google server:
Your OpenID: https://www.google.com/accounts/o8/id?id=AItOawm3ZltSt7HfYvmrzy8M1MWAoYg5TXGaJvc
Nickname: luo
Email:
[email protected]
Fullname: carl
Country: CN
Language: en-US
all the demo codes are in sample project easyopenid.