Wednesday, August 4, 2021

How to Use IS4 bearer auth in asp.net core web api project

 1. 

public void ConfigureServices(IServiceCollection services)
{
    services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
            .AddIdentityServerAuthentication(options =>
            {
                options.Authority = "https://localhost:44354";
                options.ApiName = "app.api.weather";
            });

    services.AddControllers();
}


To use IdentityServerAuthenticaltionDefaults, you need to install nuget package Microsoft.AspNet.Identity.Core



2. 

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    //..removed for brevity

    app.UseRouting();
    app.UseAuthentication();
    app.UseAuthorization();

    //..removed for brevity
}

3. 

[ApiController]
[Authorize]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
    //...removed for brevity
}










No comments:

Post a Comment

 using Microsoft.AspNetCore.Mvc; using System.Xml.Linq; using System.Xml.XPath; //<table class="common-table medium js-table js-stre...