微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。