<!DOCTYPE html>
<html ng-app="githubViewer">
<head>
<script data-require="angular.js@1.3.0-beta.5" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
<script data-require="angular-route@1.2.14" data-semver="1.2.14" src="https://code.angularjs.org/1.2.14/angular-route.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-cookies.js"></script>
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.10/js/adal.min.js"></script>
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.10/js/adal-angular.min.js"></script>
<script src="app.js"></script>
<script src="MainController.js"></script>
<script src="UserController.js"></script>
</head>
<body>
<h1>Authentication</h1>
<div ng-view=""></div>
</body>
</html>
// Code goes here
(function(module) {
var MainController = function($scope, $location) {
$location.path("/user/angular");
};
module.controller("MainController", MainController);
}(angular.module("githubViewer")));
<div>
<h3>
Redirecting...
</h3>
<p>{{userInfo.userName}}</p>
<!--<p>aud:{{userInfo.profile.aud}}</p>-->
<!--<p>iss:{{userInfo.profile.iss}}</p>-->
<!--<p>iat:{{userInfo.profile.iat}}</p>-->
<!--<p>nbf:{{userInfo.profile.nbf}}</p>-->
<!--<p>exp:{{userInfo.profile.exp}}</p>-->
<!--<p>ver:{{userInfo.profile.ver}}</p>-->
<!--<p>tid:{{userInfo.profile.tid}}</p>-->
<!--<p>amr:{{userInfo.profile.amr}}</p>-->
<!--<p>oid:{{userInfo.profile.oid}}</p>-->
<!--<p>upn:{{userInfo.profile.upn}}</p>-->
<!--<p>unique_name:{{userInfo.profile.unique_name}}</p>-->
<!--<p>sub:{{userInfo.profile.sub}}</p>-->
<!--<p>family_name:{{userInfo.profile.family_name}}</p>-->
<!--<p>given_name:{{userInfo.profile.given_name}}</p>-->
<!--<p>pwd_exp:{{userInfo.profile.pwd_exp}}</p>-->
<!--<p>pwd_url:{{userInfo.profile.pwd_url}}</p>-->
</div>
//***** This is an angular app/module registering controllers based on routing.
angular.module('githubViewer', ['ngRoute', 'AdalAngular', 'ngCookies'])
.config(['$routeProvider', '$httpProvider', 'adalAuthenticationServiceProvider', function($routeProvider, $httpProvider, adalProvider) {
$routeProvider
.when("/main", {
templateUrl: "main.html",
controller: "MainController",
requireADLogin: true,
})
.when("/user/:username", {
templateUrl: "user.html",
controller: "UserController",
requireADLogin: true,
})
.otherwise({
redirectTo: "/main"
});
adalProvider.init({
tenant: '72f988bf-86f1-41af-91ab-2d7cd011db47',
clientId: '7532e7c8-5556-4207-abbc-94d9e73f32fe',
//cacheLocation: 'localStorage', // enable this for IE, as sessionStorage does not work for localhost.
},
$httpProvider
);
}]);
'use strict';
angular.module('githubViewer')
.controller('UserController', ['$http', '$scope', 'adalAuthenticationService', '$cookies', '$location', function($http, $scope, adalService, $cookies, $location) {
let secret = "igxxObaO7IieMXMG3GPSFtCx4wzoKBQGoNZ4sH5P5oI=";
let clientId = "7532e7c8-5556-4207-abbc-94d9e73f32fe";
let grantType = "client_credentials";
$http({
method: 'POST',
url: 'https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47/oauth2/token?api-version=1.0',
data: "grant_type=" + grantType + "&resource=https://management.core.windows.net/&client_id=" + clientId + "&client_secret=" + secret,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Cache-Control': 'no-cache',
}
}).then(function successCallback(response) {
document.cookie = "azureauth2="+response.data.access_token+"; expires=Thu, 18 Dec 2020 12:00:00 UTC; path=/";
// $location.path("/home");
// $http({
// method: 'GET',
// url: 'https://management.azure.com/subscriptions/a013b98a-6c2a-4f92-a6a7-82266ac6f437/resources?api-version=2015-01-01',
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded',
// 'Cache-Control': 'no-cache',
// 'Authorization': 'Bearer ' + response.data.access_token,
// }
// }).then(function successCallback(response) {
// console.log(response);
// // this callback will be called asynchronously
// // when the response is available
// }, function errorCallback(response) {
// console.log(response);
// // called asynchronously if an error occurs
// // or server returns response with an error status.
// });
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
}]);