Miscelanious trials
This commit is contained in:
commit
f99c97f392
33 changed files with 881 additions and 0 deletions
8
IdentityShroud.Api/AppJsonSerializerContext.cs
Normal file
8
IdentityShroud.Api/AppJsonSerializerContext.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using System.Text.Json.Serialization;
|
||||
using IdentityShroud.Core.Messages;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
|
||||
[JsonSerializable(typeof(OpenIdConfiguration))]
|
||||
internal partial class AppJsonSerializerContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
24
IdentityShroud.Api/IdentityShroud.Api.csproj
Normal file
24
IdentityShroud.Api/IdentityShroud.Api.csproj
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<PublishAot>true</PublishAot>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<UserSecretsId>6b8ef434-0577-4a3c-8749-6b547d7787c5</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0"/>
|
||||
<PackageReference Include="Serilog" Version="4.3.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
|
||||
<PackageReference Include="Serilog.Expressions" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\IdentityShroud.Core\IdentityShroud.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
11
IdentityShroud.Api/IdentityShroud.http
Normal file
11
IdentityShroud.Api/IdentityShroud.http
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
@IdentityShroud_HostAddress = http://localhost:5249
|
||||
|
||||
GET {{IdentityShroud_HostAddress}}/todos/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
GET {{IdentityShroud_HostAddress}}/todos/1
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
50
IdentityShroud.Api/Program.cs
Normal file
50
IdentityShroud.Api/Program.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using IdentityShroud.Api;
|
||||
using IdentityShroud.Core;
|
||||
using Serilog;
|
||||
using Serilog.Formatting.Json;
|
||||
|
||||
// Initial logging until we can set it up from Configuration
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console(new JsonFormatter())
|
||||
.CreateLogger();
|
||||
|
||||
var applicationBuilder = WebApplication.CreateSlimBuilder(args);
|
||||
ConfigureBuilder(applicationBuilder);
|
||||
var application = applicationBuilder.Build();
|
||||
ConfigureApplication(application);
|
||||
application.Run();
|
||||
|
||||
void ConfigureBuilder(WebApplicationBuilder builder)
|
||||
{
|
||||
var services = builder.Services;
|
||||
var configuration = builder.Configuration;
|
||||
|
||||
//services.AddControllers();
|
||||
services.ConfigureHttpJsonOptions(options =>
|
||||
{
|
||||
options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
|
||||
});
|
||||
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
services.AddOpenApi();
|
||||
services.AddScoped<Db>();
|
||||
services.AddOptions<DbConfiguration>().Bind(configuration.GetSection("db"));
|
||||
|
||||
builder.Host.UseSerilog((context, services, configuration) => configuration
|
||||
.Enrich.FromLogContext()
|
||||
//.Enrich.With<UserEnricher>()
|
||||
.ReadFrom.Configuration(context.Configuration));
|
||||
}
|
||||
|
||||
void ConfigureApplication(WebApplication app)
|
||||
{
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
}
|
||||
app.UseSerilogRequestLogging();
|
||||
app.MapRealmEndpoints();
|
||||
// app.UseRouting();
|
||||
// app.MapControllers();
|
||||
}
|
||||
15
IdentityShroud.Api/Properties/launchSettings.json
Normal file
15
IdentityShroud.Api/Properties/launchSettings.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "todos",
|
||||
"applicationUrl": "http://localhost:5249",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
94
IdentityShroud.Api/RealmController.cs
Normal file
94
IdentityShroud.Api/RealmController.cs
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
using IdentityShroud.Core.Messages;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
|
||||
namespace IdentityShroud.Api;
|
||||
|
||||
public static class RealmController
|
||||
{
|
||||
public static void MapRealmEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var realm = app.MapGroup("/realms/{slug}");
|
||||
|
||||
realm.MapGet("", GetRoot);
|
||||
realm.MapGet(".well-known/openid-configuration", GetOpenIdConfiguration);
|
||||
|
||||
var openidConnect = realm.MapGroup("openid-connect");
|
||||
openidConnect.MapPost("auth", OpenIdConnectAuth);
|
||||
openidConnect.MapPost("token", OpenIdConnectToken);
|
||||
openidConnect.MapGet("jwks", OpenIdConnectJwks);
|
||||
}
|
||||
|
||||
private static Task OpenIdConnectJwks(HttpContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static Task OpenIdConnectToken(HttpContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static Task OpenIdConnectAuth(HttpContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static async Task<Results<JsonHttpResult<OpenIdConfiguration>, BadRequest>> GetOpenIdConfiguration(string slug, HttpContext context)
|
||||
{
|
||||
if (string.IsNullOrEmpty(slug))
|
||||
return TypedResults.BadRequest();
|
||||
var s = $"{context.Request.Scheme}://{context.Request.Host}{context.Request.Path}";
|
||||
var searchString = $"realms/{slug}";
|
||||
int index = s.IndexOf(searchString, StringComparison.OrdinalIgnoreCase);
|
||||
string baseUri = s.Substring(0, index + searchString.Length);
|
||||
|
||||
return TypedResults.Json(new OpenIdConfiguration()
|
||||
{
|
||||
AuthorizationEndpoint = baseUri + "/openid-connect/auth",
|
||||
TokenEndpoint = baseUri + "/openid-connect/token",
|
||||
Issuer = baseUri,
|
||||
JwksUri = baseUri + "/openid-connect/jwks",
|
||||
}, AppJsonSerializerContext.Default.OpenIdConfiguration);
|
||||
}
|
||||
|
||||
private static string GetRoot()
|
||||
{
|
||||
return "Hello World!";
|
||||
|
||||
/* keycloak returns this
|
||||
{
|
||||
"realm": "mpluskassa",
|
||||
"public_key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApYbLAeOLDEwzL4tEwuE2LfisOBXoQqWA9RdP3ph6muwF1ErfhiBSIB2JETKf7F1OsiF1/qnuh4uDfn0TO8bK3lSfHTlIHWShwaJ/UegS9ylobfIYXJsz0xmJK5ToFaSYa72D/Dyln7ROxudu8+zc70sz7bUKQ0/ktWRsiu76vY6Kr9+18PgaooPmb2QP8lS8IZEv+gW5SLqoMc1DfD8lsih1sdnQ8W65cBsNnenkWc97AF9cMR6rdD2tZfLAxEHKYaohAL9EsQsLic3P2f2UaqRTAOvgqyYE5hyJROt7Pyeyi8YSy7zXD12h2mc0mrSoA+u7s/GrOLcLoLLgEnRRVwIDAQAB",
|
||||
"token-service": "https://iam.kassacloud.nl/auth/realms/mpluskassa/protocol/openid-connect",
|
||||
"account-service": "https://iam.kassacloud.nl/auth/realms/mpluskassa/account",
|
||||
"tokens-not-before": 0
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// [HttpGet("")]
|
||||
// public ActionResult Index()
|
||||
// {
|
||||
// return new JsonResult("Hello world!");
|
||||
// }
|
||||
|
||||
// [HttpGet("{slug}/.well-known/openid-configuration")]
|
||||
// public ActionResult GetOpenIdConfiguration(
|
||||
// string slug,
|
||||
// [FromServices]LinkGenerator linkGenerator)
|
||||
// {
|
||||
// var s = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{HttpContext.Request.Path}";
|
||||
// var searchString = $"realms/{slug}";
|
||||
// int index = s.IndexOf(searchString, StringComparison.OrdinalIgnoreCase);
|
||||
// string baseUri = s.Substring(0, index + searchString.Length);
|
||||
//
|
||||
// return new JsonResult(baseUri);
|
||||
// }
|
||||
|
||||
// [HttpPost("{slug}/protocol/openid-connect/token")]
|
||||
// public ActionResult GetOpenIdConnectToken(string slug)
|
||||
//
|
||||
// {
|
||||
// return new JsonResult("Hello world!");
|
||||
// }
|
||||
}
|
||||
11
IdentityShroud.Api/appsettings.Development.json
Normal file
11
IdentityShroud.Api/appsettings.Development.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"Db": {
|
||||
"LogSensitiveData": true
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
IdentityShroud.Api/appsettings.json
Normal file
9
IdentityShroud.Api/appsettings.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue