Skip to content
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
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
25 changes: 25 additions & 0 deletions AuthServer.NET.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30804.86
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AuthServer.NET", "AuthServer.NET\AuthServer.NET.csproj", "{9F7E0828-13F2-4FD4-BA16-32EE002D5644}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9F7E0828-13F2-4FD4-BA16-32EE002D5644}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F7E0828-13F2-4FD4-BA16-32EE002D5644}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F7E0828-13F2-4FD4-BA16-32EE002D5644}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F7E0828-13F2-4FD4-BA16-32EE002D5644}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2204BA38-D887-46F3-A0A7-C8D7B26D0AAB}
EndGlobalSection
EndGlobal
17 changes: 17 additions & 0 deletions AuthServer.NET/AuthServer.NET.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UserSecretsId>ed060827-b1b2-4d61-9069-6c8c27fdb09d</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
</ItemGroup>

<ItemGroup>
<Folder Include="Models\Entities\" />
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions AuthServer.NET/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using AuthServer.NET.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

namespace AuthServer.NET.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}

public IActionResult Index()
{
return View();
}

public IActionResult Privacy()
{
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
18 changes: 18 additions & 0 deletions AuthServer.NET/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using AuthServer.NET.Models.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AuthServer.NET.Data
{
public class ApplicationDbContext : DbContext
{
public DbSet<Client> Clients { get; set; }
public DbSet<ClientAuthCode> ClientsAuthCodes { get; set; }
public DbSet<ClientClientCredentials> ClientsClientCredentials { get; set; }
public DbSet<ClientImplicit> ClientsImplicit { get; set; }
public DbSet<ClientROPassword> ClientsROPassword{ get; set; }
}
}
22 changes: 22 additions & 0 deletions AuthServer.NET/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#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/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["AuthServer.NET/AuthServer.NET.csproj", "AuthServer.NET/"]
RUN dotnet restore "AuthServer.NET/AuthServer.NET.csproj"
COPY . .
WORKDIR "/src/AuthServer.NET"
RUN dotnet build "AuthServer.NET.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "AuthServer.NET.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "AuthServer.NET.dll"]
49 changes: 49 additions & 0 deletions AuthServer.NET/Middleware/ErrorHandlerMiddleware.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using AuthServer.NET.Models.Exceptions;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.Json;
using System.Threading.Tasks;

namespace AuthServer.NET.Middleware
{
public class ErrorHandlerMiddleware
{
private readonly RequestDelegate _next;

public ErrorHandlerMiddleware(RequestDelegate next)
{
_next = next;
}

public async Task Invoke(HttpContext context)
{
try
{
await _next(context);
}
catch (Exception ex)
{
var response = context.Response;
response.ContentType = "application/json";
switch (ex)
{
case AppException c:
break;
case KeyNotFoundException c:
response.StatusCode = (int)HttpStatusCode.NotFound;

break;

default:
response.StatusCode = (int)HttpStatusCode.InternalServerError;
break;
}
var result = JsonSerializer.Serialize(new { message = ex?.Message});
await response.WriteAsync(result);
}
}
}
}
17 changes: 17 additions & 0 deletions AuthServer.NET/Models/Entities/BaseEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;

namespace AuthServer.NET.Models.Entities
{
public abstract class BaseEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}
}
13 changes: 13 additions & 0 deletions AuthServer.NET/Models/Entities/Client.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;

namespace AuthServer.NET.Models.Entities
{
[Table("Clients")]
public abstract class Client: BaseEntity
{
}
}
11 changes: 11 additions & 0 deletions AuthServer.NET/Models/Entities/ClientAuthCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AuthServer.NET.Models.Entities
{
public class ClientAuthCode : Client
{
}
}
11 changes: 11 additions & 0 deletions AuthServer.NET/Models/Entities/ClientClientCredentials.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AuthServer.NET.Models.Entities
{
public class ClientClientCredentials : Client
{
}
}
11 changes: 11 additions & 0 deletions AuthServer.NET/Models/Entities/ClientImplicit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AuthServer.NET.Models.Entities
{
public class ClientImplicit : Client
{
}
}
11 changes: 11 additions & 0 deletions AuthServer.NET/Models/Entities/ClientROPassword.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AuthServer.NET.Models.Entities
{
public class ClientROPassword : Client
{
}
}
11 changes: 11 additions & 0 deletions AuthServer.NET/Models/ErrorViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace AuthServer.NET.Models
{
public class ErrorViewModel
{
public string RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}
24 changes: 24 additions & 0 deletions AuthServer.NET/Models/Exceptions/AppException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;

namespace AuthServer.NET.Models.Exceptions
{
public class AppException :Exception
{
public AppException () : base()
{

}
public AppException(string message) : base(message)
{

}
public AppException(string message, params object[] args): base(string.Format(CultureInfo.CurrentCulture, message,args))
{

}
}
}
26 changes: 26 additions & 0 deletions AuthServer.NET/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AuthServer.NET
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
34 changes: 34 additions & 0 deletions AuthServer.NET/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:2574",
"sslPort": 44395
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"AuthServer.NET": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"publishAllPorts": true,
"useSSL": true
}
}
}
Loading