开发者

How decrypt SAML token

Have such desktop application it seems work but finally as token return encrypted saml could you prompt me how to decrypt it

class Program
    {
    static void Main(string[] args)
    {
        ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationCallback;

        var samlToken = GetSamlToken("@domain", "@login", "@password");

        Console.WriteLine(Uri.UnescapeDataString(samlToken));
        Console.ReadLine();
    }
    private static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    {
        return sslPolicyErrors == SslPolicyErrors.None
            || string.Equals(certificate.Issuer, "CN=Name", StringComparison.InvariantCultureIgnoreCase);
    }
    private static string GetSamlToken(string domain, string userName, string password)
    {

        var acsUrl = "@RPURL";

        var stsUrl = "@stsurl";

        WSTrustChannelFactory trustChannelFactory =
            new WSTrustChannelFactory(new WindowsWSTrustBinding(SecurityMode.TransportWithMessageCredential),
                new EndpointAddress(new Uri(stsUrl)));

        trustChannelFactory.TrustVersion = TrustVersion.WSTrust13;
        trustChannelFactory.Credentials.Windows.ClientCredential.Domain = domain;
        trustChannelFactory.Creden开发者_如何学JAVAtials.Windows.ClientCredential.UserName = userName;
        trustChannelFactory.Credentials.Windows.ClientCredential.Password = password;

        try
        {
            RequestSecurityToken rst =
                new RequestSecurityToken(WSTrust13Constants.RequestTypes.Issue, WSTrust13Constants.KeyTypes.Bearer);
            rst.AppliesTo = new EndpointAddress(acsUrl);
            rst.TokenType = Microsoft.IdentityModel.Tokens.SecurityTokenTypes.Saml2TokenProfile11;

            WSTrustChannel channel = (WSTrustChannel)trustChannelFactory.CreateChannel();
            GenericXmlSecurityToken token = channel.Issue(rst) as GenericXmlSecurityToken;
            string tokenString = token.TokenXml.OuterXml;

            return tokenString;
        }
        finally
        {
            trustChannelFactory.Close();
        }
    }
}

thanks


check http://zamd.net/category/federationsts/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜