Advertisement
Guest User

Untitled

a guest
Sep 5th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. //string endpointUri = string.Format("https://{0}/adfs/services/trust/13/usernamemixed", _serverName);
  2. string endpointUri = string.Format("https://{0}/adfs/services/trust/2005/usernamemixed", _serverName);
  3.  
  4. var factory = new WSTrustChannelFactory(
  5. new UserNameWSTrustBinding(),
  6. new EndpointAddress(endpointUri));
  7.  
  8. //factory.TrustVersion = TrustVersion.WSTrust13;
  9. factory.TrustVersion = TrustVersion.WSTrustFeb2005;
  10.  
  11. if (factory.Credentials != null)
  12. {
  13. factory.Credentials.UserName.UserName = _userName;
  14. factory.Credentials.UserName.Password = _password;
  15. }
  16.  
  17. var rst = new RequestSecurityToken
  18. {
  19. RequestType = RequestTypes.Issue,
  20. KeyType = KeyTypes.Bearer,
  21. AppliesTo = new EndpointReference(_relyingPartyUri),
  22. KeySizeInBits = 0,
  23.  
  24. TokenType = "urn:ietf:params:oauth:token-type:jwt",
  25.  
  26. };
  27.  
  28. var channel = factory.CreateChannel();
  29. try
  30. {
  31. var token = channel.Issue(rst);
  32. return token as GenericXmlSecurityToken;
  33. }
  34. catch (ProtocolException ex)
  35. {
  36. Debug.Write(ex.Message);
  37. }
  38. return null;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement