public string GetToken(string idpEndpoint, string rstsRealm) { var binding = new WindowsWSTrustBinding(SecurityMode.TransportWithMessageCredential); var factory = new System.ServiceModel.Security.WSTrustChannelFactory(binding, new EndpointAddress(new Uri(idpEndpoint))); factory.TrustVersion = TrustVersion.WSTrust13; factory.Credentials.SupportInteractive = false; var rst = new System.IdentityModel.Protocols.WSTrust.RequestSecurityToken { RequestType = RequestTypes.Issue, AppliesTo = new System.IdentityModel.Protocols.WSTrust.EndpointReference(rstsRealm), KeyType = KeyTypes.Bearer, TokenType = "urn:oasis:names:tc:SAML:1.0:assertion" // "urn:oasis:names:tc:SAML:2.0:assertion" }; var channel = factory.CreateChannel(); RequestSecurityTokenResponse response = null; try { var securityToken = channel.Issue(rst, out response); return(Serialize(response)); }catch { var x = response; } return(null); }
public static Binding CreateIdpBinding() { // Update this based on the authentication done by the idp WindowsWSTrustBinding binding = new WindowsWSTrustBinding() { SecurityMode = SecurityMode.TransportWithMessageCredential }; return(binding); }