【问题标题】:adal idtoken not reflecting in Session Storageadal idtoken 未反映在会话存储中
【发布时间】:2017-05-16 15:19:45
【问题描述】:

我正在使用 link 中提供的 adal.angular 库

我的 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();
      }
   }

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

但我在会话存储中看不到 id_token。在此 URL 返回到我的本地主机后,我在 Session 存储中看到的所有内容都列在下面。

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 保存在我的会话存储中。

【问题讨论】:

    标签: angularjs azure adal adal.js


    【解决方案1】:

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

    【讨论】:

    • 我使用 Chrome 并设法解决了这个问题,删除了代码 window.location.hash && (window.location.hash = g.defaultRoute);为我工作。感谢您的回复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-03
    • 1970-01-01
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    • 2013-09-11
    相关资源
    最近更新 更多