背景:
我有一个 angular 7 应用程序。
应用程序使用 Azure Active Directory B2C 和 Msal 进行身份验证
https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-angular
我在 AAD B2C 中创建了 2 个用户流:
两者都有定制的用户界面,
两者都包含指向其他 AAD B2C 流的重定向按钮。
(从注册 -> 登录 | 从登录 -> 注册)
我已经在 angular 中设置了 MSAL 模块,登录流程作为默认权限
例如
MsalModule.forRoot({
...,
authority: <"https://mytenant.b2clogin.com/tfp/mytenant.onmicrosoft.com/B2C_1_Signin">,
...
})
(通知 B2C_1_Signin 流程名称)
这运行良好,用户可以登录和注册(在流内的流之间导航并进行身份验证)。
问题:
当我尝试手动更改 MSAL 模块权限时出现问题
(当应用程序启动时,它在 MSAL init 中定义为 B2C_1_Signin 流)。
例子:
用户进入欢迎页面并可以单击登录/注册。
如果用户单击登录,则一切正常,因为权限链接在开始时定义为登录流程 ( B2C_1_Signin )。
如果用户想注册,
我需要更改权限链接
到选定的 AAD 流( B2C_1_Signup )然后我调用 MSAL loginRedirect(),用户重定向到正确的 AAD 流,输入他的详细信息并重定向回应用程序。
然后应用程序将启动一个新的登录流程并重定向到登录流程 好像用户未通过身份验证 .
这仅在我手动更改权限链接时发生(为了导航到正确的流程,我别无选择)。
否则,一切都按预期工作。
我应该如何更改权限,使应用程序不会失败用户身份验证?
手动将权限更改为登录流程,同样的错误(如预期)。
https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/498
https://medium.com/@sambowenhughes/configuring-your-angular-6-application-to-use-microsoft-b2c-authentication-99a9ff1403b3
还有很多...
用于角度设置的 MSAL:
“authentication.module.ts”
MsalModule.forRoot({
clientID: "<my-client-id>",
authority: "https://tenant.b2clogin.com/tfp/tenant.onmicrosoft.com/B2C_1_Signin",
redirectUri: "http://localhost:4200/dashboard",
/* default is true */
validateAuthority: false,
/* Defaults is 'sessionStorage' */
cacheLocation : "localStorage",
/* Defaults is 'redirectUri */
postLogoutRedirectUri: "http://localhost:4200/",
/* Ability to turn off default navigation to start page after login. Default is true. */
navigateToLoginRequestUrl : false,
/* Show login popup or redirect. Default:Redirect */
popUp: false,
})
AuthService 包装 MSAL 身份验证服务:
“auth.service.ts”
constructor(private msalService: MsalService) {}
public login(scopes: string[] = null, queryParams: string = null): void {
this.msalService.authority = this.tenantConfig.baseURL + "/" + this.tenantConfig.tenant + "/" + this.tenantConfig.signInPolicy;
this.msalService.loginRedirect(scopes, queryParams);
}
public signup(scopes: string[] = null, queryParams: string = null): void {
this.msalService.authority = this.tenantConfig.baseURL + "/" + this.tenantConfig.tenant + "/" + this.tenantConfig.signUpPolicy;
this.msalService.loginRedirect(scopes, queryParams);
}
我希望 Msal 模块能像往常一样工作,即使我更改了初始定义的权限。
最佳答案
您是否尝试过针对 MSAL GitHub 库提交问题? MSAL.JS 的问题部分可以在这里找到:https://github.com/AzureAD/microsoft-authentication-library-for-js/issues
根据此处的问题,尝试在运行时更改权限实际上存在一个持续的问题:https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/784
由于它不完全相同,我建议提交一个新的 github 问题。但是,目前看来这不是受支持的功能。
关于angular7 - 如何在运行时更改 msal 权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56173067/