Last active
August 29, 2015 13:57
-
-
Save AlexanderBrevig/9806518 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.IdentityModel.Protocols.WSTrust; | |
using Microsoft.IdentityModel.Protocols.WSTrust.Bindings; | |
using System.ServiceModel; | |
using System.ServiceModel.Security; | |
using System.IdentityModel.Tokens; | |
string stsEndpoint = "https://YOURURL.com/adfs/services/trust/13/usernamemixed"; | |
string relyingPartyUri = "https://attensi.com"; | |
WSTrustChannelFactory factory = new WSTrustChannelFactory( | |
new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential), | |
new EndpointAddress(stsEndpoint) | |
); | |
factory.TrustVersion = TrustVersion.WSTrust13; | |
factory.Credentials.UserName.UserName = "pwcusername"; | |
factory.Credentials.UserName.Password = "pwcpassword"; | |
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(); | |
try { | |
SecurityToken token = channel.Issue(rst); | |
Console.WriteLine("Token Id: " + token.Id); | |
catch (Exception e){ | |
//if authentication is failed, exception will be thrown. Error is inside the innerexception. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment