I have to integrate my AngularJS SPA with Azure AD. There is a sample app for this (https://github.com/Azure-Samples/active-directory-angularjs-singlepageapp). That sample is working fine and i have no problem logging in using that sample application.
But the sample is using some very old versions of jquery (1.11.1) and angular (1.2.25). I use jquery 3.1.1 and angular 1.6.4.
When I use those version together with the sample app i cannot login.
I am being redirect to login.microsoftonline.com which reply with a 302 authorize respond with a very long querystring and the page is stuck there, meaning is stays with that long url in the browser address bar.
If i change the scripts to the old version, refresh the page and try again i am logged in.
And i am not logged in.
Any ideas on how to get this to work?
Here is my controller
"use strict";
angular.module("todoApp", ["ngRoute","AdalAngular"])
.config(["$routeProvider", "$httpProvider", "adalAuthenticationServiceProvider", function ($routeProvider, $httpProvider, adalProvider) {
$routeProvider.when("/Home", {
controller: "homeCtrl",
templateUrl: "/App/Views/Home.html"
}).when("/TodoList", {
controller: "todoListCtrl",
templateUrl: "/App/Views/TodoList.html",
requireADLogin: true
}).when("/UserData", {
controller: "userDataCtrl",
templateUrl: "/App/Views/UserData.html"
}).otherwise({ redirectTo: "/Home" });
adalProvider.init(
{
instance: "https://login.microsoftonline.com/",
tenant: "",
clientId: "",
extraQueryParameter: "nux=1",
//cacheLocation: 'localStorage', // enable this for IE, as sessionStorage does not work for localhost.
},
$httpProvider
);
}]);
Please follow the suggestion mentioned by tomidix, it fix this issue. Here is the code for your reference:
app.js
'use strict';
angular.module('todoApp', ['ngRoute','AdalAngular'])
.config(['$routeProvider', '$httpProvider', 'adalAuthenticationServiceProvider', '$locationProvider', function ($routeProvider, $httpProvider, adalProvider, $locationProvider) {
$routeProvider.when("/Home", {
controller: "homeCtrl",
templateUrl: "/App/Views/Home.html",
}).when("/TodoList", {
controller: "todoListCtrl",
templateUrl: "/App/Views/TodoList.html",
requireADLogin: true,
}).when("/UserData", {
controller: "userDataCtrl",
templateUrl: "/App/Views/UserData.html",
}).otherwise({ redirectTo: "/Home" });
adalProvider.init(
{
instance: 'https://login.microsoftonline.com/',
tenant: 'xxxx.onmicrosoft.com',
clientId: '',
extraQueryParameter: 'nux=1',
//cacheLocation: 'localStorage', // enable this for IE, as sessionStorage does not work for localhost.
},
$httpProvider
);
$locationProvider.html5Mode(false).hashPrefix('');
}]);