We have been using SendSAMLResponseByHTTPPost in our .Net Framework Web Forms application, with a separate Api that is generating the SAML document using the ComponentSpace low-level Api. I would like to make the same call (SendSAMLResponseByHTTPPost) from a newer .Net Core application using Razor pages so that I can continue to use our same Api to generate the SAML document. Is it possible to use SendSAMLResponseByHTTPPost in a .Net Core application? All of the support entries I’ve seen about using ComponentSpace with .Net Core say to use the high-level Api, but I don’t want to redo the generation of the SAML document.
The equivalent is IHttpPostBinding.SendMessageAsync. The method signature is:
///
/// Sends a SAML message.
///
/// The URL to receive the SAML message.
/// The SAML message XML.
/// The flag indicating whether a SAML request or response.
/// The relay state or null if none.
/// A task that represents the operation.
///
/// Thrown if the SAML message cannot be sent.
///
Task SendMessageAsync(string url, string message, bool isResponse, string relayState = null);
The message parameter is the XML element as a string (eg XmlElement.OuterXml).
Your Razor page should use dependency injection to access this class.
using ComponentSpace.Saml2.Bindings.Post;
public TestModel(IHttpPostBinding httpPostBinding)
{
}
However, our recommendation is to reconsider using the SAML high-level API. This is a much easier interface to use and requires a lot less code in your application. It handles creating, signing and sending the SAML messages for you.
///
/// Sends a SAML message.
///
/// The URL to receive the SAML message.
/// The SAML message XML.
/// The flag indicating whether a SAML request or response.
/// The relay state or null if none.
/// A task that represents the operation.
///
/// Thrown if the SAML message cannot be sent.
///
Task SendMessageAsync(string url, string message, bool isResponse, string relayState = null);
The message parameter is the XML element as a string (eg XmlElement.OuterXml).
Your Razor page should use dependency injection to access this class.
using ComponentSpace.Saml2.Bindings.Post;
public TestModel(IHttpPostBinding httpPostBinding)
{
}
However, our recommendation is to reconsider using the SAML high-level API. This is a much easier interface to use and requires a lot less code in your application. It handles creating, signing and sending the SAML messages for you.
Thank you for the fast response. I will try this.
You’re welcome.
When I try to use this, I get the following exception. Am I missing some other configuration?
Failed to send the SAML message over HTTP-Post.
Object reference not set to an instance of an object.
at ComponentSpace.Saml2.Bindings.AspNetHttpResponse.AddHeader(String headerName, String headerValue)
at ComponentSpace.Saml2.Bindings.Post.HttpPostBinding.d__7.MoveNext()
In your application’s start-up, did you call services.AddSaml?
If there’s still an issue, please enable SAML trace and send the generated log file as an email attachment to support@componentspace.com mentioning your forum post.
https://www.componentspace.com/Forums/7936/Enabling-SAML-Trace
Also include a section of your code where you’re making the API call.
Thanks.
I sent an email to the address you provided. Please let me know if there’s any other info I can provide.
Received, thanks. I’ll respond to your email soon.