Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API authentication/authorization changes #138

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
using EPR.Calculator.API.Data.DataModels;
using EPR.Calculator.API.Dtos;
using EPR.Calculator.API.Enums;
using EPR.Calculator.API.Mappers;
using EPR.Calculator.API.Exporter;
using EPR.Calculator.API.Mappers;
using EPR.Calculator.API.Models;
using EPR.Calculator.API.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Azure;
Expand All @@ -34,6 +35,7 @@ public CalculatorController(ApplicationDBContext context, IConfiguration configu

[HttpPost]
[Route("calculatorRun")]
[Authorize(Roles = "SASuperUser")]
public async Task<IActionResult> Create([FromBody] CreateCalculatorRunDto request)
{
// Return bad request if the model is invalid
Expand Down Expand Up @@ -155,6 +157,7 @@ public async Task<IActionResult> Create([FromBody] CreateCalculatorRunDto reques

[HttpPost]
[Route("calculatorRuns")]
[Authorize(Roles = "SASuperUser")]
public IActionResult GetCalculatorRuns([FromBody] CalculatorRunsParamsDto request)
{
if (!ModelState.IsValid)
Expand Down Expand Up @@ -186,6 +189,7 @@ public IActionResult GetCalculatorRuns([FromBody] CalculatorRunsParamsDto reques

[HttpGet]
[Route("calculatorRuns/{runId}")]
[Authorize(Roles = "SASuperUser")]
public IActionResult GetCalculatorRun(int runId)
{
if (!ModelState.IsValid)
Expand Down
1 change: 1 addition & 0 deletions src/EPR.Calculator.API/EPR.Calculator.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.7.6" />
<PackageReference Include="Microsoft.Identity.Web" Version="3.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
Expand Down
18 changes: 17 additions & 1 deletion src/EPR.Calculator.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
using EPR.Calculator.API.Wrapper;
using FluentValidation;
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Azure;
using Microsoft.Identity.Web;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -42,14 +44,28 @@
builder.Services.AddScoped<ICalcResultsExporter<CalcResult>, CalcResultsExporter>();
builder.Services.AddScoped<ICalcResultLapcapDataBuilder, CalcResultLapcapDataBuilder>();
builder.Services.AddScoped<ICalcResultSummaryBuilder, CalcResultSummaryBuilder>();
builder.Services.AddScoped<IStorageService, BlobStorageService>();
builder.Services.AddScoped<IStorageService, LocalFileStorageService>();
builder.Services.AddScoped<ITransposePomAndOrgDataService, TransposePomAndOrgDataService>();
builder.Services.AddScoped<ICalcResultLateReportingBuilder, CalcResultLateReportingBuilder>();
builder.Services.AddScoped<ICalcRunLaDisposalCostBuilder, CalcRunLaDisposalCostBuilder>();
builder.Services.AddScoped<ICalcResultOnePlusFourApportionmentBuilder, CalcResultOnePlusFourApportionmentBuilder>();
builder.Services.AddScoped<ICalcResultParameterOtherCostBuilder, CalcResultParameterOtherCostBuilder>();
builder.Services.AddScoped<ICalcResultCommsCostBuilder, CalcResultCommsCostBuilder>();


// Add services to the container.
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd"));
builder.Services.AddAuthorization();

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();




builder.Services.AddValidatorsFromAssemblyContaining<CreateDefaultParameterSettingValidator>();
builder.Services.AddDbContext<ApplicationDBContext>(options =>
{
Expand Down
Loading