Tomas Ivan
Tomas Ivan

Reputation: 2320

IdentityServer4 with Sustainsys.Saml2 to make OAuth SAML Assertion

I have a problem to make sample which will fulfill RFC-7522. What I have is IdentityServer4 (v2.2.0) as oAuth Authorization Server (.NET Core 2.0, Console Application) and different SAML2 IdP. Now I want to use Saml Assertion to auth user.

As inspiration I used this video where Brock Allen and Dominick Baier describes how to set up SAML2 handler.

But sadly, I'm stuck right at beginning where I want just paste that snippet to my code and every time I end up with different compilation error (depends on nuget I use). I've unfortunately had no luck in solving them.

Snipet:

//IServiceCollection services
services.AddAuthentication().AddSaml2(options =>
{
    options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
    options.SPOptions.EntityId = new Saml2NameIdentifier(samlIdentityUrl);

    var idp = new IdentityProvider(new EntityId(samlMetadataUrl), options.SPOptions)
    {
        SingleSignOnServiceUrl = new Uri(samlSignOnUrl),
        Binding = Saml2BindingType.HttpRedirect
    };

    idp.SigningKeys.AddConfiguredKey(new X509Certificate2(certificate));
    options.IdentityProviders.Add(idp);
});

Common Nugets:

Scenario #1: Sustainsys.Saml2.AspNetCore2 (0.24.0)

Package 'Sustainsys.Saml2.AspNetCore2 0.24.0' was restored using '.NetFramework, Version=v4.6.1'.. what is referred in this and this issue. On top of that I have few compilation error which could be break to 'The type 'EntityId' and 'SecurityKeyIdentifierClause' is defined in an assembly that is not referenced.'

Scenario #2: Sustainsys.Saml2.AspNetCore2 (2.0.0-preview01)

Missing whole Sustainsys namespace and it is replaced by Kentor.AuthServices. Reference .AddSaml2(..) not found.

Upvotes: 2

Views: 3001

Answers (1)

Tomas Ivan
Tomas Ivan

Reputation: 2320

Fine, I was able to solve my problem by update nugets and imports to following state:

Nugets:

  • IdentityServer4 (2.2.0)
  • Microsoft.AspNetCore.All (2.0.3)
  • Microsoft.IdentityModel.Token.Saml (5.2.4.)
  • Sustainsys.Saml2 (2.0.0-preview01)
  • Sustainsys.Saml2.AspNetCore2 (2.0.0-preview01)

Imports:

using Microsoft.IdentityModel.Tokens.Saml2;
using Kentor.AuthServices;
using Kentor.AuthServices.Metadata;
using Kentor.AuthServices.WebSso;

Upvotes: 2

Related Questions