Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

AAD B2C - .NET Core 1.1 Web API authenticates but the .NET Core 2.0 version returns 401.

$
0
0

For the past year I've been hosting a Web API built with ASP.NET Core 1.1. I recently implemented a new version of the Web API using .NET Core 2.0 but its failing authentication. Following are the relevant code snippets from the working (1.1) and failing (2.0) project Startup.cs files.

.NET Core 1.1

// Startup.Configure Method
app.UseJwtBearerAuthentication(new JwtBearerOptions()
{
	Audience = Configuration["aad:clientId"],
	AutomaticAuthenticate = true,
	AutomaticChallenge = true,
	MetadataAddress = Configuration["aad:MetadataAddress"]);
});

.NET Core 2.0

// Startup.Configure Method
app.UseMvc().UseAuthentication();

// Startup.ConfigureServices Method
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
	.AddJwtBearer(options =>
	{
		options.Audience = Configuration["aad:clientId"];			
		options.MetadataAddress = Configuration["aad:MetadataAddress"]);
	});

doc.microsoft documentation says AutomaticAuthenticate/Challenge have been removed and the default schema (JwtBearerDefaults.AuthenticationScheme) should be used for authentication and challenges.

I'm obviously missing something but I'm not sure what at this point.

Any input you might have will be appreciated.

Thanks,

Dane Vinson


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>