Yahiya Yahiya - 5 months ago 54
AngularJS Question

Adal.js not triggering the authentication

I am trying to integrate adal.js in my application. Below is my Code. Could someon please let me know why the authentication is not triggered.

var app = angular.module('TestWebApp', [
'ngRoute',
'testControllers',
'testServices',
'datatables',
'AdalAngular'


]);

/**
* Configure the Routes
*/
app.config(['$routeProvider', '$httpProvider', 'adalAuthenticationServiceProvider', function ($routeProvider, $httpProvider, adalAuthenticationServiceProvider) {


$routeProvider
// Home
.when("/dashboard", {templateUrl: "partials/package.html", controller: "searchCtrl",requireADLogin: true})
// else 404
.otherwise("/404", {templateUrl: "partials/404.html", controller: "searchCtrl"});

adalAuthenticationServiceProvider.init(
{
tenant: 'test.onmicrosoft.com',
clientId: '23234sf-sdf-------'
},
$httpProvider
);
}]);


And my page url is something link this.

http://localhost:8081/test-ui/#/dashboard

This should go to the Azure login page but its not going.

Answer

Your issue: I think you have an issue with the link. Your link should be like this:http://localhost:8081/test-ui#/dashboard

<a href="#/home">Home</a>
<a href="#/todoList">ToDo List</a>
<a href="#/contactList">Contact List</a>

Adal.Js uses requireADLogin keyword to interrupt the route change event. If you don't see any redirection, it could be related to the routechange event not firing. I suggest to add different routes to your app to verify angular routes first.

General guideline: You can try the sample app first to see if your configurations is working. Sample app:https://github.com/AzureADSamples/SinglePageApp-DotNet

If you have an issue with config, you can follow the steps in the ReadMe file to setup your app config.

If sample app works for your config and your app is having issues, you can see the calls with Fiddler and further debug into adal.js as well. Login redirect event also broadcasts adal:loginRedirect.