我为google App引擎编写了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>
确定。一切都很好!但是,当我在localhost上运行sampe应用程序时,我有另一个重定向URL:
http://localhost:8888/_ah/login?continue=/F_ah/Flogin_required
所以我不拥有OpenID登录。我有类似的东西:
问题1)如何在localhost上创建openID登录。
答案 0 :(得分:2)
这是一种正常的行为,因为在localhost上你可能想要尝试许多不同的帐户,如果你每次必须真正登录一个真实的帐户,那将是一团糟。因此,在localhost上,只需提供您想要的任何电子邮件并检查您是否想成为管理员,就可以模拟OpenID用户。