Reputation: 7102
I have a .Net 5 Entity Framework project that I have added the ITfoxtec SAML 2.0 library to it.
I need to be able to connect to a corporate network that uses SAML 2.0. The IT guys say I need to "create a SAML 2.0 assertion to point the the corporate SAML route."
I followed the code examples on the Git Repository and added all the needed configuration elements to my startup.cs
class.
Also in my AuthController.cs
I have added the following:
[Route("Login")]
public IActionResult Login(string returnUrl = null)
{
var binding = new Saml2RedirectBinding();
binding.SetRelayStateQuery(new Dictionary<string, string> { { relayStateReturnUrl, returnUrl ?? Url.Content("~/") } });
return binding.Bind(new Saml2AuthnRequest(config)).ToActionResult();
}
[Route("AssertionConsumerService")]
public async Task<IActionResult> AssertionConsumerService()
{
var binding = new Saml2PostBinding();
var saml2AuthnResponse = new Saml2AuthnResponse(config);
binding.ReadSamlResponse(Request.ToGenericHttpRequest(), saml2AuthnResponse);
if (saml2AuthnResponse.Status != Saml2StatusCodes.Success)
{
throw new AuthenticationException($"SAML Response status: {saml2AuthnResponse.Status}");
}
binding.Unbind(Request.ToGenericHttpRequest(), saml2AuthnResponse);
await saml2AuthnResponse.CreateSession(HttpContext, claimsTransform: (claimsPrincipal) => ClaimsTransform.Transform(claimsPrincipal));
var relayStateQuery = binding.GetRelayStateQuery();
var returnUrl = relayStateQuery.ContainsKey(relayStateReturnUrl) ? relayStateQuery[relayStateReturnUrl] : Url.Content("~/");
return Redirect(returnUrl);
}
The project builds and runs, but I'm not sure how to test this ITfoxtec SAML 2.0 library.
Does anyone have any experience with this?
Thanks!
Upvotes: 1
Views: 883
Reputation: 4334
You simply test it by opening the browser and clicking login. The ITfoxtec Identity SAML 2.0 component will with your code do a redirect to your corporate IdP and it expects a post back through the browser.
Upvotes: 1