我在 localhost 中运行的 vanilla js 应用程序中使用 Azure MSAL 库,并且在使用 Twitter 的登录流程中遇到了问题。
我正在使用这种loginPopup()
方法,它似乎工作正常。当我选择使用 Twitter 登录时,它会询问我的凭据,如果我输入正确,弹出窗口会关闭并且登录有效。
问题是当我输入错误的凭据时
它将我(在弹出窗口内)重定向到另一个 Twitter 页面
然后,如果我输入正确的凭据,我会在弹出窗口内重定向到我的页面,并且它不会自行关闭。在原始页面上,我没有登录。
这是错误重定向后生成的 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}`);
});
}