Authenticate ASPNet Core from Azure

First you need to create a section in appsettings.json file
  "AzureAd": {
    "Instance": "https://login.microsoftonline.com/",
    "Domain": "Your Domain",
    "TenantId": "Your Tenant Id",
    "ClientId": "Your Client Id",
    "CallbackPath": "/signin-oidc"
  }
then I usually use extension method for the service collection
public static void AddApplicationAuthentication(this IServiceCollection services)
        {
            IConfiguration Configuration = services.BuildServiceProvider().GetRequiredService<IConfiguration>();

            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
                .AddAzureAD(options => Configuration.Bind("AzureAd", options));
        }
this should do the trick

Comments

Post a Comment