简体   繁体   English

在本地和Azure上使用Active Directory进行身份验证

[英]Using Active Directory for Authentication locally and on Azure

I'm developing an application for my company's internal use. 我正在开发供公司内部使用的应用程序。 We wish the application to live on Azure and to utilize windows accounts for authentication. 我们希望该应用程序能够在Azure上运行并利用Windows帐户进行身份验证。 We are working on enabling Active Directory Federation Servers (ADFS) in order to synchronize our organizational AD to Azure AD. 我们正在努力启用Active Directory联合身份验证服务器(ADFS),以将我们的组织AD同步到Azure AD。 While that is being done, I am working on code responsible for determining who a user is. 在此过程中,我正在编写负责确定用户身份的代码。 My main goal is to restrict the Admin controller to those users who belong to an active directory group. 我的主要目标是将Admin控制器限制为属于活动目录组的那些用户。 My impression is that ADFS should allow me to query this in Azure. 我的印象是ADFS应该允许我在Azure中进行查询。

I have created a service that utilizes LDAP to determine whether or not the current user is in a particular group, and it works great locally. 我创建了一项服务,该服务利用LDAP确定当前用户是否在特定组中,并且在本地运行良好。 However, through some reading, I've determined that LDAP is not supported by Azure AD. 但是,通过阅读,我确定Azure AD不支持LDAP。 Darn! 该死!

The preferred route to communicate with the Azure AD seems to be the Graph API . 与Azure AD通信的首选途径似乎是Graph API However, the graph API does not seem to be support by an enterprise/organizational AD. 但是,图API似乎不受企业/组织AD的支持。

My first thought solve this is to utilize dependency inject to switch the service being used based on the environment, but I'm thinking there has to be a better way. 我第一个想到的解决方案是利用依赖注入来根据环境切换正在使用的服务,但是我认为必须有一种更好的方法。

What technology should I be using to interact with both on-premise Active Directory, as well as Azure Active Directory? 我应该使用什么技术与本地Active Directory以及Azure Active Directory进行交互?

We faced this same issue in our Azure implementation and discussed it at length with Microsoft. 我们在Azure实施中遇到了相同的问题,并与Microsoft进行了详细讨论。 Currently there is no common method for directory queries. 当前,没有用于目录查询的通用方法。 I believe Microsoft's plan is to eventually add GraphAPI to AD DS. 我相信微软的计划是最终将GraphAPI添加到AD DS。

Another option, if you're using a claims-based authentication protocol like OpenID Connect, is to have the Identity Provider issue claims with the values needed for your authorization logic. 如果您使用的是基于声明的身份验证协议(如OpenID Connect),则另一种选择是让身份提供者发出具有您的授权逻辑所需值的声明。

ADFS is a tool for identity federation and not directory sync. ADFS是用于身份联合而不是目录同步的工具。 For directory sync you would use AADSync - http://www.microsoft.com/en-us/download/details.aspx?id=44225 对于目录同步,您可以使用AADSync- http://www.microsoft.com/zh-cn/download/details.aspx?id= 44225

The simplest way to achieve this is to use federation with ADFS and have ADFS populate the assertion with Role information. 实现此目的的最简单方法是将联合身份验证与ADFS一起使用,并使ADFS使用角色信息填充断言。 Set up a new relying party in ADFS and add the a new Issuance Transform Rule 在ADFS中设置新的依赖方并添加新的发行转换规则

 Template: Send Group Membership as a claim Name: Admin claim Users Group: Choose your domain local group Outgoing claim type: Role Value: MyAdminRole 

You can set up the federation very easily with Visual Studio 2012 or later or add an OWIN startup class such as the following: 您可以使用Visual Studio 2012或更高版本非常容易地设置联盟,也可以添加如下OWIN启动类:

    public void ConfigureAuth(IAppBuilder app)
    {
        app.UseCookieAuthentication(new CookieAuthenticationOptions());
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
        app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions()
        {
            MetadataAddress = "https://adfs.domain.com/federationmetadata/2007-06/federationmetadata.xml",
            Wtrealm = "urn:appid"
            // SignInAsAuthenticationType = // This is picked up automatically from the default set above
        });

        AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;

    }

Then all you need to do is add the Authorise attribute to your controllers: 然后,您需要做的就是将Authorize属性添加到控制器中:

[Authorize(Roles = "MyAdminRole")]
public class AdminController : Controller
{
 ...
}

For completeness, I will also add that once AADSync is configured and running, you can also use Graph API to obtain information about your users once it has been synced to Azure AD. 为了完整起见,我还将补充一点,即配置并运行AADSync之后,一旦将其同步到Azure AD,您还可以使用Graph API获取有关用户的信息。 User and Group updates can be delayed by upto 3 hours though. 不过,用户和组的更新最多可延迟3个小时。

HTH 高温超导

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

相关问题 使用Azure Active Directory进行身份验证的Web应用 - Web app using Azure active directory for Authentication 使用Azure Active Directory进行部分身份验证 - Partial Authentication with Azure Active Directory Asp.net Identity使用密码和Azure Active Directory身份验证 - Asp.net Identity using password and Azure Active Directory authentication Azure Active Directory组织身份验证机制 - Azure Active Directory Organizational Authentication Mechasnim 将参数传递给 Azure Active Directory 身份验证 - Passing parameters to Azure Active Directory authentication 使用Windows身份验证和活动目录组作为角色 - using windows authentication with active directory groups as roles 开发环境的 Microsoft Azure Active Directory 身份验证登录 URL - Microsoft Azure Active Directory Authentication login URL for Dev environment Azure AD的Active Directory身份验证例外(AADSTS90027) - Active Directory Authentication Exception (AADSTS90027) with Azure AD Azure Active Directory -.Net Core 3 Web 应用程序 - 禁用 2 因素身份验证 - Azure Active Directory - .Net Core 3 Web Application - Disable 2 Factor Authentication 在测试环境中通过 Azure Active Directory 执行身份验证过程时出错 - Error when performing the authentication process by Azure Active Directory in test environment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM