简体   繁体   English

如何阻止用户登录,直到他们在 Azure B2C 中获得授权

[英]how to stop users logging in until they are authorised in Azure B2C

My Angular 8 (.net core back end api) app is protected by Azure B2C using MSAL library.我的 Angular 8(.net 核心后端 api)应用程序使用 MSAL 库受 Azure B2C 保护。 The user does a sign up and I use Graph API to create this user in B2C and I have a custom attribute isActive which I set to False .用户进行注册,我使用 Graph API 在 B2C 中创建此用户,我有一个自定义属性isActive我设置为False Application admin logs in the app and grants access and the created user can access the app.应用程序管理员登录应用程序并授予访问权限,创建的用户可以访问应用程序。 I want to stop the user to login until they are authorized and allowed access by the admin.我想阻止用户登录,直到他们被管理员授权并允许访问。

My question is how I can block the users from sign in until isActive is set to true?我的问题是如何在isActive设置为 true 之前阻止用户登录? Currently I'm doing it like below in my app component目前我在我的应用程序组件中如下所示

  subscribeToBroadCastServiceOnLogin() {
this.broadcastService.subscribe("msal:loginSuccess", (success) => {     

  if (
    success.idToken.claims[
      "extension_3datttttxxxxxxxxxxxxxxxxxxxxxxxxx_isActive"
    ] !== true
  ) {
    window.alert("Your login is awaiting authorization from site Admin");

    return this.authService.logout();
  }

The problem with this approach is that the user is successfully signed in already and I m logging them out based on the claim.这种方法的问题是用户已经成功登录,我正在根据声明将他们注销。 I m wondering if there is a better approach to meet this requirement?我想知道是否有更好的方法来满足这个要求?

your options are somewhat limited in b2c, in normal azure ad, you would have many options, for example, limiting sign in to the enterprise application pane, or disabling user sign in for that user altogether.您的选项在 b2c 中有些受限,在普通的 azure 广告中,您将有许多选项,例如,限制登录到企业应用程序窗格,或完全禁用该用户的用户登录。

However in b2c, you do not have option 1, and option 2 is only for local accounts.但是在 b2c 中,您没有选项 1,选项 2 仅适用于本地帐户。 that means any accounts created with social emails.. gmail,etc, you cannot disable sign in.这意味着使用社交电子邮件创建的任何帐户.. gmail 等,您不能禁用登录。

So other than what you're doing currently, the only other solution would be to build an invitation flow or equivalent, which basically prevents signup until admin approves.因此,除了您目前正在做的事情之外,唯一的其他解决方案是构建邀请流程或等效流程,这基本上会阻止注册,直到管理员批准。 so you could build something that would call an invitation signup process like here: https://github.com/azure-ad-b2c/samples/tree/master/policies/invite that way the user won't be created until you send the invite.因此您可以构建一些可以调用邀请注册过程的东西,如下所示: https://github.com/azure-ad-b2c/samples/tree/master/policies/invite这样在您发送之前不会创建用户邀请。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM