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

Odds Ratio (OR), Logistic Regression Interpretation vs. Prediction, and Ordinal Logistic Regression

An odds ratio (OR) measures the association between an exposure and an outcome. It represents the odds that an outcome will occur given ...