Forums, Documentation & Knowledge Base - ComponentSpace

Missing SubjectLocality in Saml Response


https://www.componentspace.com/forums/Topic11321.aspx

By Saran - 12/15/2020

I need to add missing field(SubjectLocality) in SAML Response
<saml:SubjectLocality Address="1.1.1.1" DNSName="abc.org"/>

Can you please let me know how to generate this
By ComponentSpace - 12/15/2020

It's unusual to include a SubjectLocality which is why it isn't directly part of the SAML high-level API. However, you can update the SAML assertion prior to its transmission using the SAML notifications interface. The following example receives the OnSAMLAssertionCreated event and updates the SAML assertion.


using ComponentSpace.SAML2.Assertions;
using ComponentSpace.SAML2.Notifications;

public class ExampleSAMLObserver : AbstractSAMLObserver
{
  public override SAMLAssertion OnSAMLAssertionCreated(string partnerName, SAMLAssertion samlAssertion)
  {
   samlAssertion.GetAuthenticationStatements()[0].SubjectLocality = new SubjectLocality()
   {
      Address = "1.1.1.1",
      DNSName = "abc.org"
   };

   return samlAssertion;
  }
}



Typically you register the event handler at application start-up.


SAMLObservable.Subscribe(new ExampleSAMLObserver());