Callback after Login() of ADAL.js is not called in Edge

一笑奈何 提交于 2021-02-07 19:55:01

问题


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>

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

  1. Why the onSuccessLogin() is not always called on edge?
  2. Why the pop window for log-in is not appearing always?
  3. Sometime after entering the credential the pop won't close.

回答1:


What worked for me is:

  • set the config.callback and popUp=true before calling AuthenticationContext(config)

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();

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)



来源:https://stackoverflow.com/questions/46032410/callback-after-login-of-adal-js-is-not-called-in-edge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!