Authenticate user by ADFS (Active Directory Federation Service)

天大地大妈咪最大 提交于 2019-11-30 22:24:26

To use Username/Password authentication you can use the

trust/13/UsernameMixed

endpoint of the ADFS 2.0.

This does NOT check if the user exists in the Active Directory!

In code you request the token like this:

WSTrustChannelFactory adfsfactory = new WSTrustChannelFactory(new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential),
                            StsEndpoint);

adfsfactory.TrustVersion = TrustVersion.WSTrust13;

// Username and Password here...
factory.Credentials.UserName.UserName = "domain\username";
factory.Credentials.UserName.Password = "password";

IWSTrustChannelContract channel = adfsfactory.CreateChannel();

// request the token
SecurityToken token = channel.Issue(rst);

Then create the channel factory for your service using your token:

var binding = new WS2007FederationHttpBinding(WSFederationHttpSecurityMode.Message);

var factory = new ChannelFactory<IYourInterface >(binding, "your service address");

factory.ConfigureChannelFactory();

IYourInterface channel = factory.CreateChannelWithIssuedToken(token);

Hope this helps!

The AD FS 2.0 sign-in pages support username/password authentication out of the box. No code or customizations necessary.

As per @Marnix, this is out the box behavior.

However, just to point out:

Authenticating the user is NOT the same as checking whether a particular user exists in Active Directory.

e.g. the user could be locked out. He still exists in AD but will not be able to authenticate.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!