使用 AD FS 為入口網站設定 SAML 2.0 提供者

注意

自 2022 年 10 月 12 日起,Power Apps 入口網站為 Power Pages。 其他資訊:Microsoft Power Pages 現在已推出 (部落格)
我們很快就會遷移並將 Power Apps 入口網站文件與 Power Pages 文件併合。

重要

Active Directory 同盟服務 (AD FS) 設定的步驟可能會因 AD FS 伺服器的版本而有所不同。

建立 AD FS 信賴憑證者信任

注意

請參閱 使用 PowerShell 設定 AD FS,以取得有關如何在 PowerShell 指令碼中執行這些步驟的資訊。

  1. 使用 AD FS 管理工具,移至服務 > 宣告描述

    1. 選取新增宣告描述

    2. 指定宣告:

      • 顯示名稱:持續識別項

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

      • 啟用核取方塊,用於:在同盟中繼資料中發行此宣告描述做為此同盟服務可接受的宣告類型

      • 啟用核取方塊,用於:在同盟中繼資料中發行此宣告描述做為此同盟服務可傳送的宣告類型

    3. 選取確定

  2. 使用 AD FS 管理工具,選取 信任關係 >信賴憑證者信任

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

    2. 歡迎使用:選取開始

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

    4. 指定顯示名稱:輸入名稱,然後選取下一步。 範例: https://portal.contoso.com/

    5. 選擇設定檔:選取 AD FS 2.0 設定檔,然後選取下一步

    6. 設定憑證:選取下一步

    7. 設定 URL:選取啟用 SAML 2.0 WebSSO 通訊協定支援核取方塊。 信賴憑證者 SAML 2.0 SSO 服務 URL:輸入 https://portal.contoso.com/signin-saml2
      附註 AD FS 要求在 HTTPS 上執行入口網站。

      注意

      產生的端點包含下列設定:

    8. 設定身分識別: 輸入 https://portal.contoso.com/,選取 新增,然後選取 下一步。 若適用,您可以為每個額外的信賴憑證者入口網站新增多個身分識別。 使用者能夠跨任何或所有可用的身分識別進行驗證。

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

    10. 準備新增信任:選取下一步

    11. 選取關閉

  3. 新增名稱識別碼宣告至信賴憑證者信任:

    轉換 Windows 帳戶名稱名稱識別碼宣告 (轉換連入宣告):

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

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

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

    • 傳遞所有宣告值

設定 SAML 2.0 提供者

設定 AD FS 信賴憑證者信任之後,您可以依照步驟設定入口網站的 SAML 2.0 提供者

識別提供者–起始的登入

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 portal page on the service provider.

.PARAMETER path

The path to the portal 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 的檔案。 執行指令碼後,繼續設定入口網站設定。

<# 

.SYNOPSIS

Adds a SAML 2.0 relying party trust entry for a website.

.PARAMETER domain

The domain name of the portal.

.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 portal relying party trust


[!INCLUDE[cc-pages-ga-banner](../../../includes/cc-pages-ga-banner.md)]

Add-CrmRelyingPartyTrust $domain

設定 SAML 2.0 提供者

設定 AD FS 信賴憑證者信任之後,您可以依照步驟 設定入口網站的 SAML 2.0 提供者

另請參閱

使用 Azure AD 為入口網站設定 SAML 2.0 提供者
在入口網站中使用 SAML 2.0 的常見問題
設定入口網站的 SAML 2.0 提供者

注意

是否能請您告知您偏好的慣用文件語言? 請填寫問卷。 (請注意,本問卷為英文版)

完成問卷大約需要七分鐘。 本問卷將不會收集個人資料 (隱私權聲明)。