簡體   English   中英

如何在AD.NET中查詢ADFS存儲庫以進行身份​​驗證

[英]How to query ADFS repository for authentication in ASP.NET

我有一個ASP.NET Web窗體應用程序和正確實現的ADFS。

我已在許多應用程序中成功將ADFS用於SSO,但現在我需要使用ADFS存儲庫僅用於驗證本地登錄憑據,而不用於登錄本身。

我的應用程序是一個簡單的表單,其中包含用於用戶名和密碼的文本框以及一個“登錄”按鈕。 用戶輸入用戶名和密碼並單擊登錄后,我需要使用ADFS檢查數據是否正確,接收響應並基於此執行其他任務。

在SSO中,我已經實現了STS本身,它顯示了登錄憑據的彈出窗口,但是在這種情況下,我希望此任務可以由我的應用程序來完成。

有人會告訴我這是否可行,並指出正確的方向嗎?

您確定要在Web應用程序中擁有自己的登錄表單嗎? 這聽起來不公平,如果ADFS與其他身份提供者進一步聯合,則您的支票可能會錯過這一點。

話雖如此,如果您確實需要這樣做,則應在ADFS配置中啟用usernamemixed終結點終結點,將應用程序配置為依賴方並請求令牌:

string stsEndpoint = "https://WIN-2013.win2008.marz.com/adfs/services/trust/13/usernamemixed";
string relyingPartyUri = "https://www.yourrelyingpartyuri.com";

WSTrustChannelFactory factory = new WSTrustChannelFactory(
new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential),
new EndpointAddress(stsEndpoint));

factory.TrustVersion = TrustVersion.WSTrust13;

// Username and Password here...
factory.Credentials.UserName.UserName = "remote_user01";
factory.Credentials.UserName.Password = "the_password";

RequestSecurityToken rst = new RequestSecurityToken
{
   RequestType = Microsoft.IdentityModel.Protocols.WSTrust.WSTrust13Constants.RequestTypes.Issue,
   AppliesTo = new EndpointAddress(relyingPartyUri),
   KeyType = Microsoft.IdentityModel.Protocols.WSTrust.WSTrust13Constants.KeyTypes.Bearer,
};

IWSTrustChannelContract channel = factory.CreateChannel();

SecurityToken token = channel.Issue(rst);

//if authentication is failed, exception will be thrown. Error is inside the innerexception.
//Console.WriteLine("Token Id: " + token.Id);

此特定代碼段是從此博客條目中復制的:

http://leandrob.com/2012/04/requesting-a-token-from-adfs-2-0-using-ws-trust-with-username-and-password/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM