wip: JWT
This commit is contained in:
22
Auths.sln
22
Auths.sln
@@ -6,6 +6,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cookie.Basic", "Cookie.Basi
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cookie.BuiltIn", "Cookie.BuiltIn\Cookie.BuiltIn.csproj", "{63CE5DC9-F976-430B-8B12-50FB3DA3F872}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cookie.BuiltIn", "Cookie.BuiltIn\Cookie.BuiltIn.csproj", "{63CE5DC9-F976-430B-8B12-50FB3DA3F872}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Cookies", "Cookies", "{A7B682CD-CF61-4684-977B-82E48A4051D8}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Jwts", "Jwts", "{29AFF1AF-FE18-491A-AFE1-CE2786187166}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jwt.Server", "Jwt.Server\Jwt.Server.csproj", "{BAD4810F-B60A-42F1-8176-649855B93794}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RsaKeyLoader", "RsaKeyLoader\RsaKeyLoader.csproj", "{579C8783-7E95-40F3-96F4-BEBFB40F2D38}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -24,5 +32,19 @@ Global
|
|||||||
{63CE5DC9-F976-430B-8B12-50FB3DA3F872}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{63CE5DC9-F976-430B-8B12-50FB3DA3F872}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{63CE5DC9-F976-430B-8B12-50FB3DA3F872}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{63CE5DC9-F976-430B-8B12-50FB3DA3F872}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{63CE5DC9-F976-430B-8B12-50FB3DA3F872}.Release|Any CPU.Build.0 = Release|Any CPU
|
{63CE5DC9-F976-430B-8B12-50FB3DA3F872}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{BAD4810F-B60A-42F1-8176-649855B93794}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{BAD4810F-B60A-42F1-8176-649855B93794}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{BAD4810F-B60A-42F1-8176-649855B93794}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{BAD4810F-B60A-42F1-8176-649855B93794}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{579C8783-7E95-40F3-96F4-BEBFB40F2D38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{579C8783-7E95-40F3-96F4-BEBFB40F2D38}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{579C8783-7E95-40F3-96F4-BEBFB40F2D38}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{579C8783-7E95-40F3-96F4-BEBFB40F2D38}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(NestedProjects) = preSolution
|
||||||
|
{3684B6DC-9301-496C-9832-FFC26084C496} = {A7B682CD-CF61-4684-977B-82E48A4051D8}
|
||||||
|
{63CE5DC9-F976-430B-8B12-50FB3DA3F872} = {A7B682CD-CF61-4684-977B-82E48A4051D8}
|
||||||
|
{BAD4810F-B60A-42F1-8176-649855B93794} = {29AFF1AF-FE18-491A-AFE1-CE2786187166}
|
||||||
|
{579C8783-7E95-40F3-96F4-BEBFB40F2D38} = {29AFF1AF-FE18-491A-AFE1-CE2786187166}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
14
Jwt.Server/Jwt.Server.csproj
Normal file
14
Jwt.Server/Jwt.Server.csproj
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.6"/>
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
6
Jwt.Server/Jwt.Server.http
Normal file
6
Jwt.Server/Jwt.Server.http
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
@Jwt.Server_HostAddress = http://localhost:5079
|
||||||
|
|
||||||
|
GET {{Jwt.Server_HostAddress}}/weatherforecast/
|
||||||
|
Accept: application/json
|
||||||
|
|
||||||
|
###
|
||||||
44
Jwt.Server/Program.cs
Normal file
44
Jwt.Server/Program.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
// Add services to the container.
|
||||||
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
builder.Services.AddSwaggerGen();
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
// Configure the HTTP request pipeline.
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
var summaries = new[]
|
||||||
|
{
|
||||||
|
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||||
|
};
|
||||||
|
|
||||||
|
app.MapGet("/weatherforecast", () =>
|
||||||
|
{
|
||||||
|
var forecast = Enumerable.Range(1, 5).Select(index =>
|
||||||
|
new WeatherForecast
|
||||||
|
(
|
||||||
|
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||||
|
Random.Shared.Next(-20, 55),
|
||||||
|
summaries[Random.Shared.Next(summaries.Length)]
|
||||||
|
))
|
||||||
|
.ToArray();
|
||||||
|
return forecast;
|
||||||
|
})
|
||||||
|
.WithName("GetWeatherForecast")
|
||||||
|
.WithOpenApi();
|
||||||
|
|
||||||
|
app.Run();
|
||||||
|
|
||||||
|
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
|
||||||
|
{
|
||||||
|
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||||
|
}
|
||||||
41
Jwt.Server/Properties/launchSettings.json
Normal file
41
Jwt.Server/Properties/launchSettings.json
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:65145",
|
||||||
|
"sslPort": 44390
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "http://localhost:5079",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"https": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "https://localhost:7256;http://localhost:5079",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"IIS Express": {
|
||||||
|
"commandName": "IISExpress",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Jwt.Server/appsettings.Development.json
Normal file
8
Jwt.Server/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Jwt.Server/appsettings.json
Normal file
9
Jwt.Server/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
||||||
5
RsaKeyLoader/Class1.cs
Normal file
5
RsaKeyLoader/Class1.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
namespace RsaKeyLoader;
|
||||||
|
|
||||||
|
public class Class1
|
||||||
|
{
|
||||||
|
}
|
||||||
13
RsaKeyLoader/KeyLoader.cs
Normal file
13
RsaKeyLoader/KeyLoader.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
|
namespace RsaKeyLoader;
|
||||||
|
|
||||||
|
public class KeyLoader
|
||||||
|
{
|
||||||
|
public void Generate(string path)
|
||||||
|
{
|
||||||
|
var rsaKey = RSA.Create();
|
||||||
|
var privateKey = rsaKey.ExportRSAPrivateKey();
|
||||||
|
File.WriteAllBytes(path, privateKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
RsaKeyLoader/RsaKeyLoader.csproj
Normal file
9
RsaKeyLoader/RsaKeyLoader.csproj
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user