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

DOCKER ARG instruction as opposed to ENV instruction

  In Docker, ARG and ENV are used to define environment variables. The ARG instruction defines variables that users can pass to the builder ...