【问题标题】:signing out appengine app without signing out from google.com退出 appengine 应用程序而不从 google.com 退出
【发布时间】:2013-01-06 09:34:59
【问题描述】:

以下代码将从 appengine 应用(在本例中为自定义域)和 google.com 中注销用户:

public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
    UserService userService = UserServiceFactory.getUserService();

    String thisURL = req.getRequestURI();

    resp.setContentType("text/html");
    if (req.getUserPrincipal() != null) {
        resp.getWriter().println("<p>Hello, " +
                                 req.getUserPrincipal().getName() +
                                 "!  You can <a href=\"" +
                                 userService.createLogoutURL(thisURL) +
                                 "\">sign out</a>.</p>");
    }
}
}

我们如何才能只从 appengine 应用中退出并让用户继续登录 google.com?

【问题讨论】:

    标签: java google-app-engine


    【解决方案1】:

    无法直接从 UserService API 执行此操作。

    您可以手动删除已设置的 AppEngine 特定 cookie,而不是使用 UserService API 注销。查看 this blog post 讨论如何这样做(用 Python 编写,但您应该能够为 Java 修改它)。这应该有效地将用户从您自己的应用程序中注销,而不是从其他 Google 服务中注销(尽管我自己没有对此进行测试)。

    更强大的方法是创建您自己的 User 类并管理您自己的会话 cookie,同时包装 UserService API。与非常易于使用的 UserService API 相比,这种方法的缺点是设置它需要额外的工作。但是,维护自己的用户的好处是,您将能够使用除 Google 之外的其他身份验证方法(例如,现在您也可以使用 Facebook 登录,如果您选择设置,甚至可以使用本机登录上)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-27
      相关资源
      最近更新 更多