gpt4 book ai didi

javascript - MSAL Angular 7 : Password Reset Implementation

转载 作者:行者123 更新时间:2023-12-04 12:52:37 29 4
gpt4 key购买 nike

我正在使用此 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’设置为‘deny’”。

理想情况下,我希望用户在密码重置后自动登录。

请告知这是否完全可行,或者至少告诉我如何在不修改 MSAL 库的情况下消除上述错误。

最佳答案

我根据你的回答做了类似的事情:

if (payload._errorDesc && payload._errorDesc.indexOf('AADB2C90118') !== -1) {
console.log('Set recovery flow to true');
console.log('Redirecting to password recovery page');
localStorage.setItem('custom.recovery.password.flow', 'true');
msalService.authority = `https://login.microsoftonline.com/tfp/${environment.tenant}/b2c_1_reset_password/v2.0/`;
msalService.loginRedirect();
}
});
this.broadcastService.subscribe('msal:loginSuccess', payload => {
if(localStorage.getItem('custom.recovery.password.flow') === 'true'){
console.log('Set recovery to false');
console.log('Redirecting to login page');
localStorage.setItem('custom.recovery.password.flow', 'false');
msalService.logout();
}
});

关于javascript - MSAL Angular 7 : Password Reset Implementation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54285749/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com