我正在使用这个 MSAL 库 ( https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-angular ) 进行身份验证。
对于密码重置,我的代码如下:
// app.component.ts
constructor(private authService: MsalService)
{
if (this.forgotPassword()) {
this.navigateToForgotPassword();
} else {
this.authService
.acquireTokenSilent(MsalHelperService.getMsalConfigurationSettingValue('consentScopes'))
.then(token => {
if (this.authService.getUser()) {
this.userService.setLoggedIn(true);
this.navigateToLandingPage();
} else {
this.userService.setLoggedIn(false);
this.login();
}
})
.catch(error => {
this.userService.setLoggedIn(false);
this.login();
});
}
...
}
// Determine if user clicked "Forgot Password"
forgotPassword() {
const storage = this.authService.getCacheStorage();
const authError: string = storage.getItem('msal.login.error') ? storage.getItem('msal.login.error') : null;
if (authError && authError.indexOf('AADB2C90118') > -1) {
return true;
}
return false;
}
navigateToForgotPassword() {
this.authService.authority = this.authService.authority.replace('b2c_1a_signupsignin', 'b2c_1a_passwordreset');
this.authService.loginRedirect(MsalHelperService.getMsalConfigurationSettingValue('consentScopes'));
}
到目前为止,一切正常。
密码重置后,用户被引导回 app.component,然后调用 loginRedirect() 来显示登录表单。
返回到 app.component 时会记录以下错误:
“拒绝在框架中显示‘ https://...signupsignin/ ’,因为它将‘X-Frame-Options’设置为‘拒绝’”。
理想情况下,我想在密码重置后自动登录用户。
请告知这是否可能,或者至少我如何在无需修改 MSAL 库的情况下摆脱上述错误。