Angularjs with keycloak auth keeps adding the same params to url after refresh

别来无恙 提交于 2019-12-11 10:58:30

问题


I am using angularjs and keycloak on my portal to authenticate. The problem might be something I configurated wrong with keycloak or something that I am missing with angular that I should do.

When I log in to the page for the first time I get something like

http://localhost/index.html?code=dQ_OdChtwNj794waGS4JGXDkKPkZd5iOJ51B2KTGr-I.3d7dc148-1fc5-4d36-9bbf-a642c8d2a283&state=a8ab64ee-4296-4048-89e8-777bbf1f39b7

After I reload I get something like this

http://localhost/index.html?code=dQ_OdChtwNj794waGS4JGXDkKPkZd5iOJ51B2KTGr-I.3d7dc148-1fc5-4d36-9bbf-a642c8d2a283&state=a8ab64ee-4296-4048-89e8-777bbf1f39b7&prompt=none&code=vh3A5izxDs5dV2IhXkb_wQUtiXqW6Kq8rAdPhIvnSF4.f127afb6-4980-4367-add7-0a951a5741cb&state=864c8ff8-a1d5-4963-8375-7ed11c124b90

As I keep refreshing the page when I am developing prompt, code and state start to pile up and I end up having.

This is my code https://github.com/jdc18/angular-product-app-keycloak/blob/master/angular-product-app2/src/main/webapp/js/app.js I have changed the code from that a little bit but it is basically the same. I am using ui-router instead of ng-route now but I have the same problem.

Also I am not sure if it is ok but with ng-route or ui-router if I click on any of my links, like profile I get something like

http://localhost/index.html?code=dQ_OdChtwNj794waGS4JGXDkKPkZd5iOJ51B2KTGr-I.3d7dc148-1fc5-4d36-9bbf-a642c8d2a283&state=a8ab64ee-4296-4048-89e8-777bbf1f39b7#/profile

with #/profile or #mylink at the end, I am not sure if this is intended.

Should I try to use something like $location to change the params or maybe change something with keycloak.


回答1:


Try with (responseMode: 'query'):

keycloak.init(onLoad: 'login-required', responseMode: 'query').success(->
.....
)

more info here



来源:https://stackoverflow.com/questions/31346977/angularjs-with-keycloak-auth-keeps-adding-the-same-params-to-url-after-refresh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!