Hello All,
After doing some research on this, I followed below steps to implement this successfully.
1) Add your website link as a relying party trust in ADFS. Please refer below guideline for the same.
Step by Step Procedures to add a Relying Party on ADFS 2.0 - SharePoint Pals[
^]
2) Collect below necessary items to pass as a parameter:
i) Relying Party Trust URL (Which URL is set as a reluing party trust in ADFS).
ii) Service token URL (Which will you get from the ADFS. Below code supports /13/usernamemixed token).
3) Use below sample code to connect with ADFS behind the scene:
string relyingPartyId = relyingPartyURL;
string adfsEndpoint = serviceTokenUrl;
WSTrustChannelFactory factory = new WSTrustChannelFactory(
new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential),
new EndpointAddress(adfsEndpoint)
);
factory.TrustVersion = TrustVersion.WSTrust13;
var channelCredentials = factory.Credentials;
channelCredentials.UserName.UserName = userName;
channelCredentials.UserName.Password = password;
channelCredentials.SupportInteractive = false;
RequestSecurityToken rst = new RequestSecurityToken
{
RequestType = Microsoft.IdentityModel.Protocols.WSTrust.WSTrust13Constants.RequestTypes.Issue,
AppliesTo = new EndpointAddress(relyingPartyId),
KeyType = Microsoft.IdentityModel.Protocols.WSTrust.WSTrust13Constants.KeyTypes.Bearer,
};
IWSTrustChannelContract channel = factory.CreateChannel();
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
(se, cert, chain, sslerror) =>
{
return true;
};
SecurityToken token = channel.Issue(rst);
The Token value including the Claim information will be stored in the token object in above example. If the user is not authenticated then the Issue method will throw exception message ("The security token could not be authenticated or authorized.").
Note: There are various chances to get ADFS configuration specific issues.