Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. using System;
  2. using System.IdentityModel.Claims;
  3. using System.IdentityModel.Protocols.WSTrust;
  4. using System.IdentityModel.Tokens;
  5. using System.ServiceModel;
  6. using System.ServiceModel.Security;
  7.  
  8. namespace WsTrustActiveSTSClient
  9. {
  10. internal class Program
  11. {
  12. private static void Main(string[] args)
  13. {
  14. WS2007HttpBinding binding = new WS2007HttpBinding(SecurityMode.TransportWithMessageCredential, false);
  15. binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
  16. binding.Security.Message.EstablishSecurityContext = false;
  17.  
  18.  
  19. EndpointAddress endpoint = new EndpointAddress("https://localhost:9443/services/wso2carbon-sts");
  20.  
  21. WSTrustChannelFactory factory = new WSTrustChannelFactory(binding, endpoint);
  22. factory.Credentials.UserName.UserName = "admin";
  23. factory.Credentials.UserName.Password = "admin";
  24.  
  25. WSTrustChannel channel = (WSTrustChannel) factory.CreateChannel();
  26.  
  27. RequestSecurityToken rst = new RequestSecurityToken
  28. {
  29. RequestType = RequestTypes.Issue,
  30. KeyType = KeyTypes.Symmetric,
  31. Claims =
  32. {
  33. new RequestClaim(ClaimTypes.Name)
  34. }
  35. };
  36.  
  37. RequestSecurityTokenResponse rstr = null;
  38. SecurityToken token = channel.Issue(rst, out rstr);
  39.  
  40. Console.WriteLine("{0}", token);
  41. Console.ReadLine();
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement