Forums, Documentation & Knowledge Base - ComponentSpace

Adding in .add authentication


https://componentspace.com/forums/Topic11987.aspx

By akanksha10 - 1/13/2022

Hi Team,
I am using idp initiated SSO , where idp is .net application and SP is .net core applicatio through normal web api calls and not middleware.
In my .net core SP, i already have wesfederation in services.AddAuthentication . How can I add SAML there?
Also, how can I increase the expiry time of cookie in that. I want to set that to 12h
Code looks like this ;
services.AddAuthentication(sharedOptions =>
    {
      sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
      sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
      sharedOptions.DefaultChallengeScheme = WsFederationDefaults.AuthenticationScheme;
    })
       .AddWsFederation(options =>
    {
      options.Wtrealm = Configuration.GetSection("SSOSettings").Value;
      options.MetadataAddress = Configuration.GetSection("SSOSettings:Metadata").Value;
      options.SkipUnrecognizedRequests = true;
      options.RequireHttpsMetadata = false;
    })
    .AddCookie();

Thanks
Akanksha
By ComponentSpace - 1/13/2022

Hi Akanksha,

We support two approaches for adding SAML SSO support to your application. The first is to call the SAML API from your application. Alternatively, you can add the SAML middleware to handle SSO rather than calling the SAML API. Calling the SAML API provides you with a little more control. Using the SAML middleware means a little less code has to be written.

The ExampleServiceProvider and MiddlewareServiceProvider projects under the Examples\SSO folder demonstrate the two approaches.

Please refer to these projects for code examples. Also, the Examples Guide in the documentation folder walks you through these examples.

Briefly though, here's an example of the start-up code when using the API approach.


// Add SAML SSO services.
services.AddSaml(Configuration.GetSection("SAML"));

 

And here's an example of the start-up code when using the middleware approach.


// Add SAML SSO services.
services.AddSaml(Configuration.GetSection("SAML"));

// Add SAML authentication services.
services.AddAuthentication().AddSaml(options =>
{
  options.PartnerName = (httpContext) => Configuration["PartnerName"];
});

 

Which cookie are you referring to? Do you mean the authentication cookie?

Assuming so, please refer to:

https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.authentication.cookies.cookieauthenticationoptions?view=aspnetcore-6.0