我已经为谷歌应用引擎编写了 openID 登录。
static {
openIdProviders = new HashMap<String, String>();
openIdProviders.put("Google", "https://www.google.com/accounts/o8/id");
openIdProviders.put("Yahoo", "yahoo.com");
}
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser(); // or req.getUserPrincipal()
Set<String> attributes = new HashSet();
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
if (user != null) {
out.println("Hello <i>" + user.getNickname() + "</i>!");
out.println("[<a href=\"" + userService.createLogoutURL(req.getRequestURI())+ "\">sign out</a>]");
} else {
out.println("Sign in at: ");
for (String providerName : openIdProviders.keySet()) {
String providerUrl = openIdProviders.get(providerName);
String loginUrl = userService.createLoginURL(req.getRequestURI(), null, providerUrl, attributes);
out.println("[<a href=\"" + loginUrl + "\">" + providerName+ "</a>] ");
}
}
}
当我部署我的应用程序时,一切都运行良好。没问题。选择 openID 提供程序后,我被重定向到该页面:
sample.appspot.com/_ah/login_redir?claimid=[OPen ID provider]=[my sample page]/_ah/login_required
那是我的servlet。
<servlet>
<servlet-name>Authorization</servlet-name>
<servlet-class>ge.eid.test.Authorization</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Authorization</servlet-name>
<url-pattern>/_ah/login_required</url-pattern>
</servlet-mapping>
好的。一切都很好!但是,当我在本地主机上运行示例应用程序时,我有另一个重定向 URL:
http://localhost:8888/_ah/login?continue=/F_ah/Flogin_required
所以我没有OpenID 登录。我有类似的东西:
问题1)如何在本地主机上创建openID登录。