使用dot net MVC5生成SAML令牌

时间:2015-01-16 10:22:20

标签: .net c#-4.0 saml

请帮助我使用Dot Net MVC生成SAML令牌,以下是我编写的代码,但它将SAML令牌值返回为NULL

using System;    
using System.Collections.Generic;    
using System.Linq;     
using System.Text;
using System.Threading.Tasks;
using System.IdentityModel; 
using System.IdentityModel.Tokens; 

namespace SAML_Demo { 
  class SAML_Demo
  { 
    private static void Main(string[] args) 
    { 
      SamlAssertion assertion = createSamlAssertion(); 
      SamlSecurityToken samlToken = new SamlSecurityToken(assertion); 

      Console.WriteLine("Hello"); 
      Console.WriteLine(samlToken.Id + " " + samlToken.ValidFrom + " " + samlToken.ValidTo + " " + samlToken.Assertion); 
    } 

    /// <summary> 
    /// Creates some Test SAML assertion 
    /// </summary> 
    /// <returns></returns> 
    private static SamlAssertion createSamlAssertion() 
    { 
      // Here we create some SAML assertion with ID and Issuer name.

      SamlAssertion assertion = new SamlAssertion();
      assertion.AssertionId = "DaenetSamlTest";
      assertion.Issuer = "damir";

      // 
      // Create some SAML subject. 
      SamlSubject samlSubject = new SamlSubject(); 
      samlSubject.Name = "My Subject";

      // Create one SAML attribute with few values. 
      SamlAttribute attr = new SamlAttribute(); 
      attr.Namespace = "http://daenet.eu/saml";          
      attr.AttributeValues.Add("Some Value 1");           
      attr.AttributeValues.Add("Some Value 2"); 
      attr.Name = "My ATTR Value";

      // Now create the SAML statement containing one attribute and one subject. 
      SamlAttributeStatement samlAttributeStatement = new SamlAttributeStatement(); 
      samlAttributeStatement.Attributes.Add(attr);
      samlAttributeStatement.SamlSubject = samlSubject; 

      // Append the statement to the SAML assertion.
      assertion.Statements.Add(samlAttributeStatement); 
      return assertion; 
    } 
  } 
}

0 个答案:

没有答案