.net 使用dot net MVC5生成SAML令牌
你能帮我用Dot Net MVC生成.net 使用dot net MVC5生成SAML令牌,.net,c#-4.0,saml,.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; name
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;
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.IdentityModel;
使用System.IdentityModel.Tokens;
名称空间SAML_Demo{
类SAML_演示
{
私有静态void Main(字符串[]args)
{
SamlAssertion断言=createSamlAssertion();
SamlSecurityToken samlToken=新的SamlSecurityToken(断言);
Console.WriteLine(“你好”);
Console.WriteLine(samlToken.Id+“”+samlToken.ValidFrom+“”+samlToken.ValidTo+“”+samlToken.Assertion);
}
///
///创建一些测试SAML断言
///
///
私有静态SamlAssertion createSamlAssertion()
{
//在这里,我们创建一些带有ID和颁发者名称的SAML断言。
SamlAssertion断言=新的SamlAssertion();
assertion.AssertionId=“DaenessalTest”;
assertion.Issuer=“damir”;
//
//创建一些SAML主题。
SamlSubject SamlSubject=新的SamlSubject();
samlSubject.Name=“我的主题”;
//创建一个值很少的SAML属性。
SamlatAttribute attr=新SamlatAttribute();
attr.Namespace=”http://daenet.eu/saml";
属性值添加(“某些值1”);
属性值添加(“某些值2”);
attr.Name=“我的attr值”;
//现在创建包含一个属性和一个主题的SAML语句。
SamlatTributTestItem SamlatTributTestItem=新SamlatTributTestItem();
SamlatTributionTestItem.Attributes.Add(attr);
samlAttributeStatement.SamlSubject=SamlSubject;
//将语句附加到SAML断言。
assertion.Statements.Add(SamlatTributionTestItem);
返回断言;
}
}
}