繁体   English   中英

Azure AD 多租户应用程序 - 检查用户是否有权使用我的应用程序

[英]Azure AD multitenant app - check if user is authorized to use my app

我开发了一个 web 站点,该站点使用 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);
    }

还是有更好的方法来做到这一点? 如果这是通往 go 的方式,如果不允许用户进入我的应用程序,我将如何处理它,我是否应该以某种方式中止登录过程并重定向到错误页面?

是的,这是正确的方法,如果我必须中止登录过程,我会抛出一个 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

暂无
暂无

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

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