adal idtoken没有反映在Session Storage中

时间:2017-05-13 10:06:30

标签: angularjs azure adal adal.js

我正在使用link

中提供的adal.angular lib

我的app.js看起来像这样

app.ui = angular.module("app.ui", ["ui.router", "ngCookies", "app.global", "app.business", "ngSanitize", "AdalAngular"]), 
app.ui.config(["$stateProvider", "$urlRouterProvider", "$controllerProvider", "$provide", "$compileProvider", "$filterProvider", "$httpProvider", "adalAuthenticationServiceProvider", 
function(a, b, c, d, e, f, $httpProvider, adalProvider) {
    try {
        var g = props.config;

        console.log(location.href);

        if (app.ui.register = {
                controller: c.register,
                directive: e.directive,
                filter: f.register,
                factory: d.factory,
                service: d.service,
                value: d.value
            }, g.routes) {


            var endpoints = {};
            adalProvider.init(
                {
                    tenant: "tenent",
                    clientId: "clientId",
                    redirectUri: "https://localhost:8443/#/login",
                    endpoints: endpoints  
                },
                    $httpProvider   // pass http provider to inject request interceptor to attach tokens
                );


            var h = null,
                i = {
                    js: [],
                    css: []
                };
            h = g.routes, angular.forEach(h, function(b) {
                var c = b.route,
                    d = b.controller,
                    e = b.templateUrl,
                    f = b.title;
                i = {
                    js: [],
                    css: []
                }, b.dependency && (b.dependency.js && (Array.isArray(b.dependency.js) ? angular.forEach(b.dependency.js, function(a) {
                    i.js.push(a)
                }) : i.js.push(b.dependency.js)), b.dependency.css && (Array.isArray(b.dependency.css) ? angular.forEach(b.dependency.css, function(a) {
                    i.css.push(a)
                }) : i.css.push(b.dependency.css))), a.state(b.state, {
                    url: c,
                    controller: d,
                    templateUrl: e,
                    title: f,
                    dependency: i,
                    resolve: dependencyLoader()
                })
            }), 
            b.otherwise(g.defaultRoute), 
            window.location.hash && (window.location.hash = g.defaultRoute);
        }

        console.log(window.location.hash);

    } catch (j) {
        console.log(j);
    }
}]);

我的defaultRoute是Login Controller,控制器js看起来像这样。

app.ui.register.controller("loginController", ["$scope", "adalAuthenticationService", a])
    function a($scope, adalAuthenticationService) {
       $scope.submit = function() {
         adalAuthenticationService.login();
      }
   }

我可以看到点击“提交”按钮时的网址获取了我的用户名和密码,然后返回https://localhost:8443,其URI为https://localhost:8443/#id_token=asdasdasdasdasd.asdasd.asdasdasdasd&state=asdasdqweasdadasdasdqw&session_state=234234asdasdas-asds-qwda-asd2-asdase234fasd

但我在会话存储中看不到id_token。

列出了此URL返回本地主机后我在会话存储中看到的所有内容
Key        - Value
adal.error - '',
adal.error.description - '',
adal.login.error - '',
adal.login.request - https://localhost:8443/#/login,
adal.nonce.idtoken - asdasd23-asd2-as34-asd2-asd23423qsdas,
adal.state.login - 123asdasd-asd2-asd2-as22-asd123dfasd,

我不确定我做错了什么,而不是在我的会话存储中保存adal.idtoken。

1 个答案:

答案 0 :(得分:0)

请参阅此代码示例:https://azure.microsoft.com/en-us/resources/samples/active-directory-angularjs-singlepageapp/,这对我有用,您的浏览器是什么,sessionStorage对IE中的localhost不起作用。