Represents SAML2 Attribute Service.
public class AttributeService : Endpoint
Public Class AttributeService
Inherits Endpoint
public ref class AttributeService : public Endpoint
Shows how to create Metadata (EntityDescriptor) for an IdP.
using ComponentPro.Saml2.Metadata;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.Xml;
...
// 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");
IdpSsoDescriptor ssoDescriptor = new IdpSsoDescriptor();
SingleLogoutService slo = new SingleLogoutService();
slo.Location = "https://xxx.xxxx.xxxx.com/idp/SLO.saml2";
ssoDescriptor.SingleLogoutServices.Add(slo);
SingleSignOnService sso = new SingleSignOnService();
sso.Location = "https://xxx.xxxx.xxxx.com/idp/SSO.saml2";
ssoDescriptor.SingleSignOnServices.Add(sso);
entityDescriptor.IdpSsoDescriptors.Add(ssoDescriptor);
ContactPerson person = new ContactPerson();
person.Company = "company";
person.EmailAddresses.Add("a@email.com");
person.GivenName = "Jenna";
entityDescriptor.ContactPeople.Add(person);
// You can add more contact person here...
#region Signing key descriptor if needed
// Load certificate to sign
KeyInfoX509Data certKeyInfoX509Data = new KeyInfoX509Data(x509Certificate);
KeyInfo certKeyInfo = new KeyInfo();
certKeyInfo.AddClause(certKeyInfoX509Data);
// Add key descriptor
KeyDescriptor keyDesc = new KeyDescriptor();
keyDesc.Use = "signing";
keyDesc.KeyInfo = certKeyInfo.GetXml();
ssoDescriptor.KeyDescriptors.Add(keyDesc);
#endregion
//ssoDescriptor.Sign(x509Certificate);
entityDescriptor.Sign(x509Certificate); // Sign the entity descriptor if needed
string xml = entityDescriptor.GetXml().OuterXml;
System.Diagnostics.Trace.WriteLine(xml);
Imports ComponentPro.Saml2.Metadata
Imports System.Security.Cryptography.X509Certificates
Imports System.Security.Cryptography.Xml
...
' Create a new instance of the EntityDescriptor class.
Dim entityDescriptor As New EntityDescriptor()
' Set ID.
entityDescriptor.Id = "MPCSHKBKAJTWEF5RsrHcS2.R3Fb"
' Create a new instance of the AttributeAuthorityDescriptor class.
Dim attributeAuthorityDescriptor As New AttributeAuthorityDescriptor()
' Add that AttributeAuthorityDescriptor to the entity descriptor.
entityDescriptor.AttributeAuthorityDescriptors.Add(attributeAuthorityDescriptor)
' Set binding type and location.
Dim attributeService As 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
Dim x509Certificate As New X509Certificate2("Pkey.pfx", "password")
Dim ssoDescriptor As New IdpSsoDescriptor()
Dim slo As New SingleLogoutService()
slo.Location = "https://xxx.xxxx.xxxx.com/idp/SLO.saml2"
ssoDescriptor.SingleLogoutServices.Add(slo)
Dim sso As New SingleSignOnService()
sso.Location = "https://xxx.xxxx.xxxx.com/idp/SSO.saml2"
ssoDescriptor.SingleSignOnServices.Add(sso)
entityDescriptor.IdpSsoDescriptors.Add(ssoDescriptor)
Dim person As New ContactPerson()
person.Company = "company"
person.EmailAddresses.Add("a@email.com")
person.GivenName = "Jenna"
entityDescriptor.ContactPeople.Add(person)
' You can add more contact person here...
' #Region "Signing key descriptor if needed"
' Load certificate to sign
Dim certKeyInfoX509Data As New KeyInfoX509Data(x509Certificate)
Dim certKeyInfo As New KeyInfo()
certKeyInfo.AddClause(certKeyInfoX509Data)
' Add key descriptor
Dim keyDesc As New KeyDescriptor()
keyDesc.Use = "signing"
keyDesc.KeyInfo = certKeyInfo.GetXml()
ssoDescriptor.KeyDescriptors.Add(keyDesc)
' #End Region
'ssoDescriptor.Sign(x509Certificate);
entityDescriptor.Sign(x509Certificate) ' Sign the entity descriptor if needed
Dim xml As String = entityDescriptor.GetXml().OuterXml
System.Diagnostics.Trace.WriteLine(xml)
ComponentPro.Saml2.Metadata.ComponentPro.Saml2.Metadata.AttributeService