Skip to content

Instantly share code, notes, and snippets.

@nest-don
Last active August 6, 2019 10:00
Show Gist options
  • Save nest-don/41d3e68825710e264c4b7bb966afb42f to your computer and use it in GitHub Desktop.
Save nest-don/41d3e68825710e264c4b7bb966afb42f to your computer and use it in GitHub Desktop.
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddNester();
services.AddDbContext<JwtauthContext>(options =>
options.UseSqlite("Data Source=/var/app/source/shared/Jwtauth.db"));
services.AddScoped<IIndustryRepository, IndustryRepository>();
// Set API Version
services.AddApiVersioning(options => {
options.ReportApiVersions = true;
options.AssumeDefaultVersionWhenUnspecified = true;
options.DefaultApiVersion = new ApiVersion(1,0);
options.ApiVersionReader = new HeaderApiVersionReader("x-api-version");
});
// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Demo Jwt Auth API", Version = "v1" });
options.OperationFilter<AppendAuthorizeToSummaryOperationFilter>(); // Adds "(Auth)" to the summary so that you can see which endpoints have Authorization
// or use the generic method, e.g. c.OperationFilter<AppendAuthorizeToSummaryOperationFilter<MyCustomAttribute>>();
// add Security information to each operation for OAuth2
options.OperationFilter<SecurityRequirementsOperationFilter>();
// or use the generic method, e.g. c.OperationFilter<SecurityRequirementsOperationFilter<MyCustomAttribute>>();
// if you're using the SecurityRequirementsOperationFilter, you also need to tell Swashbuckle you're using OAuth2
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
{
Description = "Standard Authorization header using the Bearer scheme. Example: \"bearer {token}\"",
In = ParameterLocation.Header,
Name = "Authorization",
Type = SecuritySchemeType.ApiKey
});
});
// Add Identity and JWT (Note sequence important)
services.AddIdentity(Configuration);
services.AddJwt(Configuration);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment