簡體   English   中英

使用Angularjs,Pac4j和WSO2身份驗證Play Framework

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

我正在使用角度與游戲框架。 我正在申請一個類似“ https://example.com/#/dashboard ”的網址。

我嘗試使用pac4j和WSO2登錄,但問題是登錄后我無法保留URL。一旦登錄,它就會導航到默認頁面。

所以我打算保存請求的URL( https://example.com/#/dashboard ),以便在成功登錄后我可以重定向到請求的頁面

但我已嘗試使用request.path(),request.uri(),request.queryString('')等..但我無法在播放服務器中獲取該請求的URL。 我可以通過request.hostName()獲取主機名(“example.com”)。 我怎樣才能得到“/#/ dashboard”。 你們能幫助我嗎?

我自己找到了解決方案。 url中'#'符號后的參數僅用於路由,因此我們的html只能讀取和路由,服務器無法獲取該值,因此pac4j無法使用此參數存儲和重定向url。 為了使這個工作起作用,我們必須從url中刪除散列'#'。 以下鏈接將幫助您做到這一點。

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

如果您正在使用Yeoman和generator-angular,請執行此額外步驟

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

我正在使用Yeoman&grunt,所以我改變了下面的內容。 在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')
              ),
.....

參考: 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