【问题标题】:Google UserService logoutUrl with Angular #带有 Angular 的 Google UserService logoutUrl #
【发布时间】:2015-11-06 00:55:17
【问题描述】:

我正在使用 Google UserService 获取我的应用引擎 Angular 应用程序的登录和注销 URL,并尝试将重定向的路径作为查询参数传递。这是一个 Angular URL 的示例:

http://localhost:8080/#/dashboard

在 Java 中,我尝试像这样创建 Url:

String logoutUrl = UserServiceFactory.getUserService().createLogoutURL(redirectPath);

redirectPath 是预期的查询参数字符串“#/dashboard”。

问题是使用包含的“#”生成的 URL 不起作用。它只是使用新的 URL 重定向到自身。下面是从 UserService 生成的 URL 的样例:

/_ah/logout?continue=%23%2Fdashboard

如果我只是将字符串“/”传递给端点,那么我会得到一个这样的 URL:

/_ah/logout?continue=%2F

这按预期工作,并将我的 Angular 应用程序加载到根文档中。我真的希望能够让我的 UserService URLS 按预期工作。有什么想法吗?

这是它从上面的 URL 重定向到的 URL:

http://localhost:8080/_ah/logout?continue=%23%2Fdashboard#/dashboard

【问题讨论】:

  • 您能否提供有关此“奇怪的重定向”的 HTTP 标头/更多详细信息?
  • 我在问题中添加了重定向 URL。

标签: javascript angularjs google-app-engine angular-ui-router gae-userservice


【解决方案1】:

我找到了解决问题的方法。如果我发送完整的 URL 而不仅仅是资源路径,则 UserService 可以正常工作。我的 Angular 代码现在如下所示。该应用程序将获取登录 URL,然后在登录时重定向到请求的 URL。这实际上是在服务中,但我简化了 StackOverflow 的代码。

$http({
    url: '/rest/user/login_uri?redirectPath=' + encodeURIComponent($location.absUrl()),
    method: 'GET',
    contentType: "application/json"
}).success(function (data) {
    $window.location.href = data.uri;
}).catch(function (data) {
    //Handle failed request....
});

我希望这对以后的人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-07
    • 1970-01-01
    相关资源
    最近更新 更多