ComponentSpace

Forums



Need to add Extensions to AuthnRequest


Need to add Extensions to AuthnRequest

Author
Message
epassadore
epassadore
New Member
New Member (2 reputation)New Member (2 reputation)New Member (2 reputation)New Member (2 reputation)New Member (2 reputation)New Member (2 reputation)New Member (2 reputation)New Member (2 reputation)New Member (2 reputation)

Group: Forum Members
Posts: 2, Visits: 14
ComponentSpace - 3/6/2019
Below is some example code demonstrating using the ISAMLObserver interface to update the SAML authn request with extensions data.


using ComponentSpace.SAML2.Notifications;
using ComponentSpace.SAML2.Protocols;

public class SAMLObserver : AbstractSAMLObserver
{
  public override AuthnRequest OnAuthnRequestCreated(AuthnRequest authnRequest)
  {
   var xmlDocument = new XmlDocument();
   xmldocument.LoadXml("<test/>");

   authnRequest.Extensions = new Extensions()
   {
     Data = xmldocument.ChildNodes
   };

   return authnRequest;
  }
}



You need to subscribe to events, for example, at application start-up in Global.asax.


protected void Application_Start()
{
  SAMLObservable.Subscribe(new SAMLObserver());
}


The OnAuthnRequestCreated will be called whenever a SAML authn request has been created. It’s your opportunity to update the authn request.
There are no changes required to the code where you call SAMLServiceProvider.InitiateSSO.

Hello,
I'm evaluating your products and I need to understand how to add some custom attribute to a SAML Request (for example the attribute AttributeConsumingServiceIndex).
After some readings I understand that I have to ovverride a SAMLObserver. Can you provide an example in .NET Core 3.1 to set this item?

Regards
Erik
ComponentSpace
ComponentSpace
ComponentSpace Development
ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)

Group: Administrators
Posts: 3.2K, Visits: 11K
Hi Erik,

Please note that this topic refers to SAML for ASP.NET rather than SAML for ASP.NET Core. A better approach when using SAML for ASP.NET Core is to hook into the OnAuthnRequestCreated event and set the AttributeConsumingServiceIndex property as shown in the following example.


// Set the AttributeConsumingServiceIndex in the authn request.
_samlServiceProvider.Events.OnAuthnRequestCreated += (httpContext, authnRequest) =>
{
  authnRequest.AssertionConsumerServiceIndex = 1;
    
  return authnRequest;
};

// Initiate single sign-on to the identity provider (SP-initiated SSO).    
var partnerName = _configuration["PartnerName"];

await _samlServiceProvider.InitiateSsoAsync(partnerName);




Regards
ComponentSpace Development
epassadore
epassadore
New Member
New Member (2 reputation)New Member (2 reputation)New Member (2 reputation)New Member (2 reputation)New Member (2 reputation)New Member (2 reputation)New Member (2 reputation)New Member (2 reputation)New Member (2 reputation)

Group: Forum Members
Posts: 2, Visits: 14
ComponentSpace - 2/15/2021
Hi Erik,

Please note that this topic refers to SAML for ASP.NET rather than SAML for ASP.NET Core. A better approach when using SAML for ASP.NET Core is to hook into the OnAuthnRequestCreated event and set the AttributeConsumingServiceIndex property as shown in the following example.


// Set the AttributeConsumingServiceIndex in the authn request.
_samlServiceProvider.Events.OnAuthnRequestCreated += (httpContext, authnRequest) =>
{
  authnRequest.AssertionConsumerServiceIndex = 1;
    
  return authnRequest;
};

// Initiate single sign-on to the identity provider (SP-initiated SSO).    
var partnerName = _configuration["PartnerName"];

await _samlServiceProvider.InitiateSsoAsync(partnerName);



Hi,
excuse me for the wrong topic.
Thank you for the reply, now I am able to set this attribute.

Regards
Erik
ComponentSpace
ComponentSpace
ComponentSpace Development
ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)

Group: Administrators
Posts: 3.2K, Visits: 11K
Not a problem. You're very welcome.

Regards
ComponentSpace Development
GO


Similar Topics


Execution: 0.000. 2 queries. Compression Enabled.
Login
Existing Account
Email Address:


Password:


Select a Forum....












Forums, Documentation & Knowledge Base - ComponentSpace


Search