Merged PR 70: Tuitio rebranding

- Tuitio rebranding
- Tuitio rebranding
- Tuitio rebranding
- Tuitio rebranding
- netmash
- Tuitio
- Tuitio rebranding
- Dockerfile update
- Tuitio rebranding
- removed old scripts
- readme update
- removed old notes file
- packages updates
master
Tudor Stanciu 2023-01-31 00:17:54 +00:00
parent c032338bcd
commit 2eb299049e
82 changed files with 482 additions and 536 deletions

4
.gitignore vendored
View File

@ -338,3 +338,7 @@ ASALocalRun/
# BeatPulse healthcheck temp database
healthchecksdb
*/**/appsettings.Development.json
build.sh
buildx.sh

View File

@ -1,10 +1,10 @@
<Project>
<Import Project="dependencies.props" />
<PropertyGroup>
<Version>1.1.3</Version>
<Version>2.0.0</Version>
<Authors>Tudor Stanciu</Authors>
<Company>STA</Company>
<PackageTags>IdentityServer</PackageTags>
<Copyright>STA Identity server</Copyright>
<PackageTags>Tuitio</PackageTags>
<Copyright>STA Tuitio</Copyright>
</PropertyGroup>
</Project>

View File

@ -1,18 +0,0 @@
# Identity Server
## How To Use 🔧
## Roadmap 🚧
## IdentityServer.Api
⚡️ Nu mai returna si status code din metoda de autentificare
⚡️ Store passwords as hash\
⚡️ Documentatie in fisier .md afisata in frontend - e diferite de release notes\
## IdentityServer.Frontend
⚡️ Se vor putea adauga/edita/sterge/inactiva useri\
⚡️ Se vor putea vedea login-urile unui user; se va putea invalida un token activ\
⚡️ Se va putea decoda un token - public, fara auth\

View File

@ -1,37 +0,0 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY dependencies.props .
COPY Directory.Build.props .
COPY NuGet.config .
COPY ["IdentityServer.Api/IdentityServer.Api.csproj", "IdentityServer.Api/"]
COPY ["IdentityServer.Application/IdentityServer.Application.csproj", "IdentityServer.Application/"]
COPY ["IdentityServer.Domain/IdentityServer.Domain.csproj", "IdentityServer.Domain/"]
COPY ["IdentityServer.PublishedLanguage/IdentityServer.PublishedLanguage.csproj", "IdentityServer.PublishedLanguage/"]
COPY ["IdentityServer.Domain.Data/IdentityServer.Domain.Data.csproj", "IdentityServer.Domain.Data/"]
RUN dotnet restore "IdentityServer.Api/IdentityServer.Api.csproj"
COPY . .
WORKDIR "/src/IdentityServer.Api"
RUN dotnet build "IdentityServer.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "IdentityServer.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV urls="http://*:80"
ENV ConnectionStrings__DatabaseConnection="*********************************"
ENV TZ=Europe/Bucharest
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
#Workaround to lower the TLS level in container for old sql server version
RUN sed -i 's/TLSv1.2/TLSv1.0/g' /etc/ssl/openssl.cnf
ENTRYPOINT ["dotnet", "IdentityServer.Api.dll", "--console"]

View File

@ -1,93 +0,0 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Core;
using Serilog.Events;
using Serilog.Sinks.MSSqlServer;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace IdentityServer.Api
{
public class Program
{
public static void Main(string[] args)
{
var isConsole = args.Contains("--console");
if (!isConsole)
{
var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
var pathToContentRoot = Path.GetDirectoryName(pathToExe);
Directory.SetCurrentDirectory(pathToContentRoot);
}
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var connectionString = configuration.GetConnectionString("DatabaseConnection");
var loggingLevelParam = configuration.GetValue<string>("Logging:LogLevel:Default");
var loggingLevelOk = Enum.TryParse(loggingLevelParam, out LogEventLevel loggingLevel);
if (!loggingLevelOk)
throw new Exception($"Logging level '{loggingLevelParam}' is not valid.");
var loggingLevelSwitch = new LoggingLevelSwitch(loggingLevel);
var columnOptions = new ColumnOptions();
columnOptions.Store.Remove(StandardColumn.Properties);
columnOptions.Store.Remove(StandardColumn.MessageTemplate);
columnOptions.Store.Add(StandardColumn.LogEvent);
var mssqlSinkOptions = new MSSqlServerSinkOptions() { AutoCreateSqlTable = true, TableName = "__Logs" };
Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(loggingLevelSwitch)
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.MSSqlServer(connectionString, mssqlSinkOptions, columnOptions: columnOptions)
.CreateLogger();
//Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg));
try
{
var urls = configuration.GetValue<string>("urls");
Log.Information("Starting identity server API...");
Log.Information($"API listening on {urls}");
Console.WriteLine("Application started. Press Ctrl+C to shut down.");
CreateHostBuilder(args, configuration, !isConsole).Build().Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Identity server API host terminated unexpectedly");
}
finally
{
Log.CloseAndFlush();
}
}
public static IHostBuilder CreateHostBuilder(string[] args, IConfiguration configuration, bool useWindowsService)
{
var builder = Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>()
.UseConfiguration(configuration)
.UseSerilog();
});
if (useWindowsService)
builder.UseWindowsService();
return builder;
}
}
}

View File

@ -1,89 +0,0 @@
using IdentityServer.Application;
using IdentityServer.Application.Services.Abstractions;
using IdentityServer.Domain.Data;
using MediatR;
using MediatR.Pipeline;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NDB.Extensions.Swagger;
using NDB.Extensions.Swagger.Constants;
using NDB.Infrastructure.DatabaseMigration;
using NDB.Infrastructure.DatabaseMigration.Constants;
using Newtonsoft.Json;
using System.Reflection;
namespace IdentityServer.Api
{
public class Startup
{
private readonly IConfiguration _configuration;
public Startup(IConfiguration configuration)
{
_configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers()
.AddNewtonsoftJson(o => o.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc);
// MediatR
services.AddMediatR(GetMediatRAssemblies());
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(RequestPreProcessorBehavior<,>));
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(RequestPostProcessorBehavior<,>));
// AutoMapper
services.AddAutoMapper(
typeof(Application.Mappings.MappingProfile).Assembly);
// Swagger
services.AddSwagger("Identity Server API", AuthorizationType.None);
// Data access
services.AddMigration(DatabaseType.SQLServer, MetadataLocation.Database);
services.AddDataAccess();
// Application
services.AddApplicationServices();
}
private Assembly[] GetMediatRAssemblies()
{
var assembly = typeof(Application.Commands.AuthenticateUser).Assembly;
return new Assembly[] { assembly };
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// global cors policy
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.ConfigureSwagger("IdentityServer API");
app.UseMigration();
var behaviorService = app.ApplicationServices.GetService<IBehaviorService>();
behaviorService.FillTokenStore();
}
}
}

View File

@ -1,9 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

View File

@ -1,20 +0,0 @@
{
"urls": "http://*:5063",
"ConnectionStrings": {
"DatabaseConnection": "Server=######;Database=######;User Id=######;Password=######;MultipleActiveResultSets=true"
},
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"Restrictions": {
"MaxFailedLoginAttempts": 5
},
"Token": {
"ValidityInMinutes": 43800
}
}

View File

@ -1,11 +0,0 @@
using IdentityServer.PublishedLanguage.Events;
using NDB.Application.DataContracts;
namespace IdentityServer.Application.Commands
{
public class AuthenticateUser : Command<AuthenticateUserResult>
{
public string UserName { get; set; }
public string Password { get; set; }
}
}

View File

@ -1,10 +0,0 @@
using IdentityServer.PublishedLanguage.Dto;
using NDB.Application.DataContracts;
namespace IdentityServer.Application.Commands
{
public class AuthorizeToken : Command<TokenCore>
{
public string Token { get; set; }
}
}

View File

@ -1,13 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Description>Identity server published language package</Description>
<PackageProjectUrl>https://dev.azure.com/tstanciu94/IdentityServer</PackageProjectUrl>
<RepositoryUrl>https://dev.azure.com/tstanciu94/_git/IdentityServer</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<PackageReleaseNotes>Identity server published language package</PackageReleaseNotes>
<Version>1.1.0</Version>
</PropertyGroup>
</Project>

View File

@ -1,21 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Description>Identity server wrapper</Description>
<PackageReleaseNotes>Identity server wrapper</PackageReleaseNotes>
<PackageProjectUrl>https://dev.azure.com/tstanciu94/IdentityServer</PackageProjectUrl>
<RepositoryType>Git</RepositoryType>
<RepositoryUrl>https://dev.azure.com/tstanciu94/_git/IdentityServer</RepositoryUrl>
<PackageTags>IdentityServer wrapper</PackageTags>
<Version>1.1.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IdentityServer.PublishedLanguage" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.3" />
<PackageReference Include="NDB.Extensions.Http" Version="1.0.0" />
</ItemGroup>
</Project>

View File

@ -3,14 +3,14 @@ Publish:
dotnet publish --configuration Release --runtime win7-x64
Create windows service:
sc create IdentityServer.Api binPath= "<path_to_the_service_executable>"
sc create Tuitio.Api binPath= "<path_to_the_service_executable>"
#######################################################################################################################################################
#######################################################################################################################################################
Push language package:
dotnet nuget push IdentityServer.PublishedLanguage.1.1.0.nupkg -k ******** -s http://********/NuGetServer/nuget
dotnet nuget push IdentityServer.Wrapper.1.1.0.nupkg -k ******** -s http://********/NuGetServer/nuget
dotnet nuget push Tuitio.PublishedLanguage.1.1.0.nupkg -k ******** -s http://********/NuGetServer/nuget
dotnet nuget push Tuitio.Wrapper.1.1.0.nupkg -k ******** -s http://********/NuGetServer/nuget
#######################################################################################################################################################
TO DO:
@ -22,7 +22,7 @@ Docker commands:
Create image:
--from solution folder:
docker image build -t "identity-server-api:1.0.1" -f "IdentityServer.Api/Dockerfile" .
docker image build -t "identity-server-api:1.0.1" -f "Tuitio.Api/Dockerfile" .
Run image:
docker run -p 5053:80 -it identity-server-api:1.0.1

View File

@ -1,9 +1,35 @@
# Identity Server
# Tuitio
This project represents a simple identity server implementation focused strictly on the needs of my home lab.
Tuitio is a simple identity server implementation focused strictly on the needs of my home lab.
At the moment it has a simple API consisting of only two methods:
* ```/identity/authenticate``` - takes care of authenticating a user based on credentials and generates an access token.
* ```/identity/authorize``` - deals with the authorization of a token (verifies its existence, validity, authenticity, etc)
* ```/identity/authenticate``` - handles user authentication using credentials and generates an access token.
* ```/identity/authorize``` - manages the authorization process for a token, including verification of its existence, validity, and authenticity.
***Tuitio*** is a latin word that encompasses meanings such as supervision, safeguarding, defense, guard duty, and protection.
## Database
Currently, the database server supported by the system is only Microsoft SQL Server. In the following versions, the system will also be compatible with PostgreSQL and SQLite.
## Logging
The logging functionality is managed with Serilog, and its configuration is done in the ```appsettings.json``` file. In addition to its standard configuration, Tuitio also has a preconfigured area where two destinations for logs are available: SqlServer database and Seq. Each of the destinations can be activated or not. If logging in the console is sufficient, all additional logging destinations can be disabled.
This configuration area is:
```
"Logs": {
"SqlServer": {
"Enabled": false,
"Connection": "Server=<server>;Database=<database>;User Id=<user>;Password=<password>;"
},
"Seq": {
"Enabled": false,
"Url": "",
"ApiKey": ""
}
}
```
## Hosting
The only hosting environment tested for this service is Docker, but considering that .NET 6 is cross platform, it can most likely be hosted in any environment.
## Stack
* .NET (C#)
@ -11,4 +37,4 @@ At the moment it has a simple API consisting of only two methods:
* SQL Server
* Swagger
* Docker
* Shell
* Seq

View File

@ -9,8 +9,8 @@
- Authentication: An user name and a password are required in the request body. The request type is POST. The output is an object with the following structure: { token: { raw: "***", validFrom: "", validUntil: "" }, status: "SUCCESS" }
- Authorization: The request type is also POST and and its scope is to authorize a token. The input is just the token in string format: { token: "***" }
For .NET consumers there are two nuget packages developed to facilitate the integration with this identity server:
- IdentityServer.PublishedLanguage: It contains constants and classes for data transfer objects.
- IdentityServer.Wrapper: It compose and executes all the REST requests to the identity server and offers to a consumer a simple interface with all methods. This interface can be injected with dependency injection at consumer startup with UseIdentityServices method. The only input is the server base address.
- Tuitio.PublishedLanguage: It contains constants and classes for data transfer objects.
- Tuitio.Wrapper: It compose and executes all the REST requests to the identity server and offers to a consumer a simple interface with all methods. This interface can be injected with dependency injection at consumer startup with UseIdentityServices method. The only input is the server base address.
- The source of this nugets is public, but on my personal server: https://lab.code-rove.com/public-nuget-server/nuget
</Content>
</Note>
@ -27,13 +27,13 @@
<Version>1.1.0</Version>
<Content>
◾ Upgrade all projects to .NET 5
◾ Upgrade packages MicrosoftExtensions, AutoMapper, EntityFramework, NDB
◾ Upgrade packages MicrosoftExtensions, AutoMapper, EntityFramework, Netmash
</Content>
</Note>
<Note>
<Version>1.1.1</Version>
<Content>
◾ Added NDB.Infrastructure.DatabaseMigration
◾ Added Netmash.Infrastructure.DatabaseMigration
◾ Organized sql scripts to meet database migrator requirements
</Content>
</Note>
@ -49,4 +49,15 @@
◾ Upgrade the migration service to version 1.1.0. Migration metadata is now stored in the sql server database.
</Content>
</Note>
<Note>
<Version>2.0.0</Version>
<Content>
◾ Tuitio rebranding
◾ .NET 6 upgrade
◾ Nuget packages upgrade
◾ Added Seq logging
◾ Refactoring and code cleanup
◾ Added README.md file
</Content>
</Note>
</ReleaseNotes>

View File

@ -5,37 +5,29 @@ VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5A8FF505-3E4D-4258-BC3E-CACD74A7B98C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer.Api", "IdentityServer.Api\IdentityServer.Api.csproj", "{2F84E560-EEC0-4511-B8D9-2C35C226B688}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tuitio", "src\Tuitio\Tuitio.csproj", "{2F84E560-EEC0-4511-B8D9-2C35C226B688}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0B8B6E9B-0200-47EC-91D9-BEDF4BFC248F}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution items", "solution items", "{0B8B6E9B-0200-47EC-91D9-BEDF4BFC248F}"
ProjectSection(SolutionItems) = preProject
.dockerignore = .dockerignore
.gitattributes = .gitattributes
.gitignore = .gitignore
dependencies.props = dependencies.props
Directory.Build.props = Directory.Build.props
Documentation.md = Documentation.md
Notes.txt = Notes.txt
NuGet.config = NuGet.config
ReleaseNotes.xml = ReleaseNotes.xml
README.md = README.md
ReleaseNotes.xml = ReleaseNotes.xml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer.Application", "IdentityServer.Application\IdentityServer.Application.csproj", "{6556D255-AF22-478E-A71A-BE37C16D5EE4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tuitio.Application", "src\Tuitio.Application\Tuitio.Application.csproj", "{6556D255-AF22-478E-A71A-BE37C16D5EE4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer.Domain", "IdentityServer.Domain\IdentityServer.Domain.csproj", "{5890B079-3CB0-4AD6-8809-BB2E081590B1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tuitio.Domain", "src\Tuitio.Domain\Tuitio.Domain.csproj", "{5890B079-3CB0-4AD6-8809-BB2E081590B1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer.Domain.Data", "IdentityServer.Domain.Data\IdentityServer.Domain.Data.csproj", "{CE81A435-49AC-4544-A381-FAC91BEB3C49}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tuitio.Domain.Data", "src\Tuitio.Domain.Data\Tuitio.Domain.Data.csproj", "{CE81A435-49AC-4544-A381-FAC91BEB3C49}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer.PublishedLanguage", "IdentityServer.PublishedLanguage\IdentityServer.PublishedLanguage.csproj", "{67B4D1FF-D02E-4DA6-9FB8-F71667360448}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tuitio.PublishedLanguage", "src\Tuitio.PublishedLanguage\Tuitio.PublishedLanguage.csproj", "{67B4D1FF-D02E-4DA6-9FB8-F71667360448}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer.Wrapper", "IdentityServer.Wrapper\IdentityServer.Wrapper.csproj", "{F6FEC33B-C79E-4484-B356-9C7F1A5E5D95}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{5A9268B6-F73B-4773-86BF-45DFF7EF75F7}"
ProjectSection(SolutionItems) = preProject
build-amd64.sh = build-amd64.sh
release.sh = release.sh
EndProjectSection
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tuitio.Wrapper", "src\Tuitio.Wrapper\Tuitio.Wrapper.csproj", "{F6FEC33B-C79E-4484-B356-9C7F1A5E5D95}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -78,7 +70,6 @@ Global
{CE81A435-49AC-4544-A381-FAC91BEB3C49} = {5A8FF505-3E4D-4258-BC3E-CACD74A7B98C}
{67B4D1FF-D02E-4DA6-9FB8-F71667360448} = {5A8FF505-3E4D-4258-BC3E-CACD74A7B98C}
{F6FEC33B-C79E-4484-B356-9C7F1A5E5D95} = {5A8FF505-3E4D-4258-BC3E-CACD74A7B98C}
{5A9268B6-F73B-4773-86BF-45DFF7EF75F7} = {0B8B6E9B-0200-47EC-91D9-BEDF4BFC248F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E93DC46D-9C55-4A05-B299-497CDD90747E}

View File

@ -1,23 +0,0 @@
#!/bin/bash
# chmod u+x build-amd64.sh
echo "Welcome!"
version="1.1.3-alpha3"
localRegistryPass="************"
echo "Create docker image with version $version."
docker image build -t "identity-server:$version" -f "IdentityServer.Api/Dockerfile" .
echo "Tag docker image with registry prefix."
docker tag identity-server:$version alpine-nexus:8500/identity/identity-server:$version
echo "Login to alpine-nexus registry."
docker login --username=admin --password=$localRegistryPass alpine-nexus:8500
echo "Push image alpine-nexus:8500/identity/identity-server:$version to registry."
docker push alpine-nexus:8500/identity/identity-server:$version
echo "Remove image alpine-nexus:8500/identity/identity-server:$version from local machine."
docker rmi alpine-nexus:8500/identity/identity-server:$version
echo "DONE!"

View File

@ -1,17 +1,16 @@
<Project>
<PropertyGroup Label="Package Versions">
<MicrosoftExtensionsPackageVersion>5.0.0</MicrosoftExtensionsPackageVersion>
<SerilogPackageVersion>4.1.0</SerilogPackageVersion>
<SerilogExtensionsPackageVersion>3.1.0</SerilogExtensionsPackageVersion>
<SerilogSinksConsolePackageVersion>4.0.0</SerilogSinksConsolePackageVersion>
<MicrosoftExtensionsPackageVersion>6.0.0</MicrosoftExtensionsPackageVersion>
<SerilogPackageVersion>6.1.0</SerilogPackageVersion>
<SerilogSinksSeqPackageVersion>5.2.2</SerilogSinksSeqPackageVersion>
<SerilogSinksMSSqlServerPackageVersion>5.6.1</SerilogSinksMSSqlServerPackageVersion>
<AutoMapperPackageVersion>10.1.1</AutoMapperPackageVersion>
<AutoMapperExtensionsPackageVersion>8.1.1</AutoMapperExtensionsPackageVersion>
<MediatRPackageVersion>6.0.0</MediatRPackageVersion>
<SwashbucklePackageVersion>5.3.1</SwashbucklePackageVersion>
<EntityFrameworkCorePackageVersion>5.0.12</EntityFrameworkCorePackageVersion>
<NDBExtensionsSwaggerPackageVersion>1.0.2</NDBExtensionsSwaggerPackageVersion>
<NDBApplicationPackageVersion>1.0.0</NDBApplicationPackageVersion>
<NDBDatabaseMigrationPackageVersion>1.1.3</NDBDatabaseMigrationPackageVersion>
<AutoMapperPackageVersion>12.0.1</AutoMapperPackageVersion>
<AutoMapperExtensionsPackageVersion>12.0.0</AutoMapperExtensionsPackageVersion>
<MediatRPackageVersion>9.0.0</MediatRPackageVersion>
<EntityFrameworkCorePackageVersion>6.0.1</EntityFrameworkCorePackageVersion>
<NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
<NetmashExtensionsSwaggerPackageVersion>1.0.6</NetmashExtensionsSwaggerPackageVersion>
<NetmashDatabaseMigrationPackageVersion>1.2.0</NetmashDatabaseMigrationPackageVersion>
<NetmashExtensionsHttpPackageVersion>1.0.0</NetmashExtensionsHttpPackageVersion>
</PropertyGroup>
</Project>

View File

@ -1,23 +0,0 @@
#!/bin/sh
echo "Welcome!"
version="1.1.3"
oldver="1.1.2"
echo "Pull docker image identity-server:$version from registry."
docker pull alpine-nexus:8500/identity/identity-server:$version
echo "Stop old container."
docker stop identity-server && docker rm identity-server
echo "Run new container."
docker run -d --name identity-server --restart=always --memory 500mb --memory-reservation 100mb -p 5007:80 alpine-nexus:8500/identity/identity-server:$version
# https://phoenixnap.com/kb/docker-memory-and-cpu-limit
echo "Remove old image identity-server:$oldver."
docker rmi alpine-nexus:8500/identity/identity-server:$oldver
echo "Get container logs:"
docker logs identity-server
echo "DONE!"

View File

@ -1,15 +1,15 @@
using AutoMapper;
using IdentityServer.Application.Commands;
using IdentityServer.Application.Services;
using IdentityServer.PublishedLanguage.Constants;
using IdentityServer.PublishedLanguage.Dto;
using IdentityServer.PublishedLanguage.Events;
using Tuitio.Application.Commands;
using Tuitio.Application.Services;
using Tuitio.PublishedLanguage.Constants;
using Tuitio.PublishedLanguage.Dto;
using Tuitio.PublishedLanguage.Events;
using MediatR;
using Microsoft.Extensions.Logging;
using System.Threading;
using System.Threading.Tasks;
namespace IdentityServer.Application.CommandHandlers
namespace Tuitio.Application.CommandHandlers
{
public class AuthenticateUserHandler : IRequestHandler<AuthenticateUser, AuthenticateUserResult>
{

View File

@ -1,13 +1,13 @@
using AutoMapper;
using IdentityServer.Application.Commands;
using IdentityServer.Application.Services;
using IdentityServer.PublishedLanguage.Dto;
using Tuitio.Application.Commands;
using Tuitio.Application.Services;
using Tuitio.PublishedLanguage.Dto;
using MediatR;
using Microsoft.Extensions.Logging;
using System.Threading;
using System.Threading.Tasks;
namespace IdentityServer.Application.CommandHandlers
namespace Tuitio.Application.CommandHandlers
{
public class AuthorizeTokenHandler : IRequestHandler<AuthorizeToken, TokenCore>
{

View File

@ -0,0 +1,11 @@
using MediatR;
using Tuitio.PublishedLanguage.Events;
namespace Tuitio.Application.Commands
{
public class AuthenticateUser : IRequest<AuthenticateUserResult>
{
public string UserName { get; set; }
public string Password { get; set; }
}
}

View File

@ -0,0 +1,10 @@
using MediatR;
using Tuitio.PublishedLanguage.Dto;
namespace Tuitio.Application.Commands
{
public class AuthorizeToken : IRequest<TokenCore>
{
public string Token { get; set; }
}
}

View File

@ -1,10 +1,10 @@
using IdentityServer.Application.Services;
using IdentityServer.Application.Services.Abstractions;
using IdentityServer.Application.Stores;
using IdentityServer.Domain.Abstractions;
using Tuitio.Application.Services;
using Tuitio.Application.Services.Abstractions;
using Tuitio.Application.Stores;
using Tuitio.Domain.Abstractions;
using Microsoft.Extensions.DependencyInjection;
namespace IdentityServer.Application
namespace Tuitio.Application
{
public static class DependencyInjectionExtensions
{

View File

@ -1,10 +1,10 @@
using AutoMapper;
using IdentityServer.Domain.Entities;
using Tuitio.Domain.Entities;
using System.Collections.Generic;
using dto = IdentityServer.PublishedLanguage.Dto;
using models = IdentityServer.Domain.Models;
using dto = Tuitio.PublishedLanguage.Dto;
using models = Tuitio.Domain.Models;
namespace IdentityServer.Application.Mappings
namespace Tuitio.Application.Mappings
{
public class MappingProfile : Profile
{

View File

@ -1,4 +1,4 @@
namespace IdentityServer.Application.Services.Abstractions
namespace Tuitio.Application.Services.Abstractions
{
public interface IBehaviorService
{

View File

@ -1,4 +1,4 @@
namespace IdentityServer.Application.Services.Abstractions
namespace Tuitio.Application.Services.Abstractions
{
internal interface IHashingService
{

View File

@ -1,14 +1,14 @@
using IdentityServer.Application.Services.Abstractions;
using IdentityServer.Application.Stores;
using IdentityServer.Domain.Entities;
using IdentityServer.Domain.Models;
using IdentityServer.Domain.Repositories;
using Tuitio.Application.Services.Abstractions;
using Tuitio.Application.Stores;
using Tuitio.Domain.Entities;
using Tuitio.Domain.Models;
using Tuitio.Domain.Repositories;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
namespace IdentityServer.Application.Services
namespace Tuitio.Application.Services
{
internal class BehaviorService : IBehaviorService
{

View File

@ -1,8 +1,8 @@
using IdentityServer.Domain.Abstractions;
using IdentityServer.Domain.Models.Config;
using Tuitio.Domain.Abstractions;
using Tuitio.Domain.Models.Config;
using Microsoft.Extensions.Configuration;
namespace IdentityServer.Application.Services
namespace Tuitio.Application.Services
{
internal class ConfigProvider : IConfigProvider
{

View File

@ -1,9 +1,9 @@
using IdentityServer.Application.Services.Abstractions;
using Tuitio.Application.Services.Abstractions;
using System;
using System.Security.Authentication;
using System.Security.Cryptography;
namespace IdentityServer.Application.Services
namespace Tuitio.Application.Services
{
internal class HashingService : IHashingService
{

View File

@ -1,7 +1,7 @@
using IdentityServer.Domain.Entities;
using IdentityServer.Domain.Models;
using Tuitio.Domain.Entities;
using Tuitio.Domain.Models;
namespace IdentityServer.Application.Services
namespace Tuitio.Application.Services
{
internal interface ITokenService
{

View File

@ -1,7 +1,7 @@
using IdentityServer.Domain.Models;
using Tuitio.Domain.Models;
using System.Threading.Tasks;
namespace IdentityServer.Application.Services
namespace Tuitio.Application.Services
{
public interface IUserService
{

View File

@ -1,13 +1,13 @@
using AutoMapper;
using IdentityServer.Domain.Abstractions;
using IdentityServer.Domain.Entities;
using IdentityServer.Domain.Models;
using Tuitio.Domain.Abstractions;
using Tuitio.Domain.Entities;
using Tuitio.Domain.Models;
using Newtonsoft.Json;
using System;
using System.Text;
using System.Text.RegularExpressions;
namespace IdentityServer.Application.Services
namespace Tuitio.Application.Services
{
internal class TokenService : ITokenService
{

View File

@ -1,13 +1,13 @@
using IdentityServer.Application.Services.Abstractions;
using IdentityServer.Application.Stores;
using IdentityServer.Domain.Abstractions;
using IdentityServer.Domain.Entities;
using IdentityServer.Domain.Models;
using IdentityServer.Domain.Repositories;
using Tuitio.Application.Services.Abstractions;
using Tuitio.Application.Stores;
using Tuitio.Domain.Abstractions;
using Tuitio.Domain.Entities;
using Tuitio.Domain.Models;
using Tuitio.Domain.Repositories;
using System;
using System.Threading.Tasks;
namespace IdentityServer.Application.Services
namespace Tuitio.Application.Services
{
internal class UserService : IUserService
{

View File

@ -1,6 +1,6 @@
using IdentityServer.Domain.Models;
using Tuitio.Domain.Models;
namespace IdentityServer.Application.Stores
namespace Tuitio.Application.Stores
{
internal interface ITokenStore
{

View File

@ -1,10 +1,10 @@
using IdentityServer.Application.Services;
using IdentityServer.Domain.Models;
using Tuitio.Application.Services;
using Tuitio.Domain.Models;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
namespace IdentityServer.Application.Stores
namespace Tuitio.Application.Stores
{
internal class TokenStore : ITokenStore
{

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
@ -11,13 +11,12 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="NDB.Application.DataContracts" Version="$(NDBApplicationPackageVersion)" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IdentityServer.Domain\IdentityServer.Domain.csproj" />
<ProjectReference Include="..\IdentityServer.PublishedLanguage\IdentityServer.PublishedLanguage.csproj" />
<ProjectReference Include="..\Tuitio.Domain\Tuitio.Domain.csproj" />
<ProjectReference Include="..\Tuitio.PublishedLanguage\Tuitio.PublishedLanguage.csproj" />
</ItemGroup>
</Project>

View File

@ -1,8 +1,8 @@
using IdentityServer.Domain.Data.EntityTypeConfiguration;
using IdentityServer.Domain.Entities;
using Tuitio.Domain.Data.EntityTypeConfiguration;
using Tuitio.Domain.Entities;
using Microsoft.EntityFrameworkCore;
namespace IdentityServer.Domain.Data.DbContexts
namespace Tuitio.Domain.Data.DbContexts
{
public class IdentityDbContext : DbContext
{

View File

@ -1,11 +1,11 @@
using IdentityServer.Domain.Data.DbContexts;
using IdentityServer.Domain.Data.Repositories;
using IdentityServer.Domain.Repositories;
using Tuitio.Domain.Data.DbContexts;
using Tuitio.Domain.Data.Repositories;
using Tuitio.Domain.Repositories;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
namespace IdentityServer.Domain.Data
namespace Tuitio.Domain.Data
{
public static class DependencyInjectionExtensions
{

View File

@ -1,8 +1,8 @@
using IdentityServer.Domain.Entities;
using Tuitio.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace IdentityServer.Domain.Data.EntityTypeConfiguration
namespace Tuitio.Domain.Data.EntityTypeConfiguration
{
class AppUserConfiguration : IEntityTypeConfiguration<AppUser>
{

View File

@ -1,8 +1,8 @@
using IdentityServer.Domain.Entities;
using Tuitio.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace IdentityServer.Domain.Data.EntityTypeConfiguration
namespace Tuitio.Domain.Data.EntityTypeConfiguration
{
class UserClaimConfiguration : IEntityTypeConfiguration<UserClaim>
{

View File

@ -1,8 +1,8 @@
using IdentityServer.Domain.Entities;
using Tuitio.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace IdentityServer.Domain.Data.EntityTypeConfiguration
namespace Tuitio.Domain.Data.EntityTypeConfiguration
{
class UserStatusConfiguration : IEntityTypeConfiguration<UserStatus>
{

View File

@ -1,8 +1,8 @@
using IdentityServer.Domain.Entities;
using Tuitio.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace IdentityServer.Domain.Data.EntityTypeConfiguration
namespace Tuitio.Domain.Data.EntityTypeConfiguration
{
class UserTokenConfiguration : IEntityTypeConfiguration<UserToken>
{

View File

@ -1,13 +1,13 @@
using IdentityServer.Domain.Data.DbContexts;
using IdentityServer.Domain.Entities;
using IdentityServer.Domain.Models;
using IdentityServer.Domain.Repositories;
using Tuitio.Domain.Data.DbContexts;
using Tuitio.Domain.Entities;
using Tuitio.Domain.Models;
using Tuitio.Domain.Repositories;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace IdentityServer.Domain.Data.Repositories
namespace Tuitio.Domain.Data.Repositories
{
class IdentityRepository : IIdentityRepository
{

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IdentityServer.Domain\IdentityServer.Domain.csproj" />
<ProjectReference Include="..\Tuitio.Domain\Tuitio.Domain.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -1,6 +1,6 @@
using IdentityServer.Domain.Models.Config;
using Tuitio.Domain.Models.Config;
namespace IdentityServer.Domain.Abstractions
namespace Tuitio.Domain.Abstractions
{
public interface IConfigProvider
{

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace IdentityServer.Domain.Entities
namespace Tuitio.Domain.Entities
{
public class AppUser
{

View File

@ -1,4 +1,4 @@
namespace IdentityServer.Domain.Entities
namespace Tuitio.Domain.Entities
{
public class UserClaim
{

View File

@ -1,4 +1,4 @@
namespace IdentityServer.Domain.Entities
namespace Tuitio.Domain.Entities
{
public class UserStatus
{

View File

@ -1,6 +1,6 @@
using System;
namespace IdentityServer.Domain.Entities
namespace Tuitio.Domain.Entities
{
public class UserToken
{

View File

@ -1,4 +1,4 @@
namespace IdentityServer.Domain.Models.Config
namespace Tuitio.Domain.Models.Config
{
public class RestrictionsConfig
{

View File

@ -1,4 +1,4 @@
namespace IdentityServer.Domain.Models.Config
namespace Tuitio.Domain.Models.Config
{
public class TokenConfig
{

View File

@ -1,6 +1,6 @@
using System;
namespace IdentityServer.Domain.Models
namespace Tuitio.Domain.Models
{
public class Token
{

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace IdentityServer.Domain.Models
namespace Tuitio.Domain.Models
{
public class TokenCore
{

View File

@ -1,8 +1,8 @@
using IdentityServer.Domain.Entities;
using IdentityServer.Domain.Models;
using Tuitio.Domain.Entities;
using Tuitio.Domain.Models;
using System.Threading.Tasks;
namespace IdentityServer.Domain.Repositories
namespace Tuitio.Domain.Repositories
{
public interface IIdentityRepository
{

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>

View File

@ -1,4 +1,4 @@
namespace IdentityServer.PublishedLanguage.Constants
namespace Tuitio.PublishedLanguage.Constants
{
public struct AuthenticationStatus
{

View File

@ -1,6 +1,6 @@
using System;
namespace IdentityServer.PublishedLanguage.Dto
namespace Tuitio.PublishedLanguage.Dto
{
public class Token
{

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace IdentityServer.PublishedLanguage.Dto
namespace Tuitio.PublishedLanguage.Dto
{
public class TokenCore
{

View File

@ -1,6 +1,6 @@
using IdentityServer.PublishedLanguage.Dto;
using Tuitio.PublishedLanguage.Dto;
namespace IdentityServer.PublishedLanguage.Events
namespace Tuitio.PublishedLanguage.Events
{
public class AuthenticateUserResult
{

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Description>Tuitio published language package</Description>
<PackageProjectUrl>https://lab.code-rove.com/gitea/tudor.stanciu/tuitio</PackageProjectUrl>
<RepositoryUrl>https://lab.code-rove.com/gitea/tudor.stanciu/tuitio</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<PackageReleaseNotes>Tuitio published language package</PackageReleaseNotes>
<Version>2.0.0</Version>
</PropertyGroup>
</Project>

View File

@ -1,4 +1,4 @@
namespace IdentityServer.Wrapper.Constants
namespace Tuitio.Wrapper.Constants
{
internal struct ApiRoutes
{

View File

@ -1,8 +1,8 @@
using IdentityServer.Wrapper.Models;
using IdentityServer.Wrapper.Services;
using Tuitio.Wrapper.Models;
using Tuitio.Wrapper.Services;
using Microsoft.Extensions.DependencyInjection;
namespace IdentityServer.Wrapper
namespace Tuitio.Wrapper
{
public static class DependencyInjectionExtension
{

View File

@ -1,4 +1,4 @@
namespace IdentityServer.Wrapper.Models
namespace Tuitio.Wrapper.Models
{
internal class ServiceConfiguration
{

View File

@ -1,7 +1,7 @@
using IdentityServer.PublishedLanguage.Dto;
using Tuitio.PublishedLanguage.Dto;
using System.Threading.Tasks;
namespace IdentityServer.Wrapper.Services
namespace Tuitio.Wrapper.Services
{
public interface IIdentityService
{

View File

@ -1,13 +1,13 @@
using IdentityServer.PublishedLanguage.Dto;
using IdentityServer.Wrapper.Constants;
using IdentityServer.Wrapper.Models;
using NDB.Extensions.Http;
using Tuitio.PublishedLanguage.Dto;
using Tuitio.Wrapper.Constants;
using Tuitio.Wrapper.Models;
using Netmash.Extensions.Http;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace IdentityServer.Wrapper.Services
namespace Tuitio.Wrapper.Services
{
internal class IdentityService : IIdentityService
{

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Description>Tuitio wrapper</Description>
<PackageReleaseNotes>Tuitio wrapper</PackageReleaseNotes>
<PackageProjectUrl>https://lab.code-rove.com/gitea/tudor.stanciu/tuitio</PackageProjectUrl>
<RepositoryType>Git</RepositoryType>
<RepositoryUrl>https://lab.code-rove.com/gitea/tudor.stanciu/tuitio</RepositoryUrl>
<PackageTags>Tuitio wrapper</PackageTags>
<Version>2.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Netmash.Extensions.Http" Version="$(NetmashExtensionsHttpPackageVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tuitio.PublishedLanguage\Tuitio.PublishedLanguage.csproj" />
</ItemGroup>
</Project>

View File

@ -1,9 +1,9 @@
using IdentityServer.Application.Commands;
using Tuitio.Application.Commands;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
namespace IdentityServer.Api.Controllers
namespace Tuitio.Api.Controllers
{
[ApiController]
[Route("identity")]

View File

@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
namespace IdentityServer.Api.Controllers
namespace Tuitio.Api.Controllers
{
[ApiController]
[Route("system")]

36
src/Tuitio/Dockerfile Normal file
View File

@ -0,0 +1,36 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /workspace
COPY ["dependencies.props", "."]
COPY ["Directory.Build.props", "."]
COPY ["NuGet.config", "."]
COPY ["src/Tuitio/Tuitio.csproj", "src/Tuitio/"]
COPY ["src/Tuitio.Application/Tuitio.Application.csproj", "src/Tuitio.Application/"]
COPY ["src/Tuitio.Domain/Tuitio.Domain.csproj", "src/Tuitio.Domain/"]
COPY ["src/Tuitio.PublishedLanguage/Tuitio.PublishedLanguage.csproj", "src/Tuitio.PublishedLanguage/"]
COPY ["src/Tuitio.Domain.Data/Tuitio.Domain.Data.csproj", "src/Tuitio.Domain.Data/"]
RUN dotnet restore "src/Tuitio/Tuitio.csproj"
COPY . .
WORKDIR "/workspace/src/Tuitio"
RUN dotnet build "Tuitio.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Tuitio.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV Urls="http://*:80"
ENV TZ=Europe/Bucharest
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
#Workaround to lower the TLS level in container for old sql server version
RUN sed -i 's/TLSv1.2/TLSv1.0/g' /etc/ssl/openssl.cnf
ENTRYPOINT ["dotnet", "Tuitio.dll"]

View File

@ -0,0 +1,8 @@
namespace Tuitio.Extensions
{
internal static class DataTypeExtensions
{
public static string Nullify(this string value)
=> string.IsNullOrWhiteSpace(value) ? null : value;
}
}

View File

@ -0,0 +1,41 @@
using Microsoft.Extensions.Configuration;
using Serilog;
using Serilog.Configuration;
using Serilog.Sinks.MSSqlServer;
using System;
namespace Tuitio.Extensions
{
internal static class LoggingExtensions
{
internal static LoggerSinkConfiguration ConfiguredDestinations(this LoggerSinkConfiguration writeTo, IConfiguration configuration)
{
var sqlServerEnabled = configuration.GetValue<bool>("Logs:SqlServer:Enabled");
var sqlServerConnection = configuration.GetValue<string>("Logs:SqlServer:Connection");
var seqEnabled = configuration.GetValue<bool>("Logs:Seq:Enabled");
var seqUrl = configuration.GetValue<string>("Logs:Seq:Url");
var seqApiKey = configuration.GetValue<string>("Logs:Seq:ApiKey");
if (sqlServerEnabled && string.IsNullOrWhiteSpace(sqlServerConnection))
throw new Exception("If SqlServer logging is enabled, the SqlServer connection must be configured.");
if (seqEnabled && string.IsNullOrWhiteSpace(seqUrl))
throw new Exception("If Seq logging is enabled, the Seq URL must be configured.");
if (sqlServerEnabled)
{
var columnOptions = new ColumnOptions();
columnOptions.Store.Remove(StandardColumn.Properties);
columnOptions.Store.Remove(StandardColumn.MessageTemplate);
columnOptions.Store.Add(StandardColumn.LogEvent);
var mssqlSinkOptions = new MSSqlServerSinkOptions() { AutoCreateSqlTable = true, TableName = "__Logs" };
writeTo.MSSqlServer(sqlServerConnection, mssqlSinkOptions, columnOptions: columnOptions);
}
if (seqEnabled)
writeTo.Seq(seqUrl, apiKey: seqApiKey.Nullify());
return writeTo;
}
}
}

View File

@ -0,0 +1,62 @@
using MediatR;
using MediatR.Pipeline;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Netmash.Extensions.Swagger;
using Netmash.Extensions.Swagger.Constants;
using Netmash.Infrastructure.DatabaseMigration;
using Netmash.Infrastructure.DatabaseMigration.Constants;
using Tuitio.Application;
using Tuitio.Application.Services.Abstractions;
using Tuitio.Domain.Data;
namespace Tuitio.Extensions
{
public static class StartupExtensions
{
public static void ConfigureServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddControllers();
// MediatR
services.AddMediatR(typeof(Application.Commands.AuthenticateUser).Assembly);
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(RequestPreProcessorBehavior<,>));
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(RequestPostProcessorBehavior<,>));
// AutoMapper
services.AddAutoMapper(
typeof(Application.Mappings.MappingProfile).Assembly);
// Swagger
services.AddSwagger("Tuitio API", AuthorizationType.None);
// Data access
services.AddMigration(DatabaseType.SQLServer, MetadataLocation.Database);
services.AddDataAccess();
// Application
services.AddApplicationServices();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public static void Configure(this WebApplication app)
{
// global cors policy
app.UseCors(z => z.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.ConfigureSwagger("Tuitio API");
app.UseMigration();
var behaviorService = app.Services.GetService<IBehaviorService>();
behaviorService.FillTokenStore();
}
}
}

48
src/Tuitio/Program.cs Normal file
View File

@ -0,0 +1,48 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Serilog;
using System;
using Tuitio.Extensions;
namespace Tuitio.Api
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((_, loggerConfiguration) =>
{
loggerConfiguration
.ReadFrom.Configuration(builder.Configuration)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.ConfiguredDestinations(builder.Configuration);
});
builder.Services.ConfigureServices(builder.Configuration);
var app = builder.Build();
app.Configure();
try
{
var urls = builder.Configuration.GetValue<string>("Urls");
Log.Information("Starting Tuitio API...");
Log.Information($"API listening on {urls}");
Console.WriteLine("Application started. Press Ctrl+C to shut down.");
app.Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Tuitio API host terminated unexpectedly");
}
finally
{
Log.CloseAndFlush();
}
}
}
}

View File

@ -1,6 +1,6 @@
{
"profiles": {
"IdentityServer.Api": {
"Tuitio.Api": {
"commandName": "Project",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {

View File

@ -1,30 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="NDB.Extensions.Swagger" Version="$(NDBExtensionsSwaggerPackageVersion)" />
<PackageReference Include="NDB.Infrastructure.DatabaseMigration" Version="$(NDBDatabaseMigrationPackageVersion)" />
<PackageReference Include="Netmash.Extensions.Swagger" Version="$(NetmashExtensionsSwaggerPackageVersion)" />
<PackageReference Include="Netmash.Infrastructure.DatabaseMigration" Version="$(NetmashDatabaseMigrationPackageVersion)" />
<PackageReference Include="Serilog.AspNetCore" Version="$(SerilogPackageVersion)" />
<PackageReference Include="Serilog.Extensions.Logging" Version="$(SerilogExtensionsPackageVersion)" />
<PackageReference Include="Serilog.Sinks.Console" Version="$(SerilogSinksConsolePackageVersion)" />
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="$(SerilogSinksMSSqlServerPackageVersion)" />
<PackageReference Include="Serilog.Sinks.Seq" Version="$(SerilogSinksSeqPackageVersion)" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="$(AutoMapperExtensionsPackageVersion)" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="$(MediatRPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="$(MicrosoftExtensionsPackageVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IdentityServer.Application\IdentityServer.Application.csproj" />
<ProjectReference Include="..\IdentityServer.Domain.Data\IdentityServer.Domain.Data.csproj" />
<ProjectReference Include="..\Tuitio.Application\Tuitio.Application.csproj" />
<ProjectReference Include="..\Tuitio.Domain.Data\Tuitio.Domain.Data.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,32 @@
{
"Urls": "http://*:5063",
"ConnectionStrings": {
"DatabaseConnection": "Server=######;Database=######;User Id=######;Password=######;MultipleActiveResultSets=true"
},
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Information"
}
}
},
"Logs": {
"SqlServer": {
"Enabled": false,
"Connection": "Server=#########;Database=#########;User Id=#########;Password=#########;MultipleActiveResultSets=true"
},
"Seq": {
"Enabled": false,
"Url": "",
"ApiKey": ""
}
},
"AllowedHosts": "*",
"Restrictions": {
"MaxFailedLoginAttempts": 5
},
"Token": {
"ValidityInMinutes": 43800
}
}