Need help resolving the issue which is not covered anywhere in docs/SO as far as I can tell.
I'm using Auth0 (https://auth0.com/) to authenticate WebApi calls. If I disable JwtBearerAuthentication, integration tests work, otherwise I get the following exception when make a call via an HttpClient:
Result StackTrace:
at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.<GetConfigurationAsync>d__24.MoveNext()
...
IDX10803: Unable to obtain configuration from: 'https:///.well-known/openid-configuration'.
IDX10108: The address specified is not valid as per HTTPS scheme. Please specify an https address for security reasons. If you want to test with http address, set the RequireHttps property on IDocumentRetriever to false.
Detailed info is available here: https://gist.github.com/another-guy/6f4c66cea405b395a265ad53cfcfca1d
project.json of the service
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.Cors": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"ServiceCommon": "1.0.0-*",
"ShortGuid": "1.0.2",
"Swashbuckle.SwaggerGen": "6.0.0-beta901",
"Swashbuckle.SwaggerUi": "6.0.0-beta901",
"System.Data.SqlClient": "4.1.0",
"Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
"Microsoft.AspNetCore.Identity": "1.0.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"System.IdentityModel.Tokens.Jwt": "5.0.0",
"Peppermint": "1.0.0-*"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
project.json of the tests
{
"version": "1.0.0-*",
"testRunner": "xunit",
"dependencies": {
"xunit": "2.1.0",
"TheNextOne2Service": "1.0.0-*",
"NSubstitute": "2.0.0-alpha003",
"dotnet-test-xunit": "1.0.0-rc2-build10025",
"Microsoft.AspNetCore.TestHost": "1.0.0",
"System.Diagnostics.TraceSource": "4.0.0-rc2-24027",
"ShortGuid": "1.0.2"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": [
"dnxcore50",
"portable-net45+win8"
]
}
}
}
Startup.cs configuration for Jwt based auth
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//...
var options = new JwtBearerOptions
{
Audience = Configuration["auth0:clientId"],
Authority = $"https://{Configuration["auth0:domain"]}/",
};
app.UseJwtBearerAuthentication(options);
app.UseCors(builder =>
{
builder
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
app.UseMvc();
//...
}
Thanks!
Configuration["auth0:domain"] is returning null. Your config sources may not be set up correctly.
@Tratcher Thanks a ton! After adding application settings files to my unit test project and the following section in project.json my tests work fine!
"buildOptions": {
"copyToOutput": [ "appsettings*.json" ]
}
Most helpful comment
Configuration["auth0:domain"]is returning null. Your config sources may not be set up correctly.