The Attribute element identifies an attribute by name and optionally includes its value(s). It has the
AttributeType complex type. It is used within an attribute statement to express particular attributes and
values associated with an assertion subject. It is also used in an attribute query to request that the values of specific SAML attributes be returned.
Shows how to create an AuthnStatement and add it to an Assertion.
using System;
using ComponentPro.Saml2;
...
// Create SAML Assertion.
Assertion samlAssertion = new Assertion();
// Set Issuer
samlAssertion.Issuer = new Issuer("http://idp.domain.org", null, null, SamlNameIdentifierFormat.Entity, null);
samlAssertion.Subject = new Subject(new NameId("johnvu@test.com", null, null, SamlNameIdentifierFormat.EmailAddress, null));
samlAssertion.Conditions = new Conditions(new TimeSpan(1, 0, 0));
// Create SAML AuthnStatement.
ComponentPro.Saml2.AuthnStatement authnStatement = new ComponentPro.Saml2.AuthnStatement();
authnStatement.AuthnContext = new AuthnContext();
authnStatement.SessionNotOnOrAfter = DateTime.UtcNow.AddDays(1);
authnStatement.AuthnContext.AuthnContextClassRef = new AuthnContextClassRef(SamlAuthenticationContext.InternetProtocolPassword);
// Add it to the assertion.
samlAssertion.Statements.Add(authnStatement);
// Add an attribute statement.
AttributeStatement attributeStatement = new AttributeStatement();
// Add FirstName attribute
attributeStatement.Attributes.Add(new ComponentPro.Saml2.Attribute("FirstName", SamlAttributeNameFormat.Basic, null, "John"));
samlAssertion.Statements.Add(attributeStatement);
attributeStatement = new AttributeStatement();
// Add LastName attribute
attributeStatement.Attributes.Add(new ComponentPro.Saml2.Attribute("LastName", SamlAttributeNameFormat.Basic, null, "Vu"));
samlAssertion.Statements.Add(attributeStatement);
Imports ComponentPro.Saml2
...
' Create SAML Assertion.
Dim samlAssertion As New Assertion()
' Set Issuer
samlAssertion.Issuer = New Issuer("http://idp.domain.org", Nothing, Nothing, SamlNameIdentifierFormat.Entity, Nothing)
samlAssertion.Subject = New Subject(New NameId("johnvu@test.com", Nothing, Nothing, SamlNameIdentifierFormat.EmailAddress, Nothing))
samlAssertion.Conditions = New Conditions(New TimeSpan(1, 0, 0))
' Create SAML AuthnStatement.
Dim authnStatement As New ComponentPro.Saml2.AuthnStatement()
authnStatement.AuthnContext = New AuthnContext()
authnStatement.SessionNotOnOrAfter = Date.UtcNow.AddDays(1)
authnStatement.AuthnContext.AuthnContextClassRef = New AuthnContextClassRef(SamlAuthenticationContext.InternetProtocolPassword)
' Add it to the assertion.
samlAssertion.Statements.Add(authnStatement)
' Add an attribute statement.
Dim attributeStatement As New AttributeStatement()
' Add FirstName attribute
attributeStatement.Attributes.Add(New ComponentPro.Saml2.Attribute("FirstName", SamlAttributeNameFormat.Basic, Nothing, "John"))
samlAssertion.Statements.Add(attributeStatement)
attributeStatement = New AttributeStatement()
' Add LastName attribute
attributeStatement.Attributes.Add(New ComponentPro.Saml2.Attribute("LastName", SamlAttributeNameFormat.Basic, Nothing, "Vu"))
samlAssertion.Statements.Add(attributeStatement)
ComponentPro.Saml2.ComponentPro.Saml2.Attribute