使用AAD MSAL登录-登录已经在进行中 [英] Login with AAD MSAL - Login is already in progress

查看:468
本文介绍了使用AAD MSAL登录-登录已经在进行中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.net网站,该网站使用MSAL登录.

I have a ASP.net website, that uses MSAL to login.

我一直遇到的问题是,无论何时用户登录,然后再次注销,用户都会被重定向到注销页面. 该页面实现new Msal.UserAgentApplication(msalConfig).logout()功能,并将用户重定向回登录页面.

The issue I keep having is that, whenever the user logs in, then logs out again the user is redirected to a logout page. This page implements the new Msal.UserAgentApplication(msalConfig).logout() function, and redirects the user back to the login page.

这一切都很好.然后,登录页面将自动将用户重定向回AAD登录页面.

This all works perfectly. The login page will then automatically redirect the user back to the AAD login page.

如果用户随后决定再次登录,则MyMsalObject.GetAccount()的结果将返回null,并发生错误,提示以下内容:

If the user then decides to login again, the result of MyMsalObject.GetAccount() returns null, and an error occurs that mentions the following:

ClientAuthError:Login_In_Progress:登录呼叫时出错-登录已在进行中.

ClientAuthError: Login_In_Progress: Error during login call - login is already in progress.

起初,我使用了一个js文件来处理登录&注销后,我意识到这可能不是他的最佳解决方案,因为它尝试加载时进行登录.

At first I used one js file to handle log in & logout, I then realised that that probably wasn't he best solution, as it attempted a login on load.

所以我决定将它们分成两个单独的JS文件,但这并不能解决我的问题.

So I decided to split them up into two separate JS files but this hasn't fixed my problem.

msalObject定义:

msalObject definition:

var msalConfig = {
    auth: {
        clientId: "my_client_id",
        authority: "my_authority_url",
        redirectUri: "http://localhost:port"
    },
    cache: {
        cacheLocation: "localStorage",
        storeAuthStateInCookie: true
    }
};

var myMSALObj = new Msal.UserAgentApplication(msalConfig);

登录代码:

$(document).ready(function(){
    if (!myMSALObj.getAccount()) {
            myMSALObj.loginRedirect(msalConfig);
            acquireTokenRedirectAndCallMSGraph();
    }
});

一些额外的细节. 现在,我做到了这一点,以便用户必须先单击一个按钮,然后才能重定向到Microsoft登录.

Some extra details. I've now made it so that users must click on a button before being redirected to Microsoft to login.

不幸的是,上述情况仍然适用.首次成功登录后&注销后,即使尝试二次登录尝试也不会在函数getaccount()中产生值,

The above unfortunately still applies. After logging in succesfully for the first time & logging out, a secondary login attempt will not yield a value in the function getaccount() even though, it works perfectly the first time.

登录后出现的错误仍然相同:

The error I get after I've logged in is still the same namely:

ClientAuthError: Login_In_Progress: Error during login call - login is already in progress.

即使我刚刚登录.

有人可以解决吗?

有一些进展..某种程度上,我已经能够通过更改注销用户的方式来修复上述错误.

There is a little bit of progress.. sort of, I've been able to fix the error above by changing way I log the user out.

现在,配置文件已成为文档就绪&我也将注销功能移到了那里.

The config file is now a definition within document ready & I've moved the log out function in there aswell.

尽管我现在面临着新的挑战.

Although I now face a new challenge..

Refused to display 'https://login.microsoftonline.com/{{}}' in a frame because it set 'X-Frame-Options' to 'deny'.

我不能完全确定这是向前还是向后.复制方案保持不变,您先登录,然后再注销&再次返回,当microsoft将用户发送回登录页面时,我收到此编辑中提到的错误,但第一次登录尝试时却未收到此错误.

And im not entirely sure if this is a step forward or backwards. The reproduction scenario remains the same, you log in, then you log out & back in again, when microsoft sends the user back to the login page I get the error mentioned in this edit, but I don't get this error on the 1st login attempt.

答案如下:

The answer stated on: https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/FAQs#q6-how-to-avoid-page-reloads-when-acquiring-and-renewing-tokens-silently doesn't help at ALL, I'm using chrome but it still doesn't work..

推荐答案

检查会话/本地存储和cookie中是否有任何悬挂的msal信息.我们遇到了同样的问题,我偶然发现了此链接.

Check session/local storage and cookies for any dangling msal information. We had the same problem, and I stumbled into this link.

https://github.com/AzureAD/microsoft -authentication-library-for-js/issues/1069

它建议清除存储和cookie,但如果您使用浏览器工具进行深入研究,则会看到一些条目,例如"msal ... interactive ...".这些将具有进行中"的值,这就是导致错误的原因.

It suggests clearing storage and cookies, but if you dig into using your browser tools, you'll see several entries like "msal...interactive...". Those will have values of "in progress", and that's what is causing the error.

删除这些条目可以解决问题.

Deleting those entries clears up the problem.

这篇关于使用AAD MSAL登录-登录已经在进行中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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