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

Added docker compose #3

Merged
merged 6 commits into from
Apr 15, 2022
Merged
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
8 changes: 7 additions & 1 deletion Poort8.Ishare.Common.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32328.378
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Poort8.Ishare.Common", "Poort8.Ishare.Common\Poort8.Ishare.Common.csproj", "{BF1AC9D7-3818-443A-97B2-2109C03898DC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Poort8.Ishare.Common", "Poort8.Ishare.Common\Poort8.Ishare.Common.csproj", "{BF1AC9D7-3818-443A-97B2-2109C03898DC}"
EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{83A90D51-889C-4588-9A5F-9AB3A5FB8509}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +17,10 @@ Global
{BF1AC9D7-3818-443A-97B2-2109C03898DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF1AC9D7-3818-443A-97B2-2109C03898DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF1AC9D7-3818-443A-97B2-2109C03898DC}.Release|Any CPU.Build.0 = Release|Any CPU
{83A90D51-889C-4588-9A5F-9AB3A5FB8509}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83A90D51-889C-4588-9A5F-9AB3A5FB8509}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83A90D51-889C-4588-9A5F-9AB3A5FB8509}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83A90D51-889C-4588-9A5F-9AB3A5FB8509}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
31 changes: 0 additions & 31 deletions Poort8.Ishare.Common/Controllers/WeatherForecastController.cs

This file was deleted.

6 changes: 3 additions & 3 deletions Poort8.Ishare.Common/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Poort8.Ishare.Common/Poort8.Ishare.Common.csproj", "Poort8.Ishare.Common/"]
RUN dotnet restore "Poort8.Ishare.Common/Poort8.Ishare.Common.csproj"
COPY ["Poort8.Ishare.Common.csproj", "."]
RUN dotnet restore "./Poort8.Ishare.Common.csproj"
COPY . .
WORKDIR "/src/Poort8.Ishare.Common"
WORKDIR "/src/."
RUN dotnet build "Poort8.Ishare.Common.csproj" -c Release -o /app/build

FROM build AS publish
Expand Down
6 changes: 4 additions & 2 deletions Poort8.Ishare.Common/Poort8.Ishare.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>ee38f0c8-9d70-44f7-acea-f05954609c7e</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.15.0" />
<PackageReference Include="Poort8.Ishare.Core" Version="1.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
</ItemGroup>

</Project>
10 changes: 6 additions & 4 deletions Poort8.Ishare.Common/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
var builder = WebApplication.CreateBuilder(args);
using Poort8.Ishare.Core;

// Add services to the container.
var builder = WebApplication.CreateBuilder(args);

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

builder.Services.AddIshareCoreServices();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
Expand Down
87 changes: 87 additions & 0 deletions Poort8.Ishare.Common/Token/TokenController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using Microsoft.AspNetCore.Mvc;
using Poort8.Ishare.Core;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;

namespace Poort8.Ishare.Common.Token;

[Route("api/[controller]")]
[ApiController]
public class TokenController : ControllerBase
{
private readonly ILogger<TokenController> _logger;
private readonly IAuthenticationService _authenticationService;
private readonly ISchemeOwnerService _schemeOwnerService;

public TokenController(
ILogger<TokenController> logger,
IAuthenticationService authenticationService,
ISchemeOwnerService schemeOwnerService)
{
_logger = logger;
_authenticationService = authenticationService;
_schemeOwnerService = schemeOwnerService;
}

//TODO: Swagger
[HttpPost]
[Consumes("application/x-www-form-urlencoded")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> Post([Required, FromForm] TokenRequest request)
{
_logger.LogInformation("TokenRequest from {clientId}: {request}", request.ClientId, JsonSerializer.Serialize(request));

if (request.GrantType != "client_credentials" ||
request.Scope != "iSHARE" ||
request.ClientAssertionType != "urn:ietf:params:oauth:client-assertion-type:jwt-bearer")
{
return new BadRequestObjectResult("Invalid grant_type, scope or client_assertion_type.");
}

try
{
_authenticationService.ValidateToken(request.ClientId, request.ClientAssertion);
}
catch (Exception e)
{
_logger.LogWarning("Returning bad request: invalid client_assertion. {msg}", e.Message);
return new BadRequestObjectResult("Invalid client_assertion.");
}

try
{
await _schemeOwnerService.VerifyCertificateIsTrustedAsync(request.ClientAssertion);
}
catch (Exception e)
{
_logger.LogWarning("Returning bad request: certificate chain is not trusted. {msg}", e.Message);
return new BadRequestObjectResult("Certificate chain is not trusted.");
}

try
{
await _schemeOwnerService.VerifyPartyAsync(request.ClientId, request.ClientAssertion);
}
catch (Exception e)
{
_logger.LogWarning("Returning bad request: failed party checks. {msg}", e.Message);
return new BadRequestObjectResult("Failed party checks.");
}

try
{
var token = _authenticationService.CreateAccessToken(request.ClientId);
var tokenResponse = new TokenResponse(token);

_logger.LogInformation("Returning ok with token response {token}", token);
return new OkObjectResult(tokenResponse);
}
catch (Exception e)
{
_logger.LogCritical("Returning internal server error. {msg}", e.Message);
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
}
27 changes: 27 additions & 0 deletions Poort8.Ishare.Common/Token/TokenRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;

namespace Poort8.Ishare.Common.Token;

public class TokenRequest
{
[Required]
[BindProperty(Name = "grant_type")]
public string GrantType { get; set; } = null!;

[Required]
[BindProperty(Name = "scope")]
public string Scope { get; set; } = null!;

[Required]
[BindProperty(Name = "client_id")]
public string ClientId { get; set; } = null!;

[Required]
[BindProperty(Name = "client_assertion_type")]
public string ClientAssertionType { get; set; } = null!;

[Required]
[BindProperty(Name = "client_assertion")]
public string ClientAssertion { get; set; } = null!;
}
20 changes: 20 additions & 0 deletions Poort8.Ishare.Common/Token/TokenResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text.Json.Serialization;

namespace Poort8.Ishare.Common.Token;

public class TokenResponse
{
[JsonPropertyName("access_token")]
public string AccessToken { get; set; }

[JsonPropertyName("token_type")]
public string TokenType { get; } = "Bearer";

[JsonPropertyName("expires_in")]
public int ExpiresIn { get; } = 3600;

public TokenResponse(string accessToken)
{
AccessToken = accessToken;
}
}
12 changes: 0 additions & 12 deletions Poort8.Ishare.Common/WeatherForecast.cs

This file was deleted.

9 changes: 8 additions & 1 deletion Poort8.Ishare.Common/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
},
"ClientId": "EU.EORI.NL888888881",
"Certificate": "",
"CertificatePassword": "",
"CertificateChain": "",
"CertificateChainPassword": "",
"SchemeOwnerUrl": "https://scheme.isharetest.net",
"SchemeOwnerIdentifier": "EU.EORI.NL000000000"
}
18 changes: 18 additions & 0 deletions docker-compose.dcproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
<PropertyGroup Label="Globals">
<ProjectVersion>2.1</ProjectVersion>
<DockerTargetOS>Linux</DockerTargetOS>
<ProjectGuid>83a90d51-889c-4588-9a5f-9ab3a5fb8509</ProjectGuid>
<DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
<DockerServiceUrl>{Scheme}://localhost:{ServicePort}/swagger</DockerServiceUrl>
<DockerServiceName>poort8.ishare.common</DockerServiceName>
</PropertyGroup>
<ItemGroup>
<None Include="docker-compose.override.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose.yml" />
<None Include=".dockerignore" />
</ItemGroup>
</Project>
20 changes: 20 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3.4'

services:
poort8.ishare.common:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
- ClientId=EU.EORI.NL888888881
- Certificate=
- CertificatePassword=
- CertificateChain=
- CertificateChainPassword=
- SchemeOwnerUrl=https://scheme.isharetest.net
- SchemeOwnerIdentifier=EU.EORI.NL000000000
ports:
- "80"
- "443"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3.4'

services:
poort8.ishare.common:
image: ${DOCKER_REGISTRY-}poort8isharecommon
build:
context: .
dockerfile: Poort8.Ishare.Common/Dockerfile