2012-11-22 49 views
14

我們有一個用於我們的聯合Active Directory域與Office 365獲取ADFS令牌在PowerShell中

最近我們有一個問題,即集羣停止響應,而這又打破了電子郵件/日曆址的ADFS 2.0環境我們所有的用戶。由於我們目前沒有任何對ADFS的監控,我正在嘗試編寫一個PowerShell腳本,它將定期嘗試對我們的ADFS集羣進行身份驗證,並獲取類似於testexchangeconnectivity.com工作的SSO測試的有效令牌。

看來,令牌實際上是由

/ADFS /服務/信託/ 2005/usernamemixed

發出,但每當我試圖運行對調用-WebRequest的或新的Web網頁代理此URI並提供本地AD憑據,我收到400錯誤請求錯誤。

爲了正確地從此端點請求令牌,我需要做些什麼?

回答

0

本質上,您使用WSTrustChannelFactory創建一個通道並將其傳遞給RequestSecurityToken。

萊昂德羅有一個很好的,簡潔的sample

你需要的,如果你不使用.NET 4.5安裝Windows標識基礎(WIF)。

0

我使用WS-Federation和WS-Trust進行聯合身份驗證的產品。我相信你的情況是我們工作流程的一部分。

多年來,我開發了基於SOAP的API的PowerShell自動化,並且在某些時候我將這些知識整合到了庫中的WcfPS模塊中。

該模塊的code是開源的,雖然它的腳本在很大程度上依賴於來自System.ServiceModelSystem.IdentityModel程序集的.n​​et框架類和程序集。我提到這是因爲這些程序集中的大多數apis不能從.NET標準2中獲得,所以該模塊不幸的將不能用於非Windows操作系統。您還可以在我的帖子WCFPS - PowerShell module to work with SOAP endpoints中閱讀更多內容。

這是一個示例,您可以根據您的服務提供商要求和依賴方配置發佈對稱和承載令牌。該代碼需要對聯合安全流程,設置和術語有基本的瞭解。

# Define the ADFS MEX uri 
$adfsMexUri="https://adfs.example.com/adfs/services/trust/mex" 

#region Define authentication endpoints. One for windows and one with username/password 
$windowsMixed13AuthenticationEndpoint="https://adfs.example.com/adfs/services/trust/13/windowsmixed" 
$usernamePasswordMixed13AuthenticationEndpoint="https://adfs.example.com/adfs/services/trust/13/usernamemixed" 
#endregion 

#region Define service providers for which we want to issue a symmetric and a bearer token respectively 
# Symmatric is for SOAP, WS-Trust 
# Bearer is for Web, WS-Federation 
$soapServiceProviderAppliesTo="https://myserviceprovider/Soap/" 
$webServiceProviderAppliesTo="https://myserviceprovider/Web/" 
#endregion 

# Parse the MEX and locate the service endpoint 
$issuerImporter=New-WcfWsdlImporter -Endpoint $adfsMexUri 

#region Issue tokens with windows authentications 
$issuerEndpoint=$issuerImporter | New-WcfServiceEndpoint -Endpoint $windowsMixed13AuthenticationEndpoint 
$soapToken=New-SecurityToken -Endpoint $issuerEndpoint -AppliesTo $soapServiceProviderAppliesTo -Symmetric 
$webToken=New-SecurityToken -Endpoint $issuerEndpoint -AppliesTo $webServiceProviderAppliesTo -Bearer 
#endregion 

#region Issue tokens with username/password credentials 
$credential=Get-Credential 
$issuerEndpoint=$issuerImporter | New-WcfServiceEndpoint -Endpoint $usernamePasswordMixed13AuthenticationEndpoint 
$soapToken=New-SecurityToken -Endpoint $issuerEndpoint -Credential $credential -AppliesTo $soapServiceProviderAppliesTo -Symmetric 
$webToken=New-SecurityToken -Endpoint $issuerEndpoint -Credential $credential -AppliesTo $webServiceProviderAppliesTo -Bearer  
#endregion