带有Angular#的Google UserService登录URL

Google UserService logoutUrl with Angular #

本文关键字:登录 URL UserService Google Angular# 带有      更新时间:2023-09-26

我正在使用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应用程序。我真的希望能够让我的UserServiceURLS按预期工作。有什么想法吗?

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

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

我找到了这个问题的解决方案。如果我发送完整的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....
});

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