I configured the state which contains url with url parameters like this: url:route/:id1/:id2:id3
with ADAL js. When I hit url with route/1/2/3
, after login, I am redirected to route/:id1/:id2/:id3?id1=1&id2=2&id3=3
instead of route/1/2/3
.
I investigated further and in adal-angular.js file, we are setting browser url with $location.url().search(jsonParameters)
where jsonParameters
is json object with value {id1:1, id2:2, id3:3}
which is causing the url malformation.
Can you guys point me in correct direction on how to solve this issue and redirect to proper url?
Edit: Adding code sample
I have configured the AAD route as specified below:
$stateProvider
.state('State1', {
templateUrl: getViewUrl('viewUrl'),
controller: 'homeController',
controllerAs: 'home',
url: '/route/:id1/:id2/:id3',
requireADLogin: true
})
I am initializing the adal sevice provider in following way:
$locationProvider.html5Mode(false);
var endpoints = {}
endpoints[EnvironmentConfig.url1] = EnvironmentConfig.url1;
endpoints[EnvironmentConfig.url2] = EnvironmentConfig.url2;
adalAuthenticationServiceProvider.init(
{
instance: EnvironmentConfig.aadUrl, // 'https://login.microsoftonline.com/',
tenant: EnvironmentConfig.tenant, // 'microsoft.onmicrosoft.com',
clientId: EnvironmentConfig.clientId,
endpoints: endpoints,
loginResource: EnvironmentConfig.breServiceADUrl
//cacheLocation: 'localStorage', // enable this for IE, as sessionStorage does not work for localhost.
}, $httpProvider);
Thanks.
I read the source code for adal-angular.js and found out that there is an issue when redirecting to the link with url parameters. I have modified code by @Fei Xue little bit to reproduce the scenario.
I have added fix also. Adal-angular uses location.search method to replace the redirected url after successful login. But search method converts stored json object to query parameters which is causing the issue.
You can run below code as is to repro the issue. In incognito browser if we try to go to
http://localhost:8080/hello/1/2/3
and it will redirect us tohttp://localhost:8080/#/hello/:id1/:id2/:id3?id1=1&id2=2&id3=1
which is wrong.I have commented the fix for this issue. After uncommenting the code and it will work as expected and it will correctly redirect us to
http://localhost:8080/hello/1/2/3
The code I tested seems no different with yours, I post the code for your reference. Hope it is helpful:
To test the code, first click the login and than you can switch the view by click the Hello and About hyperlink.
Update
It seems this issue was fixed by the version
1.0.12
of ADAL from #345. I suggest that you upgrade the ADAL to the latest version 1.0.13 to fix this issue.