我有一个ASP.NET Web窗体应用程序和ADFS正确实现。
我在许多应用程序中成功使用ADFS进行SSO,但现在我需要使用ADFS存储库来验证本地登录凭据,而不是登录本身。
我的应用程序是一个简单的表单,其中包含用于用户名和密码的文本框以及一个登录按钮。一旦用户插入用户名和密码并点击登录,我需要检查ADFS数据是否正确,接收响应并根据执行其他任务。
在我已经实现的SSO中,STS本身显示了登录凭据的弹出窗口,但在这种情况下,我希望我的应用程序能够完成此任务。
任何人都可以告诉我这是否可能并指出我正确的方向?
答案 0 :(得分:1)
您确定要在网络应用中拥有自己的登录表单吗?这听起来不公平,如果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);
此博客条目中复制了此特定代码段: