Can JwtBearerSample be used with ADFS instead of AzureAD
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?
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.
ADFS 2012 R2 can issue JWT tokens - but does not support OIDC discovery.
Manually configuring issuer, audience and signing key should work.
@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?
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 Thanks, I will have a look at IdentityServer
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.
@leastprivilege are there any docs on how to manually configure issuer, key, etc and prevent UseJwtBearerAuthentication to request metadata from ADFS on unexisting endpoint?
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
Thank you very much.
@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?
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",
}
});