// Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. using Client; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.IdentityModel.Tokens; namespace Api { public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddControllers(); // accepts any access token issued by identity server services.AddAuthentication("Bearer") .AddJwtBearer("Bearer", options => { options.Authority = Urls.IdentityServer; options.TokenValidationParameters = new TokenValidationParameters { ValidateAudience = false }; }); // adds an authorization policy to make sure the token is for scope 'api1' services.AddAuthorization(options => { options.AddPolicy("ApiScope", policy => { policy.RequireAuthenticatedUser(); policy.RequireClaim("scope", "api1"); }); }); } public void Configure(IApplicationBuilder app) { app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers() .RequireAuthorization("ApiScope"); }); } } }