实现联合身份验证

适用于:yes-img-132013 yes-img-162016 yes-img-192019 yes-img-seSubscription Edition no-img-sopSharePoint in Microsoft 365

在 SharePoint Server 中实现联合身份验证

本分步指南介绍如何在 SharePoint 中使用 Active Directory 联合身份验证服务 (AD FS) 配置联合身份验证。

联合身份验证概述

在联合身份验证中,SharePoint 处理由受信任的外部安全令牌服务 (STS) 颁发的 SAML 令牌。 尝试登录的用户将重定向到该 STS,该 STS 对用户进行身份验证并在身份验证成功后生成 SAML 令牌。 然后,SharePoint 会处理此令牌,并使用它来创建自己的令牌并授权用户访问该网站。

先决条件

若要执行配置,需要以下资源:

  • SharePoint 2013 场或更高版本。
  • 已创建的 AD FS 场版本 2 或更高版本,并在 .cer 文件中导出了 AD FS 签名证书的公钥。

本文使用以下值:

  • SharePoint 网站 URL: https://spsites.contoso.local/
  • AD FS 站点 URL: https://adfs.contoso.local/adfs/ls/
  • 领域 (信赖方标识符) : urn:contoso:spsites
  • 标识声明类型: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
  • 角色声明类型: http://schemas.microsoft.com/ws/2008/06/identity/claims/role
  • Windows 网站集管理员: contoso\yvand
  • 联合 (AD FS) 网站集管理员的电子邮件值: yvand@contoso.local

在 AD FS 中创建信赖方

在此步骤中,将在 AD FS 中创建信赖方。 信赖方将存储使用 SharePoint 所需的配置,以及定义身份验证成功后将在 SAML 令牌中注入哪些声明的声明规则。

在 AD FS 服务器上,启动 PowerShell 并运行以下脚本:

### STEP 1: Create the relying party
# Name of the Relying Party
$name = "SPSites"
# Unique identifier of the Relying Party (in SharePoint it's referred to as the realm)
$identifier = "urn:contoso:spsites"
# Authority that authenticates users
$identityProvider = "Active Directory"
# SharePoint URL where user is redirected upon successful authentication
$redirectURL = "https://spsites.contoso.local/_trust/default.aspx"
# Allow everyone to use this relying party
$allowEveryoneRule = '=> issue (Type = "http://schemas.microsoft.com/authorization/claims/permit", value = "true");'
# Create the Relying Party
Add-ADFSRelyingPartyTrust -Name $name -Identifier $identifier -ClaimsProviderName $identityProvider -Enabled $true -WSFedEndpoint $redirectURL -IssuanceAuthorizationRules $allowEveryoneRule -Confirm:$false

### STEP 2: Add claim rules to the relying party
# Rule below configured relying party to issue 2 claims in the SAML token: email and role
$claimsRule = @"
@RuleTemplate = "LdapClaims"
@RuleName = "AD"
c:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname", Issuer == "AD AUTHORITY"]
=> issue(
store = "Active Directory", 
types = ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress", "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"), 
query = ";mail,tokenGroups(fullDomainQualifiedName);{0}", 
param = c.Value);
"@
# Apply the rule to the Relying Party
Set-ADFSRelyingPartyTrust -TargetName $name -IssuanceTransformRules $claimsRule

脚本完成后,AD FS 中的信赖方应如下所示:

ADFS 信赖方

将 SharePoint 配置为信任 AD FS

在此步骤中,将创建一个 SPTrustedLoginProvider,用于存储 SharePoint 信任 AD FS 所需的配置。 启动 SharePoint 命令行管理程序 并运行以下脚本来创建它:

# Define claim types
$email = New-SPClaimTypeMapping "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" -IncomingClaimTypeDisplayName "EmailAddress" -SameAsIncoming
$role = New-SPClaimTypeMapping "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" -IncomingClaimTypeDisplayName "Role" -SameAsIncoming

# Public key of the AD FS signing certificate
$signingCert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\Data\Claims\ADFS Signing.cer")
# Unique realm (corresponds to the unique identifier of the AD FS Relying Party)
$realm = "urn:contoso:spsites"
# Set the AD FS URL where users are redirected to authenticate
$signinurl = "https://adfs.contoso.local/adfs/ls/"

# Create a new SPTrustedIdentityTokenIssuer in SharePoint
New-SPTrustedIdentityTokenIssuer -Name "Contoso.local" -Description "Contoso.local" -Realm $realm -ImportTrustCertificate $signingCert -ClaimsMappings $email,$role -SignInUrl $signinurl -IdentifierClaim $email.InputClaimType

重要

请勿将选项 -UseDefaultConfiguration 与 cmdlet New-SPTrustedIdentityTokenIssuer 一起使用。 此选项会导致意外的副作用,因为它在内部设置用户标识。

然后,必须将相关证书添加到 SharePoint 根颁发机构证书存储。 有 2 种可能的选项:

  • 如果 AD FS 签名证书由证书颁发机构颁发, (出于安全原因的最佳做法)

必须将颁发者证书的公钥 (和所有中间) 添加到存储:启动 SharePoint 命令行管理程序 并运行以下脚本进行添加:

$rootCert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\Data\Claims\ADFS Signing issuer.cer")
New-SPTrustedRootAuthority -Name "adfs.contoso.local signing root authority" -Certificate $rootCert
  • 如果 ADFS 签名证书是自签名证书, (出于安全原因不建议使用)

必须将 ADFS 签名证书本身的公钥添加到存储:启动 SharePoint 命令行管理程序 并运行以下脚本来添加它:

$rootCert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\Data\Claims\ADFS Signing.cer")
New-SPTrustedRootAuthority -Name "adfs.contoso.local signing certificate" -Certificate $rootCert

配置 SharePoint Web 应用程序

在此步骤中,将使用上面创建的 SPTrustedLoginProvider 将 SharePoint 中的 Web 应用程序配置为与 AD FS 信任联合。

有一些重要的规则需要遵守:

  • SharePoint Web 应用程序的默认区域必须启用 Windows 身份验证。 这是搜索爬网程序所必需的。
  • 必须使用 HTTPS 配置将使用 AD FS 联合身份验证的 SharePoint URL。

有两种可能的配置:

  • 如果创建新的 Web 应用程序并在默认区域中同时使用 Windows 和 AD FS 身份验证:

    1. 启动 SharePoint 命令行管理程序 并运行以下脚本:

      # This script creates a new web application and sets Windows and AD FS authentication on the Default zone
      # URL of the SharePoint site federated with ADFS
      $trustedSharePointSiteUrl = "https://spsites.contoso.local/"
      $applicationPoolManagedAccount = "Contoso\spapppool"
      
      $winAp = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication -DisableKerberos:$true
      $sptrust = Get-SPTrustedIdentityTokenIssuer "Contoso.local"
      $trustedAp = New-SPAuthenticationProvider -TrustedIdentityTokenIssuer $sptrust
      
      New-SPWebApplication -Name "SharePoint - ADFS on contoso.local" -Port 443 -SecureSocketsLayer -URL $trustedSharePointSiteUrl -ApplicationPool "SharePoint - ADFS on contoso.local" -ApplicationPoolAccount (Get-SPManagedAccount $applicationPoolManagedAccount) -AuthenticationProvider $winAp, $trustedAp
      
    2. 打开 SharePoint 管理中心 网站。

    3. “系统设置”下,选择“ 配置备用访问映射”。 此时会打开 “备用访问映射集合 ”框。

    4. 使用新的 Web 应用程序筛选显示,并确认看到如下所示的内容:

      Web 应用程序的备用访问映射

  • 如果扩展现有 Web 应用程序以在新区域上设置 AD FS 身份验证:

    1. 启动 SharePoint 命令行管理程序并运行以下脚本:

      # This script extends an existing web application to set AD FS authentication on a new zone
      # URL of the default zone of the web application
      $webAppDefaultZoneUrl = "http://spsites/"
      # URL of the SharePoint site federated with ADFS
      $trustedSharePointSiteUrl = "https://spsites.contoso.local/"
      
      $sptrust = Get-SPTrustedIdentityTokenIssuer "Contoso.local"
      $ap = New-SPAuthenticationProvider -TrustedIdentityTokenIssuer $sptrust
      $wa = Get-SPWebApplication $webAppDefaultZoneUrl
      New-SPWebApplicationExtension -Name "SharePoint - ADFS on contoso.local" -Identity $wa -SecureSocketsLayer -Zone Intranet -Url $trustedSharePointSiteUrl -AuthenticationProvider $ap
      
    2. 打开 SharePoint 管理中心 网站。

    3. “系统设置”下,选择“ 配置备用访问映射”。 此时会打开 “备用访问映射集合 ”框。

    4. 使用已扩展的 Web 应用程序筛选显示,并确认看到如下所示的内容:

      扩展应用程序的备用访问映射

在 IIS 中设置 HTTPS 证书

由于 SharePoint URL 使用 HTTPS 协议 (https://spsites.contoso.local/) ,因此必须在相应的 Internet Information Services (IIS) 网站上设置证书。

生成站点证书

注意

如果已生成证书,则可以跳过此步骤。

  1. 打开 Windows PowerShell 控制台。

  2. 运行以下脚本以生成自签名证书并将其添加到计算机的 MY 存储中:

    New-SelfSignedCertificate -DnsName "spsites.contoso.local" -CertStoreLocation "cert:\LocalMachine\My"
    

重要

自签名证书仅适用于测试目的。 在生产环境中,强烈建议改用证书颁发机构颁发的证书。

设置证书

  1. 打开 Internet Information Services Manager 控制台。

  2. 在树视图中展开服务器,展开 “网站”,在 contoso.local 网站上选择“SharePoint - ADFS ”,然后选择“ 绑定”。

  3. 选择 “https 绑定 ”,然后选择“ 编辑”。

  4. 在“TLS/SSL 证书”字段中,选择 “spsites.contoso.local 证书”,然后选择“ 确定”。

创建网站集

在此步骤中,你将创建一个包含两个管理员的团队网站集:一个管理员作为 Windows 管理员,一个作为联合 (AD FS) 管理员。

  1. 打开 SharePoint 管理中心 网站。

  2. 在“应用程序管理”下,选择“创建网站集”。 此时会打开 “创建网站集 ”页。

  3. 键入 “标题”、“ Url”,然后选择模板 “工作组网站”。

  4. “主网站集管理员 ”部分中,单击书籍图标以打开人员选取器对话框。

  5. 在“人员选取器”对话框中,键入 Windows 管理员帐户,例如 yvand

  6. 在左侧,单击“ 组织”筛选列表。 应会看到如下所示的输出:

    人员选取器 Windows 管理员

  7. 选择帐户,然后单击“ 确定”。

  8. “辅助网站集管理员 ”部分中,单击书籍图标以打开人员选取器对话框。

  9. 在人员选取器对话框中,键入 AD FS 管理员帐户的 确切 电子邮件值,例如 yvand@contoso.local

  10. 在左侧,单击“ Contoso.local”筛选列表。 应会看到如下所示的输出:

    人员选取器 FS 管理员电子邮件

  11. 选择帐户,然后单击“ 确定”。

  12. 单击“确定”创建网站集。

创建网站集后,你应该能够使用 Windows 或联合网站集管理员帐户登录它。

后续步骤

在联合身份验证中,人员选取器不会验证输入,这可能会导致拼写错误或用户意外选择了错误的声明类型。 可以使用自定义声明提供程序解决此问题;例如 LDAPCP

重要

LDAPCP 不是Microsoft产品,Microsoft支持不支持。 若要在本地 SharePoint 场上下载、安装和配置 LDAPCP,请参阅 LDAPCP 网站。

在 SharePoint Server 订阅版中,本机人员选取器可以使用用户配置文件服务应用程序进行联合身份验证来搜索和解析人员。 了解如何将人员选取器配置为使用联合身份验证