Security icon indicating copy to clipboard operation
Security copied to clipboard

Can JwtBearerSample be used with ADFS instead of AzureAD

Open NickAb opened this issue 10 years ago • 11 comments

Hello, I want to secure my ASP.NET 5 WebAPI using on-premise ADFS on Windows Server 2012. Can app.UseJwtBearerAuthentication be used for this? If yes, how should I reconfigure JwtBearerSample to auth against local ADFS server?

NickAb avatar Jan 25 '16 16:01 NickAb

Isn't that WsFed/SAML based? No, there's no support for that this release cycle. We need support from https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet first.

Tratcher avatar Jan 27 '16 20:01 Tratcher

ADFS 2012 R2 can issue JWT tokens - but does not support OIDC discovery.

Manually configuring issuer, audience and signing key should work.

leastprivilege avatar Jan 27 '16 20:01 leastprivilege

@leastprivilege ADFS supports OAuth2 authorization code flow and I was able to implement it on client side, so that AngularJS SPA can obtain token and pass it on each request to the API (although I used OWINS UseActiveDirectoryFederationServicesBearerAuthentication to validate tokens, until we have Windows Server 2016 with new ADFS). My question is it OK to use authorization code flow on browser-side (AngularJS SPA) if it is going to be used intranet only and does not require high level security?

NickAb avatar Jan 29 '16 02:01 NickAb

Well - since this is the only option in ADFS - I guess the answer is yes ;)

You could also use IdentityServer as a gateway to ADFS - this would give you full OAuth 2.0 and OpenID Connect support while retaining Windows SSO and AD support.

leastprivilege avatar Jan 29 '16 07:01 leastprivilege

@leastprivilege Thanks, I will have a look at IdentityServer

NickAb avatar Jan 29 '16 07:01 NickAb

I would second what @leastprivilege suggested - the OAuth2 flows in ADFS 2012 R2 are intended exclusively for native clients hence extracting tokens from it via a JS user_agent would put you in unsupported territory. But if you front ADFS with something like IdentityServer, then the interaction with ADFS falls back to (supported) web sign on.

vibronet avatar Jan 30 '16 00:01 vibronet

@leastprivilege are there any docs on how to manually configure issuer, key, etc and prevent UseJwtBearerAuthentication to request metadata from ADFS on unexisting endpoint?

NickAb avatar Jan 30 '16 05:01 NickAb

If you set JwtBearerOptions.Configuration directly it won't try to download the metadata. https://github.com/aspnet/Security/blob/dev/src/Microsoft.AspNetCore.Authentication.JwtBearer/JwtBearerOptions.cs#L82 https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/KDev/src/Microsoft.IdentityModel.Protocols.OpenIdConnect/Configuration/OpenIdConnectConfiguration.cs

Tratcher avatar Jan 30 '16 05:01 Tratcher

Thank you very much.

NickAb avatar Jan 30 '16 06:01 NickAb

@Tratcher

If you set JwtBearerOptions.Configuration directly it won't try to download the metadata.

I apologize, but I got a bit confused by this. I gather this is the most recent sample of making IdentityServer 4 work with ADFS: https://github.com/IdentityServer/IdentityServer4/blob/dev/src/Host/Startup.cs#L113

And, as far as I can tell, the options argument in this code sample is not of the type JwtBearerOptions.Configuration

So if I follow the path of using IdentityServer in lieu of what I would call a Security Token Service as recommended by @leastprivilege, what would be proper steps to enable IdentityServer using on-prem ADFS as the identity provider, assuming we are talking about ADFS v3 which does not implement OpenID Connect?

DmytroLapshyn avatar Aug 15 '17 14:08 DmytroLapshyn

The Configuration property of the type JwtBearerOptions is a OpenIdConnectConfiguration type:

        app.UseJwtBearerAuthentication(new JwtBearerOptions
        {
            AutomaticAuthenticate = true,
            AutomaticChallenge = true,
            TokenValidationParameters = tokenValidationParameters,
            Configuration = new OpenIdConnectConfiguration
            {
                Issuer = $"https://{options.AdfsHostName}/adfs/services/trust",
            }
        });

jspetit avatar Dec 01 '17 16:12 jspetit