简体   繁体   English

ASP.net Mvc 5 - 从 azure AD 在 MVC5 web 应用程序中授权的组策略

[英]ASP.net Mvc 5 - Group policy in authorization from azure AD in MVC5 web app

I am working in asp.net MVC 5 application Authenticate with external identity provider Azure AD.我正在使用 asp.net MVC 5 应用程序使用外部身份提供程序 Azure AD 进行身份验证。 I want to create authorization with group members.我想创建与组成员的授权。 How can I add a group policy in my application?如何在我的应用程序中添加组策略? I could found a solution for .net core but not for .net framework.我可以找到 .net 核心的解决方案,但不是 .net 框架的解决方案。

It seems the sample that you want.看起来你想要的样本 This sample shows how to build an MVC web application that uses Azure AD Groups for authorization.此示例显示如何构建使用 Azure AD 组进行授权的 MVC web 应用程序。 But it is the old one, the newer sample is used for ASP.net core.但它是旧的,较新的样品用于 ASP.net 内核。

This is a similar issue about using Azure AD groups & group claims.这是关于使用 Azure AD 组和组声明的类似问题

Allow group policy claims in azure Update manifest file in Azure AD app registraions允许 azure 中的组策略声明 在Azure AD 应用注册中更新清单文件

Use the custom attributes to check claims.使用自定义属性检查声明。

public class ClaimsAuthorize : AuthorizeAttribute {
private string claimType;
private string claimValue;

public ClaimsAuthorize(string claimType, string claimValue)
{
  this.claimType = claimType;
  this.claimValue = claimValue;
}

public ClaimsAuthorize()
{
  claimType = "groups";
  claimValue = ConfigurationManager.AppSettings["GroupObjectId"];
}

public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)
{
  var user = filterContext.HttpContext.User as ClaimsPrincipal;

  if (user.HasClaim(claimType, claimValue))
    base.OnAuthorization(filterContext);
  else
    throw new UnauthorizedAccessException();
}}

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

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