1

我已经为谷歌应用引擎编写了 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登录。

4

1 回答 1

2

这是一种正常的行为,因为在 localhost 上您可能想尝试许多不同的帐户,如果您每次都必须使用真实帐户实际登录,那将是一团糟。因此,当在 localhost 上时,您只需提供您想要的任何电子邮件并检查您是否想成为管理员即可模拟 OpenID 用户。

于 2013-08-26T10:01:09.617 回答