App Engine的登录失败重定向 [英] App Engine Login Redirect Fails

查看:114
本文介绍了App Engine的登录失败重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在2011年3月1日的App Engine改变了它的登录流程,打破了我的应用程序(见
谷歌网上论坛<一个href=\"http://groups.google.com/group/google-appengine-java/browse_thread/thread/21f534e093250b56/9decc6b1eddd9ba6?pli=1\"相对=nofollow>消息)。这个问题在这个堆栈也来了
溢<一个href=\"http://stackoverflow.com/questions/5203545/why-does-google-app-engine-append-a-path-to-my-continue-location-during-login\">question.建议的答案

On March 1, 2011 App Engine changed its login flow, breaking my app (see the Google Groups message). This issue also came up in this Stack Overflow question. The suggested answers are

这个应用程式的执行重定向。也就是说,createLoginUrl只能当
继续URL是应用程序的URL。如果需要用户发送到
另一个应用程序/主机登录后,那么你的应用程序需要做的重定向

"have the app perform the redirect. That is, createLoginUrl only works when the continue url is a url for the app. If you need the user to be sent to another app/host after login, then your app needs to do that redirect"

在你自己的应用程序建立一个重定向处理。让该目标
的继续参数,并将其发送最后重定向到您的
实际的目标。

"set up a redirect handler on your own app. Make that the target of the continue parameter, and have it send a final redirect to your actual target".

我要问这个问题得到关于如何使这项工作的细节。我的应用程序由两个GAE应用程序,一个GWT前端和后端露出的REST
API。这里是电流流过。

I'm asking this question to get details on how to make this work. My application consists of two GAE apps, a GWT front end and the back end exposing a REST API. Here is the current flow.

在用户浏览 http://my-front.appspot.com/ 和GWT使得
JSONP调用一个 http://my-back.appspot.com/User 的servlet。

The user browses to http://my-front.appspot.com/, and the GWT makes a JSONP call to a http://my-back.appspot.com/User servlet.

在/用户的servlet检查GAE
UserServiceFactory.getUserService()。getCurrentUser(),看看它是否
空值。对于没有登录的用户,这是空,而Servlet返回
JSONP用户没有登录

The /User servlet checks the GAE UserServiceFactory.getUserService().getCurrentUser() to see if it's null. For users not logged in, this is null, and the servlet returns JSONP that the user is not logged in.

在GWT code收到消息无法登录,并执行

The GWT code gets the "not logged in" message, and does

String login = "http://my-back.appspot.com/Login";
Window.open(login, "_self", "");

在登录的servlet:

The Login servlet:

public void doActualGet(HttpServletRequest req, HttpServletResponse resp) 
    throws ServletException, IOException {

    UserService userService = UserServiceFactory.getUserService();
    String url = "http://my-back.appspot.com/LoginRedirectServlet";
    // String url ="http://my-front.appspot.com";  <--------- Before 1 March
    log.info("Auth then redirect to: " + url);
    String redirect = userService.createLoginURL(url);
    resp.setStatus(301);
    resp.setHeader("Location", redirect);
    resp.setHeader("Connection", "close");
}

我的新LoginRedirectServlet有句台词:

My new LoginRedirectServlet has one line:

resp.sendRedirect("http://my-front.appspot.com/");

这通常会导致重定向循环,虽然有时打的初始URL几次后,它的工作原理。我怀疑是有一些错Window.open近code,但我向所有人开放的建议。

This usually results in a redirect loop, though sometimes after hitting the initial url several times it works. My suspicion is that there's something wrong about the code near Window.open, but I'm open to all suggestions.

谢谢,
格伦

推荐答案

信贷由于尼克·约翰逊抱怨的两个应用程序架构。我从来不喜欢它。我搬到战争/ MyFront.html和战争/ myfront编译GWT code /到myback项目的WAR文件,改变了所有的URL形式的 http://my-back.appspot.com/ 和部署。有效!

Credit due to Nick Johnson for whining about the two-app architecture. I've never liked it. I moved war/MyFront.html and the compiled GWT code in war/myfront/ to the war file of the myback project, changed all urls to the form http://my-back.appspot.com/ and deployed. It worked!

这仅仅是一个黑客,但它证明了的原则。

This is just a hack, but it proves the principle.

这篇关于App Engine的登录失败重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆