• Loading...
ComponentPro UltimateSaml

AssertionConsumerService Class

See AlsoMembersMembers Options: Show AllLanguage Filter: AllSend comments on this topic to ComponentPro
Represents SAML2 Assertion Consumer Service.

Syntax

public class AssertionConsumerService : IndexedEndpointType

Examples

Shows how to create Metadata (EntityDescriptor) for an SP.

using ComponentPro.Saml2.Metadata;
using System.Xml;
using System.Security.Cryptography.Xml;
using System.Security.Cryptography.X509Certificates;

...

// Load your certificate.
X509Certificate2 x509Certificate = new X509Certificate2(@"..\..\Pkey.pfx", "password");

// Create Entity Descriptor with ID received from the IdP.
EntityDescriptor descriptor = new EntityDescriptor();
descriptor.Id = "84CCAA9F05EE4BA1B13F8943FDF1D320";
SpSsoDescriptor spd = new SpSsoDescriptor();
spd.Id = "someid";
spd.AuthnRequestsSigned = true;
spd.ProtocolSupportEnumeration = "urn:oasis:names:tc:SAML:2.0:protocol";

// Creating a key descriptor.
KeyDescriptor keyDescriptor = new KeyDescriptor();
keyDescriptor.Use = "signing";
KeyInfoX509Data keyData = new KeyInfoX509Data(x509Certificate);

// Create KeyInfo.
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(keyData);
keyDescriptor.KeyInfo = keyInfo.GetXml();
// Add KeyDescriptor.
spd.KeyDescriptors.Add(keyDescriptor);

// Assign assertion service url.
AssertionConsumerService consumerService = new AssertionConsumerService();
consumerService.Index = 0;
consumerService.IsDefault = true;
consumerService.Location = "http://www.test.com/AssertionService.aspx";
consumerService.Binding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST";
spd.AssertionConsumerServices.Add(consumerService);

descriptor.SpSsoDescriptors.Add(spd);

// Add some information. 
// Organization information
descriptor.Organization = new Organization();
descriptor.Organization.OrganizationNames.Add(new OrganizationName("Company - some name", "en"));
descriptor.Organization.OrganizationDisplayNames.Add(new OrganizationDisplayName("Company", "en"));
descriptor.Organization.OrganizationUrls.Add(new OrganizationUrl("https://www.company.be", "en"));

// Add contact person info.
ContactPerson person = new ContactPerson();
person.Company = "Company";
person.EmailAddresses.Add("helpdesk@company.be");
// Contact information
descriptor.ContactPeople.Add(person);
// Sign metadata with service provider key
descriptor.Sign(x509Certificate);

// Get XML element and its content.
XmlElement xml = descriptor.GetXml();

// Print out
System.Diagnostics.Trace.WriteLine(xml.OuterXml);

//XmlDocument document = xml.OwnerDocument; 
 
//context.Response.ContentType = "text/xml"; 
//context.Response.ContentEncoding = System.Text.Encoding.UTF8; 
//document.Save(context.Response.Output);
//context.Response.End();

Shows how to create Metadata.

using ComponentPro.Saml2.Metadata;
using System.Security.Cryptography.X509Certificates;

...

// Create a new instance of the EntityDescriptor class.
EntityDescriptor entityDescriptor = new EntityDescriptor();
// Set ID.
entityDescriptor.Id = "MPCSHKBKAJTWEF5RsrHcS2.R3Fb";
// Create a new instance of the AttributeAuthorityDescriptor class.
AttributeAuthorityDescriptor attributeAuthorityDescriptor = new AttributeAuthorityDescriptor();
// Add that AttributeAuthorityDescriptor to the entity descriptor.
entityDescriptor.AttributeAuthorityDescriptors.Add(attributeAuthorityDescriptor);

// Set binding type and location.
AttributeService attributeService = new AttributeService();
attributeService.Binding = "urn:oasis:names:tc:SAML:2.0:bindings:SOAP";
attributeService.Location = "https://xxx.xxxx.xxxx.com/idp/attrsvc.ssaml2";
attributeAuthorityDescriptor.AttributeServices.Add(attributeService);

// Load the key to sign
X509Certificate2 x509Certificate = new X509Certificate2(@"\..\..\Pkey.pfx", "password");

SpSsoDescriptor ssoDescriptor = new SpSsoDescriptor();

ArtifactResolutionService ars = new ArtifactResolutionService();
ars.IsDefault = true;
ars.Location = "https://ssoqa.thedialogcenter.com/hsyeg/sp/ARS.ssaml2";
ssoDescriptor.ArtifactResolutionServices.Add(ars);

SingleLogoutService slo = new SingleLogoutService();
slo.Binding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect";
slo.Location = "https://ssoqa.thedialogcenter.com/hsyeg/sp/SLO.saml2";
ssoDescriptor.SingleLogoutServices.Add(slo);

slo = new SingleLogoutService();
slo.Binding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST";
slo.Location = "https://ssoqa.thedialogcenter.com/hsyeg/sp/SLO.saml2";
ssoDescriptor.SingleLogoutServices.Add(slo);

slo = new SingleLogoutService();
slo.Binding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact";
slo.Location = "https://ssoqa.thedialogcenter.com/hsyeg/sp/SLO.saml2";
ssoDescriptor.SingleLogoutServices.Add(slo);

slo = new SingleLogoutService();
slo.Binding = "urn:oasis:names:tc:SAML:2.0:bindings:SOAP";
slo.Location = "https://ssoqa.thedialogcenter.com/hsyeg/sp/SLO.ssaml2";
ssoDescriptor.SingleLogoutServices.Add(slo);

AssertionConsumerService acs = new AssertionConsumerService();
acs.Binding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST";
acs.Location = "https://ssoqa.thedialogcenter.com/hsyeg/sp/ACS.saml2";
ssoDescriptor.AssertionConsumerServices.Add(acs);

AttributeConsumingService attcs = new AttributeConsumingService();
attcs.ServiceNames.Add(new ServiceName("AttributeContract", "en"));
attcs.RequestedAttributes.Add(new RequestedAttribute("lname"));
attcs.RequestedAttributes.Add(new RequestedAttribute("mid"));
attcs.RequestedAttributes.Add(new RequestedAttribute("fname"));
ssoDescriptor.AttributeConsumingServices.Add(attcs);

// You may want to sign 
// ssoDescriptor.Sign(x509Certificate);

entityDescriptor.SpSsoDescriptors.Add(ssoDescriptor);            

ContactPerson person = new ContactPerson();
person.Company = "Health Dialog";
person.GivenName = "John";
person.Surname = "Brown";
person.EmailAddresses.Add("a@email.com");
person.TelephoneNumbers.Add("12345");

entityDescriptor.ContactPeople.Add(person);

//RoleDescriptor role = new RoleDescriptor(); 
//KeyDescriptor key = new KeyDescriptor(); 
//key.Use = "encryption"; 
//role.KeyDescriptors.Add(key);           


//ssoDescriptor.Sign(x509Certificate); // Sign SSO Descriptor if needed.
entityDescriptor.Sign(x509Certificate); // In this case we sign the entity descriptor. 
 
string xml = entityDescriptor.GetXml().OuterXml;

System.Diagnostics.Trace.WriteLine(xml);

Inheritance Hierarchy

            ComponentPro.Saml2.Metadata.ComponentPro.Saml2.Metadata.AssertionConsumerService

Framework

.NET Framework.NET Framework

Supported version: 2.0, 3.0, 3.5, 4.0, 4.5.x, 4.6.x and later
Assembly: ComponentPro.Saml (in ComponentPro.Saml.dll)

See Also