【问题标题】:Azure AD multitenant app - check if user is authorized to use my appAzure AD 多租户应用 - 检查用户是否有权使用我的应用
【发布时间】:2020-07-25 07:13:02
【问题描述】:

我开发了一个使用 asp.net 和 owin 与 Azure AD 集成的网站。我已在 AD 中将该应用程序注册为多租户应用程序,这意味着拥有工作或学校帐户的每个人都可以登录我的应用程序。很好,这就是我想要的,但是在用户通过身份验证后,我需要检查登录用户是否有权使用我的应用程序(他是否注册为用户?他有许可证吗?)推荐什么实现这一点的方法?我是否连接到 openid 连接中间件 SecurityTokenReceived 事件并在那里进行检查?

Notifications = new OpenIdConnectAuthenticationNotifications
            {
                SecurityTokenReceived = OnSececurityTokenReceived
            }

private Task OnSececurityTokenReceived(SecurityTokenReceivedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> context)
    {
        //check if this user is registered as a user of my app and has a valid license?;
        return Task.FromResult(0);
    }

或者有更好的方法吗?如果这是要走的路,如果不允许用户进入我的应用程序,我将如何处理它,我是否应该以某种方式中止登录过程并重定向到错误页面?

【问题讨论】:

    标签: c# asp.net owin openid-connect owin-middleware


    【解决方案1】:

    是的,这是正确的方法,如果我必须中止登录过程,我会抛出一个 throw a:

    System.IdentityModel.Tokens.SecurityTokenValidationException("You are not allow to login to this application");
    

    来源: https://www.microsoftpressstore.com/articles/article.aspx?p=2473126&seqNum=2

    【讨论】:

      猜你喜欢
      • 2017-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-20
      相关资源
      最近更新 更多