分享方式:


使用 AD FS 設定 SAML 2.0 提供者

Active Directory 同盟服務 (AD FS) 是一種 SAML 2.0 識別提供者,您可以用它來驗證您的 Power Pages 網站訪客。 您可以使用確認符合 SAML 2.0 規格的其他提供者。

本文說明下列步驟:

重要

AD FS 設定的步驟可能會因 AD FS 伺服器的版本而有所不同。

在 Power Pages 中設定 AD FS

將 AD FS 設定為您網站的身分識別提供者。

  1. 在您的 Power Pages 網站中,選取設定>識別提供者

    如果未出現任何識別提供者,請確認在您的網站的一般驗證設定中,有將外部登入設定為開啟

  2. 選取 + 新提供者

  3. 選取登入提供者底下,選取其他

  4. 通訊協定下,選取 SAML 2.0

  5. 輸入提供者的名稱。

    提供者名稱是使用者在登入頁面上選取識別提供者時,會在按鈕上看到的文字。

  6. 選取下一步

  7. 回覆 URL 底下,選取複製

    不要關閉 Power Pages 瀏覽器索引標籤。您很快就要返回此頁面。

建立 AD FS 信賴憑證者信任

您也可以使用 PowerShell 指令碼來執行這些步驟

  1. 在伺服器管理員中,選取工具,然後選取 AD FS 管理

  2. 展開服務

  3. 在右側面板中,選取新增宣告說明

  4. 輸入下列值:

    • 顯示名稱持續識別項

    • 宣告識別項urn:oasis:names:tc:SAML:2.0:nameid-format:persistent

    • 選取在同盟中繼資料中發行此聲明描述... 選項。

  5. 選取確定

  6. 選取信任關係>信賴憑證者信任

  7. 選取新增信賴憑證者信任

  8. 選取開始

  9. 選取手動輸入關於個信賴憑證者的資料,然後選取下一步

  10. 輸入名稱,例如「https://portal.contoso.com/ 試用」。

  11. 選取下一步

  12. 選取 AD FS 2.0 設定檔,然後選取下一步

  13. 設定憑證頁面上,選取下一步

  14. 選取啟用 SAML 2.0 WebSSO 通訊協定支援。

  15. 信賴當事人 SAML 2.0 SSO 服務 URL 下,輸入您複製的回覆 URL。 AD FS 要求執行 HTTPS 的網站,而非 HTTP。

  16. 選取下一步

  17. 設定識別碼頁面上,輸入您的網站 URL,然後選取新增

    如有需要,您可以為每個額外的信賴憑證者網站新增多個身分識別。 使用者能使用任何可用的身分識別進行驗證。

  18. 選取下一步

  19. 是否要立即設定多重驗證?頁面上,選取我現在不想為這個信賴型信任方信任設定多重驗證設定

  20. 選擇發行授權規則頁面上,選取允許所有使用者存取此信賴憑證者,然後選取下一步

  21. 檢閱並信任資訊,然後選取下一步

  22. 選取關閉

  23. 編輯宣告規則中 ,根據您編輯的信任和您要建立規則的規則,選取下列索引標籤之一:

    • 接受轉換規則
    • 發行轉換規則
    • 發行授權規則
    • 委派授權規則
  24. 選取新增規則

  25. 宣告規則範本清單中,選取轉換連入宣告範本,然後選取下一步

  26. 輸入或選取下列值:

    • 宣告規則名稱轉換 Windows 帳戶名稱為名稱識別碼

    • 連入宣告類型Windows 帳戶名稱

    • 連出宣告類型名稱識別碼

    • 連出名稱識別碼格式持續識別碼

  27. 選擇傳遞所有宣告值

  28. 選取結束,然後選取 OK

完成提供者設定

設定 AD FS 信賴憑證者信任後:

  1. 在 Azure 中建立應用程式註冊

  2. 在 Power Pages 中輸入網站設定

識別提供者起始的登入

AD FS 支援識別提供者起始的單一登入 (SSO) 設定檔 SAML 2.0 規格。 若要讓服務提供程式網站能正確回應識別提供者的 SAML 要求,您必須對該 RelayState 參數進行編碼。

要編碼至 SAML RelayState 參數內的基本字串值必須採用下列格式 ReturnUrl=/content/sub-content/,其中 /content/sub-content/ 是服務提供者網站上作為瀏覽目標的網頁路徑。 您可以指定網站上任何有效頁面的路徑。 字串值經過編碼後,會放入下列格式的容器字串中:RPID=&lt;URL encoded RPID&gt;&RelayState=&lt;URL encoded RelayState&gt;。 這整個字串會再次經過編碼,並新增至下列格式的另一個容器中:<https://adfs.contoso.com/adfs/ls/idpinitiatedsignon.aspx?RelayState=&lt;URL> encoded RPID/RelayState&gt;

例如,假設服務提供者路徑為:/content/sub-content/ 且信賴憑證者識別碼為:https://portal.contoso.com/,請利用下列步驟建構 URL:

  • 編碼值 ReturnUrl=/content/sub-content/ 以取得 ReturnUrl%3D%2Fcontent%2Fsub-content%2F

  • 編碼值 https://portal.contoso.com/ 以取得 https%3A%2F%2Fportal.contoso.com%2F

  • 編碼值 RPID=https%3A%2F%2Fportal.contoso.com%2F&RelayState=ReturnUrl%3D%2Fcontent%2Fsub-content%2F 以取得 RPID%3Dhttps%253A%252F%252Fportal.contoso.com%252F%26RelayState%3DReturnUrl%253D%252Fcontent%252Fsub-content%252F

  • 在前面加上 AD FS 識別提供者起始的 SSO 路徑以得到最終的 URL https://adfs.contoso.com/adfs/ls/idpinitiatedsignon.aspx?RelayState=RPID%3Dhttps%253A%252F%252Fportal.contoso.com%252F%26RelayState%3DReturnUrl%253D%252Fcontent%252Fsub-content%252F

您可以使用來下列 PowerShell 指令碼建構 URL。 將指令碼儲存至名為 Get-IdPInitiatedUrl.ps1 的檔案。


<#
.SYNOPSIS 
Constructs an IdP-initiated SSO URL to access a website page on the service provider.
.PARAMETER path
The path to the website page.
.PARAMETER rpid
The relying party identifier.
.PARAMETER adfsPath
The AD FS IdP initiated SSO page.
.EXAMPLE
PS C:\\> .\\Get-IdPInitiatedUrl.ps1 -path "/content/sub-content/" -rpid "https://portal.contoso.com/" -adfsPath "https://adfs.contoso.com/adfs/ls/idpinitiatedsignon.aspx"
#>
param
(
[parameter(mandatory=$true,position=0)]
$path,
[parameter(mandatory=$true,position=1)]
$rpid,
[parameter(position=2)]
$adfsPath = https://adfs.contoso.com/adfs/ls/idpinitiatedsignon.aspx
)
$state = ReturnUrl=$path
$encodedPath = [uri]::EscapeDataString($state)
$encodedRpid = [uri]::EscapeDataString($rpid)
$encodedPathRpid = [uri]::EscapeDataString("RPID=$encodedRpid&RelayState=$encodedPath")
$idpInitiatedUrl = {0}?RelayState={1} -f $adfsPath, $encodedPathRpid
Write-Output $idpInitiatedUrl

使用 PowerShell 設定 AD FS

您可以透過在 AD FS 伺服器上執行以下 PowerShell 指令碼,無需手動執行在 AD FS 伺服器中新增信賴憑證者的程序。 將指令碼儲存至名為 Add-AdxPortalRelyingPartyTrustForSaml.ps1 的檔案。 指令碼執行完成後,繼續在 Power Pages 中設定網站設定

<# 
.SYNOPSIS
Adds a SAML 2.0 relying party trust entry for a website.
.PARAMETER domain
The domain name of the website.
.EXAMPLE
PS C:\\> .\\Add-AdxPortalRelyingPartyTrustForSaml.ps1 -domain portal.contoso.com
#>
param
(
[parameter(Mandatory=$true,Position=0)]
$domain,
[parameter(Position=1)]
$callbackPath = /signin-saml2
)
$VerbosePreference = Continue
$ErrorActionPreference = Stop
Import-Module adfs
Function Add-CrmRelyingPartyTrust
{
param (
[parameter(Mandatory=$true,Position=0)]
$name
)
$identifier = https://{0}/ -f $name
$samlEndpoint = New-ADFSSamlEndpoint -Binding POST -Protocol SAMLAssertionConsumer -Uri (https://{0}{1} -f $name, $callbackPath)
$identityProviderValue = Get-ADFSProperties | % { $_.Identifier.AbsoluteUri }
$issuanceTransformRules = @'
@RuleTemplate = MapClaims
@RuleName = Transform [!INCLUDE[pn-ms-windows-short](../../../includes/pn-ms-windows-short.md)] Account Name to Name ID claim
c:[Type == "https://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname"]
=> issue(Type = "https://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", Issuer = c.Issuer, OriginalIssuer = c.OriginalIssuer, Value = c.Value, ValueType = c.ValueType, Properties["https://schemas.xmlsoap.org/ws/2005/05/identity/claimproperties/format"] = "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent");
@RuleTemplate = LdapClaims
@RuleName = Send LDAP Claims
c:[Type == "https://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname", Issuer == "AD AUTHORITY"]
=> issue(store = "[!INCLUDE[pn-active-directory](../../../includes/pn-active-directory.md)]", types = ("https://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname", "https://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname", "https://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"), query = ";givenName,sn,mail;{{0}}", param = c.Value);
'@ -f $identityProviderValue
$issuanceAuthorizationRules = @'
@RuleTemplate = AllowAllAuthzRule
=> issue(Type = https://schemas.microsoft.com/authorization/claims/permit, Value = true);
'@
Add-ADFSRelyingPartyTrust -Name $name -Identifier $identifier -SamlEndpoint $samlEndpoint -IssuanceTransformRules $issuanceTransformRules -IssuanceAuthorizationRules $issuanceAuthorizationRules
}
# add the 'Identity Provider' claim description if it is missing
[!INCLUDE[cc-pages-ga-banner](../../../includes/cc-pages-ga-banner.md)]
if (-not (Get-ADFSClaimDescription | ? { $_.Name -eq Persistent Identifier })) {
Add-ADFSClaimDescription -name "Persistent Identifier" -ClaimType "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" -IsOffered:$true -IsAccepted:$true
}
# add the website relying party trust
[!INCLUDE[cc-pages-ga-banner](../../../includes/cc-pages-ga-banner.md)]
Add-CrmRelyingPartyTrust $domain

另請參閱

設定 SAML 2.0 提供者
使用 Microsoft Entra ID 設定 SAML 2.0 提供者
SAML 2.0 常見問題