简体   繁体   English

使用Angularjs,Pac4j和WSO2身份验证Play Framework

[英]Play Framework with Angularjs, Pac4j and WSO2 authentication

I am using angular with play framework. 我正在使用角度与游戏框架。 I am requesting a URL something like " https://example.com/#/dashboard ". 我正在申请一个类似“ https://example.com/#/dashboard ”的网址。

I try to login using pac4j and WSO2 but the problem is that i can't retain the URL after logged in. Once it is logged in, it navigate to the default page. 我尝试使用pac4j和WSO2登录,但问题是登录后我无法保留URL。一旦登录,它就会导航到默认页面。

So i planned to save the requested URL( https://example.com/#/dashboard ) so that after successful login i can redirect to the requested page 所以我打算保存请求的URL( https://example.com/#/dashboard ),以便在成功登录后我可以重定向到请求的页面

But i have tried with request.path(), request.uri(), request.queryString('') etc.. but i can't get that reqeusted url in play server. 但我已尝试使用request.path(),request.uri(),request.queryString('')等..但我无法在播放服务器中获取该请求的URL。 I can get the host name("example.com") through request.hostName(). 我可以通过request.hostName()获取主机名(“example.com”)。 How can i get "/#/dashboard". 我怎样才能得到“/#/ dashboard”。 Can you guys help me. 你们能帮助我吗?

I found solution on my own. 我自己找到了解决方案。 The param after '#' symbol in the url is only for routing so our html only can read and route, server can't get that value so pac4j can't store and redirect url with this parameters. url中'#'符号后的参数仅用于路由,因此我们的html只能读取和路由,服务器无法获取该值,因此pac4j无法使用此参数存储和重定向url。 To make this thing work, we have to remove hash '#' from the url. 为了使这个工作起作用,我们必须从url中删除散列'#'。 The below links will help you to do that. 以下链接将帮助您做到这一点。

https://scotch.io/tutorials/pretty-urls-in-angularjs-removing-the-hashtag https://scotch.io/tutorials/pretty-urls-in-angularjs-removing-the-hashtag

If you are using Yeoman & generator-angular do this extra step 如果您正在使用Yeoman和generator-angular,请执行此额外步骤

https://www.npmjs.com/package/connect-modrewrite https://www.npmjs.com/package/connect-modrewrite

I am using Yeoman & grunt so i changed something like below. 我正在使用Yeoman&grunt,所以我改变了下面的内容。 In package.json add this dependency "connect-modrewrite" and in the grunt add the below in livereload 在package.json中添加此依赖项“connect-modrewrite”,并在grunt中添加以下livereload

.....
      livereload: {
        options: {
          open: true,
          middleware: function (connect) {
            return [
              modRewrite(['^[^\\.]*$ /index.html [L]']), // Only this line need to be added
              connect.static('.tmp'),
              connect().use(
                '/bower_components',
                connect.static('./bower_components')
              ),
.....

Ref : http://jjt.io/2013/11/16/angular-html5mode-using-yeoman-generator-angular/ but this link for older versions, for new version use the link which i mentioned above( https://www.npmjs.com/package/connect-modrewrite ) 参考: http//jjt.io/2013/11/16/angular-html5mode-using-yeoman-generator-angular/但旧版本的此链接,新版本使用我上面提到的链接( https:// www.npmjs.com/package/connect-modrewrite

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM