Edge中未调用ADAL.js的Login()之后的回调 [英] Callback after Login() of ADAL.js is not called in Edge

查看:62
本文介绍了Edge中未调用ADAL.js的Login()之后的回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ADAL.js (称为Azure Active目录)作为用于验证用户的javascript库.我为此使用了以下代码:

I am using ADAL.js(which calls Azure Active Directory) as javascript library for verifying the user. I am using the following code for this:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.15/js/adal.min.js"></script>
    <script>
        var endpoints = {
            "https://management.core.windows.net": "https://management.core.windows.net"
        };
        var config = {
            clientId: 'e333d3fe-a73a-4476-8121-8a57f9a972ca',
            endpoints: endpoints,
        };
        var authContext = new AuthenticationContext(config);
        authContext.handleWindowCallback();

        function onSuccessLogin(error, token, msg) {

            console.log("Inside Call back");

            if (!!token) {
                console.log("Log-in to Azure successfully done", token);
            }
            else {
                console.log("Error while log-in to Azure", error);
            }

            if (!!authContext._user) {
                console.log("You are connected to Azure ")          
            }
        }

        function login() {
            authContext.popUp = true;
            authContext.callback = onSuccessLogin;
            authContext.login();
           // authContext.handleWindowCallback();
            var user = authContext.getCachedUser();
            console.log(user);
        };

        function logout () {
            authContext.logout();
        };

    </script>
    <input id="Button1" type="button" value="clickme" onclick="clickme()" />
    <input id="Button3" type="button" value="login" onclick="login()" />
    <input id="Button2" type="button" value="logout" onclick="logout()" />

    // These are the text-boxes whose value I want to retain.
    First name:<br>
    <input id=fname" type="text" name="firstname" value="Mickey">
    <br>
    Last name:<br>
    <input id="lname" type="text" name="lastname" value="Mouse">
</body>
</html>

虽然在chrome中一切正常,但是这些代码在Edge中很少有问题:

These are few issue with this code in Edge, although everything is working fine in chrome:

  1. 为什么onSuccessLogin()并不总是在边缘调用?
  2. 为什么登录的弹出窗口总是不显示?
  3. 有时输入凭据后,弹出窗口不会关闭.

推荐答案

对我有用的是:

    在调用AuthenticationContext(config)之前
  • 设置 config.callback popUp = true
  • set the config.callback and popUp=true before calling AuthenticationContext(config)

如果URL不包含#,也不应调用handleWindowCallback().代码应为:如果(authenticationContext.isCallback(window.location.hash)){authenticationContext.handleWindowCallback();

Also you should not call handleWindowCallback() if the URL does not contain a #. The code should be: if (authenticationContext.isCallback(window.location.hash)) { authenticationContext.handleWindowCallback();

我建议您先看看一下,并在以下两种情况下(带有和不带有弹出窗口)改编我在Edge(当然还有Chrome)中测试和工作的以下示例: https://github.com/Azure-Samples/active-directory-dotnet-webapi-onbehalfof-ca/blob/master/TodoListSPA/app.js (配置位于 https://github.com/Azure-Samples/active-directory-dotnet-webapi-onbehalfof-ca/blob/master/TodoListSPA/appconfig.js )

I suggest that you have a look and adapt the following sample I tested and worked in Edge (and of course Chrome) in both cases (with and without popup): https://github.com/Azure-Samples/active-directory-dotnet-webapi-onbehalfof-ca/blob/master/TodoListSPA/app.js (the configuration is in https://github.com/Azure-Samples/active-directory-dotnet-webapi-onbehalfof-ca/blob/master/TodoListSPA/appconfig.js)

这篇关于Edge中未调用ADAL.js的Login()之后的回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆