This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using MedsProcessor.WebAPI.Infrastructure; | |
using Microsoft.AspNetCore.Builder; | |
namespace MedsProcessor.WebAPI.Extensions | |
{ | |
public static class IApplicationBuilderExtensions | |
{ | |
public static IApplicationBuilder UseBasicAuthentication( | |
this IApplicationBuilder app, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Http; | |
namespace MedsProcessor.WebAPI.Infrastructure | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddSwaggerGen(opts => | |
{ | |
opts.SwaggerDoc( | |
"v1-0", | |
new Info | |
{ | |
Title = "HZZO meds-processor v1.0", | |
Version = "1.0" | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MedsProcessor.WebAPI.Infrastructure; | |
using Microsoft.AspNetCore.Authorization; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.AspNetCore.Mvc; | |
namespace MedsProcessor.WebAPI.Controllers | |
{ | |
[ApiVersionNeutral, Route("api/[controller]")] | |
public class AuthController : ApiControllerBase | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.ComponentModel.DataAnnotations; | |
using System.IdentityModel.Tokens.Jwt; | |
using System.Security.Claims; | |
using System.Text; | |
using Microsoft.Extensions.Options; | |
using Microsoft.IdentityModel.Tokens; | |
namespace MedsProcessor.WebAPI.Infrastructure | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using Microsoft.IdentityModel.Tokens; | |
namespace MedsProcessor.WebAPI.Infrastructure | |
{ | |
public class AuthTokenOptions | |
{ | |
public string Secret { get; set; } | |
public string Issuer { get; set; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddScoped<IJwtAuthService, JwtAuthService>(); | |
var tokenOptsConfig = Configuration.GetSection(nameof(AuthTokenOptions).Replace("Options", "")); | |
var tokenOpts = tokenOptsConfig.Get<AuthTokenOptions>(); | |
services.Configure<AuthTokenOptions>(tokenOptsConfig); | |
services.AddAuthentication(opts => | |
{ | |
opts.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; | |
opts.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Authorization; | |
using Microsoft.AspNetCore.Mvc; | |
namespace MedsProcessor.WebAPI.Controllers.v1_0 | |
{ | |
[ApiVersion("1.0"), Route("api/v{apiVersion:apiVersion}")] | |
[ProducesResponseType(401), ProducesResponseType(403)] | |
public abstract class ApiV1ControllerBase : ApiControllerBase { } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddMvc().AddJsonOptions(opts => | |
{ | |
opts.SerializerSettings.ContractResolver = new DefaultContractResolver | |
{ | |
NamingStrategy = new SnakeCaseNamingStrategy() | |
}; | |
opts.SerializerSettings.Formatting = Formatting.Indented; | |
opts.SerializerSettings.Converters.Add(new StringEnumConverter()); | |
opts.SerializerSettings.DateFormatString = "yyyy-MM-dd"; | |
opts.SerializerSettings.DefaultValueHandling = DefaultValueHandling.Ignore; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using MedsProcessor.Common; | |
using MedsProcessor.Common.Models; | |
using MedsProcessor.WebAPI.Core; | |
using MedsProcessor.WebAPI.Infrastructure; | |
using Microsoft.AspNetCore.Mvc; | |
namespace MedsProcessor.WebAPI.Controllers |