简体   繁体   中英

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 ".

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.

So i planned to save the requested URL( https://example.com/#/dashboard ) so that after successful login i can redirect to the requested page

But i have tried with request.path(), request.uri(), request.queryString('') etc.. but i can't get that reqeusted url in play server. I can get the host name("example.com") through request.hostName(). How can i get "/#/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. To make this thing work, we have to remove hash '#' from the url. The below links will help you to do that.

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

If you are using Yeoman & generator-angular do this extra step

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

I am using Yeoman & grunt so i changed something like below. In package.json add this dependency "connect-modrewrite" and in the grunt add the below in 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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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