microsoft / service-fabric

Service Fabric is a distributed systems platform for packaging, deploying, and managing stateless and stateful distributed applications and containers at large scale.
https://docs.microsoft.com/en-us/azure/service-fabric/
MIT License
3.03k stars 401 forks source link

Service Fabric .Net Core VS Template incorrect for AAD Authentication #755

Open jaybarden opened 6 years ago

jaybarden commented 6 years ago

Hi,

When using the Service Fabric WebAPI template in VS15 (15.7.3) to autheticate to my AAD instance, I receive the following error:

Error: Microsoft.IdentityModel.Tokens.SecurityTokenInvalidSignatureException: IDX10500: Signature validation failed. No security keys were provided to validate the signature.

After much head-scratching as the stand-alone WebAPI template works and produces the same core WebAPI project, I located the issue - the AzureAD option object was not populating.

Cause:

Startup.cs had: public Startup(IConfiguration configuration) { Configuration = configuration; }

Needs to be similar to below (no doubt there is a neater solution, but this works):

public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

        builder.AddEnvironmentVariables();
        Configuration = builder.Build();
    }

I've attached a working solution bar obsfucating the AAD details. This solution was created from the template. SFApplication.zip

I hope this helps,

Jason

ashishnegi commented 6 years ago

@jaybarden Thanks for this information. Can you open a PR on service-fabric-dotnet-core-getting-started and service-fabric-dotnet-getting-started ?

It will be helpful to others as well.