MSAL.js Twitter 弹出窗口在错误登录尝试后未重定向

问题描述

我在 localhost 中运行的 vanilla js 应用程序中使用 Azure MSAL 库,但我在 Twitter 登录流程中遇到了问题。

我正在使用 loginPopup() 方法,它似乎工作正常。当我选择使用 Twitter 登录时,它会询问我的凭据,如果我输入正确,弹出窗口就会关闭并且登录成功。

问题是当我输入错误的凭据时

First login redirection to Twitter

它将我(在弹出窗口内)重定向到另一个 Twitter 页面

Second redirection inside the popup window

然后,如果我输入正确的凭据,我将被重定向到弹出窗口内的页面,并且它不会自行关闭。而在原始页面上,我没有登录

这是错误重定向生成的 URL,该 URL 停留在弹出窗口中并且不会自行关闭

https://localhost:3001/#state=asdasdasd...&client_info=asdasdasd....&code=asdasdasd...

这是我的 msalConfig

export const msalConfig = {
    auth: {
        clientId: process.env.B2C_CLIENTID,authority: process.env.B2C_AUTHORITY,kNownAuthorities: [process.env.B2C_KNowN_AUTHORITIES],redirectUri: process.env.B2C_REDIRECT_URL
    },cache: {
        cacheLocation: "localStorage",storeAuthStateInCookie: false
    }
};

还有我的登录方式:

constructor() {
        this.account = null;
        this.myMSALObj = new msal.PublicclientApplication(msalConfig);
        this.myMSALObj.handleRedirectPromise()
            .then((resp) => { this.handleResponse(resp); })
            .catch(console.error);
    }
    loginWithTwitter() {
        this.myMSALObj.loginPopup()
            .then(response => {
                utils.setSocialId(response.uniqueId);
                utils.setSocialApplication(Constants.soCIAL_APPLICATION.TWITTER);
                const socialIdentity = {
                    email: response.idTokenClaims.emails[0],name: response.idTokenClaims.name,socialApplication: Constants.soCIAL_APPLICATION.TWITTER,userId: response.uniqueId
                };
                login.loginPlayerWithSocialIdentity(socialIdentity);
            })
            .catch(error => {
                console.log(`Error signing in with Twitter: ${error}`);
            });
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)