Initial
This commit is contained in:
13
.idea/.idea.TimetableDesigner.API.Services.Authentication/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.TimetableDesigner.API.Services.Authentication/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Rider ignored files
|
||||||
|
/.idea.TimetableDesigner.API.Services.Authentication.iml
|
||||||
|
/projectSettingsUpdater.xml
|
||||||
|
/modules.xml
|
||||||
|
/contentModel.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
4
.idea/.idea.TimetableDesigner.API.Services.Authentication/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.TimetableDesigner.API.Services.Authentication/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||||
|
</project>
|
||||||
8
.idea/.idea.TimetableDesigner.API.Services.Authentication/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.TimetableDesigner.API.Services.Authentication/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="UserContentModel">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/.idea.TimetableDesigner.API.Services.Authentication/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.TimetableDesigner.API.Services.Authentication/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace TimetableDesigner.API.Services.Authentication.DTO;
|
||||||
|
|
||||||
|
public class AuthenticatePasswordRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace TimetableDesigner.API.Services.Authentication.DTO;
|
||||||
|
|
||||||
|
public class AuthenticateResponse
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace TimetableDesigner.API.Services.Authentication.DTO;
|
||||||
|
|
||||||
|
public class AuthenticateTokenRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace TimetableDesigner.API.Services.Authentication.DTO;
|
||||||
|
|
||||||
|
public class RegisterRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
22
TimetableDesigner.API.Services.Authentication.sln
Normal file
22
TimetableDesigner.API.Services.Authentication.sln
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimetableDesigner.API.Services.Authentication", "TimetableDesigner.API.Services.Authentication/TimetableDesigner.API.Services.Authentication.csproj", "{F8C0AEF3-B53F-4904-90F7-EE4A8587F023}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimetableDesigner.API.Services.Authentication.DTO", "TimetableDesigner.API.Services.Authentication.DTO\TimetableDesigner.API.Services.Authentication.DTO.csproj", "{384C8036-ACA7-40EB-924D-5E0271BEDB09}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{F8C0AEF3-B53F-4904-90F7-EE4A8587F023}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{F8C0AEF3-B53F-4904-90F7-EE4A8587F023}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{F8C0AEF3-B53F-4904-90F7-EE4A8587F023}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{F8C0AEF3-B53F-4904-90F7-EE4A8587F023}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{384C8036-ACA7-40EB-924D-5E0271BEDB09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{384C8036-ACA7-40EB-924D-5E0271BEDB09}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{384C8036-ACA7-40EB-924D-5E0271BEDB09}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{384C8036-ACA7-40EB-924D-5E0271BEDB09}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
25
TimetableDesigner.API.Services.Authentication/.dockerignore
Normal file
25
TimetableDesigner.API.Services.Authentication/.dockerignore
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
**/.dockerignore
|
||||||
|
**/.env
|
||||||
|
**/.git
|
||||||
|
**/.gitignore
|
||||||
|
**/.project
|
||||||
|
**/.settings
|
||||||
|
**/.toolstarget
|
||||||
|
**/.vs
|
||||||
|
**/.vscode
|
||||||
|
**/.idea
|
||||||
|
**/*.*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
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
|
using TimetableDesigner.API.Services.Authentication.DTO;
|
||||||
|
|
||||||
|
namespace TimetableDesigner.API.Services.Authentication.API;
|
||||||
|
|
||||||
|
public static class Endpoints
|
||||||
|
{
|
||||||
|
public static IEndpointRouteBuilder MapEndpoints(this IEndpointRouteBuilder app)
|
||||||
|
{
|
||||||
|
app.MapPost("/register", Register)
|
||||||
|
.WithName("Register");
|
||||||
|
app.MapPost("/authenticate_password", AuthenticatePassword)
|
||||||
|
.WithName("AuthenticatePassword");
|
||||||
|
app.MapPost("/authenticate_token", AuthenticateToken)
|
||||||
|
.WithName("AuthenticateToken");
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<Results<Ok<AuthenticateResponse>, ProblemHttpResult>> Register(RegisterRequest request)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<Results<Ok<AuthenticateResponse>, ProblemHttpResult>> AuthenticatePassword(AuthenticatePasswordRequest request)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<Results<Ok<AuthenticateResponse>, ProblemHttpResult>> AuthenticateToken(AuthenticateTokenRequest request)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using TimetableDesigner.API.Services.Authentication.Database.Model;
|
||||||
|
|
||||||
|
namespace TimetableDesigner.API.Services.Authentication.Database.Configuration;
|
||||||
|
|
||||||
|
public class AccountConfiguration : IEntityTypeConfiguration<Account>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<Account> builder)
|
||||||
|
{
|
||||||
|
builder.HasKey(x => x.Id);
|
||||||
|
builder.HasIndex(x => x.Id)
|
||||||
|
.IsUnique();
|
||||||
|
builder.Property(x => x.Id)
|
||||||
|
.IsRequired()
|
||||||
|
.UseIdentityAlwaysColumn();
|
||||||
|
|
||||||
|
builder.Property(x => x.Email)
|
||||||
|
.HasMaxLength(320)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(x => x.Password)
|
||||||
|
.HasMaxLength(1000)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(x => x.PasswordSaltLeft)
|
||||||
|
.HasMaxLength(20)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(x => x.PasswordSaltRight)
|
||||||
|
.HasMaxLength(20)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(b => b.Version)
|
||||||
|
.IsRowVersion();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using TimetableDesigner.API.Services.Authentication.Database.Model;
|
||||||
|
|
||||||
|
namespace TimetableDesigner.API.Services.Authentication.Database.Configuration;
|
||||||
|
|
||||||
|
public class RefreshTokenConfiguration : IEntityTypeConfiguration<RefreshToken>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<RefreshToken> builder)
|
||||||
|
{
|
||||||
|
builder.HasKey(x => x.Token);
|
||||||
|
builder.HasIndex(x => x.Token)
|
||||||
|
.IsUnique();
|
||||||
|
builder.Property(x => x.Token)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.HasOne(x => x.Account)
|
||||||
|
.WithMany(x => x.RefreshTokens)
|
||||||
|
.HasForeignKey(x => x.AccountId)
|
||||||
|
.IsRequired();
|
||||||
|
builder.Property(x => x.AccountId)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(x => x.ExpirationDate)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(x => x.IsExtendable)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(b => b.Version)
|
||||||
|
.IsRowVersion();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using TimetableDesigner.API.Services.Authentication.Database.Model;
|
||||||
|
|
||||||
|
namespace TimetableDesigner.API.Services.Authentication.Database;
|
||||||
|
|
||||||
|
public class DatabaseContext : DbContext
|
||||||
|
{
|
||||||
|
public virtual DbSet<Account> Accounts { get; set; }
|
||||||
|
public virtual DbSet<RefreshToken> RefreshTokens { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public DatabaseContext() { }
|
||||||
|
|
||||||
|
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options) { }
|
||||||
|
|
||||||
|
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) =>
|
||||||
|
optionsBuilder.UseNpgsql("name=Database");
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder) =>
|
||||||
|
modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetAssembly(typeof(DatabaseContext))!);
|
||||||
|
}
|
||||||
119
TimetableDesigner.API.Services.Authentication/Database/Migrations/20250924120541_Initial.Designer.cs
generated
Normal file
119
TimetableDesigner.API.Services.Authentication/Database/Migrations/20250924120541_Initial.Designer.cs
generated
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
using TimetableDesigner.API.Services.Authentication.Database;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace TimetableDesigner.API.Services.Authentication.Database.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DatabaseContext))]
|
||||||
|
[Migration("20250924120541_Initial")]
|
||||||
|
partial class Initial
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.9")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("TimetableDesigner.API.Services.Authentication.Database.Model.Account", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityAlwaysColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(320)
|
||||||
|
.HasColumnType("character varying(320)");
|
||||||
|
|
||||||
|
b.Property<byte[]>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(1000)
|
||||||
|
.HasColumnType("bytea");
|
||||||
|
|
||||||
|
b.Property<string>("PasswordSaltLeft")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(20)
|
||||||
|
.HasColumnType("character varying(20)");
|
||||||
|
|
||||||
|
b.Property<string>("PasswordSaltRight")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(20)
|
||||||
|
.HasColumnType("character varying(20)");
|
||||||
|
|
||||||
|
b.Property<uint>("Version")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.ValueGeneratedOnAddOrUpdate()
|
||||||
|
.HasColumnType("xid")
|
||||||
|
.HasColumnName("xmin");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Id")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Accounts");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("TimetableDesigner.API.Services.Authentication.Database.Model.RefreshToken", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Token")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<long>("AccountId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("ExpirationDate")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<bool>("IsExtendable")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<uint>("Version")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.ValueGeneratedOnAddOrUpdate()
|
||||||
|
.HasColumnType("xid")
|
||||||
|
.HasColumnName("xmin");
|
||||||
|
|
||||||
|
b.HasKey("Token");
|
||||||
|
|
||||||
|
b.HasIndex("AccountId");
|
||||||
|
|
||||||
|
b.HasIndex("Token")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("RefreshTokens");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("TimetableDesigner.API.Services.Authentication.Database.Model.RefreshToken", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("TimetableDesigner.API.Services.Authentication.Database.Model.Account", "Account")
|
||||||
|
.WithMany("RefreshTokens")
|
||||||
|
.HasForeignKey("AccountId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Account");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("TimetableDesigner.API.Services.Authentication.Database.Model.Account", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("RefreshTokens");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace TimetableDesigner.API.Services.Authentication.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Initial : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Accounts",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn),
|
||||||
|
Email = table.Column<string>(type: "character varying(320)", maxLength: 320, nullable: false),
|
||||||
|
Password = table.Column<byte[]>(type: "bytea", maxLength: 1000, nullable: false),
|
||||||
|
PasswordSaltLeft = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
||||||
|
PasswordSaltRight = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
||||||
|
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Accounts", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "RefreshTokens",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Token = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
AccountId = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
ExpirationDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||||
|
IsExtendable = table.Column<bool>(type: "boolean", nullable: false),
|
||||||
|
xmin = table.Column<uint>(type: "xid", rowVersion: true, nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_RefreshTokens", x => x.Token);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_RefreshTokens_Accounts_AccountId",
|
||||||
|
column: x => x.AccountId,
|
||||||
|
principalTable: "Accounts",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Accounts_Id",
|
||||||
|
table: "Accounts",
|
||||||
|
column: "Id",
|
||||||
|
unique: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_RefreshTokens_AccountId",
|
||||||
|
table: "RefreshTokens",
|
||||||
|
column: "AccountId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_RefreshTokens_Token",
|
||||||
|
table: "RefreshTokens",
|
||||||
|
column: "Token",
|
||||||
|
unique: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "RefreshTokens");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Accounts");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
using TimetableDesigner.API.Services.Authentication.Database;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace TimetableDesigner.API.Services.Authentication.Database.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DatabaseContext))]
|
||||||
|
partial class DatabaseContextModelSnapshot : ModelSnapshot
|
||||||
|
{
|
||||||
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.9")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("TimetableDesigner.API.Services.Authentication.Database.Model.Account", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityAlwaysColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(320)
|
||||||
|
.HasColumnType("character varying(320)");
|
||||||
|
|
||||||
|
b.Property<byte[]>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(1000)
|
||||||
|
.HasColumnType("bytea");
|
||||||
|
|
||||||
|
b.Property<string>("PasswordSaltLeft")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(20)
|
||||||
|
.HasColumnType("character varying(20)");
|
||||||
|
|
||||||
|
b.Property<string>("PasswordSaltRight")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(20)
|
||||||
|
.HasColumnType("character varying(20)");
|
||||||
|
|
||||||
|
b.Property<uint>("Version")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.ValueGeneratedOnAddOrUpdate()
|
||||||
|
.HasColumnType("xid")
|
||||||
|
.HasColumnName("xmin");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Id")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Accounts");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("TimetableDesigner.API.Services.Authentication.Database.Model.RefreshToken", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Token")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<long>("AccountId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("ExpirationDate")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<bool>("IsExtendable")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<uint>("Version")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.ValueGeneratedOnAddOrUpdate()
|
||||||
|
.HasColumnType("xid")
|
||||||
|
.HasColumnName("xmin");
|
||||||
|
|
||||||
|
b.HasKey("Token");
|
||||||
|
|
||||||
|
b.HasIndex("AccountId");
|
||||||
|
|
||||||
|
b.HasIndex("Token")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("RefreshTokens");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("TimetableDesigner.API.Services.Authentication.Database.Model.RefreshToken", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("TimetableDesigner.API.Services.Authentication.Database.Model.Account", "Account")
|
||||||
|
.WithMany("RefreshTokens")
|
||||||
|
.HasForeignKey("AccountId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Account");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("TimetableDesigner.API.Services.Authentication.Database.Model.Account", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("RefreshTokens");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
namespace TimetableDesigner.API.Services.Authentication.Database.Model;
|
||||||
|
|
||||||
|
public class Account
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public string Email { get; set; } = null!;
|
||||||
|
public byte[] Password { get; set; } = null!;
|
||||||
|
public string PasswordSaltLeft { get; set; } = null!;
|
||||||
|
public string PasswordSaltRight { get; set; } = null!;
|
||||||
|
public uint Version { get; set; }
|
||||||
|
|
||||||
|
public virtual IEnumerable<RefreshToken> RefreshTokens { get; set; } = new List<RefreshToken>();
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
namespace TimetableDesigner.API.Services.Authentication.Database.Model;
|
||||||
|
|
||||||
|
public class RefreshToken
|
||||||
|
{
|
||||||
|
public Guid Token { get; set; }
|
||||||
|
public long AccountId { get; set; }
|
||||||
|
public DateTimeOffset ExpirationDate { get; set; }
|
||||||
|
public bool IsExtendable { get; set; }
|
||||||
|
public uint Version { get; set; }
|
||||||
|
|
||||||
|
public virtual Account Account { get; set; } = null!;
|
||||||
|
}
|
||||||
23
TimetableDesigner.API.Services.Authentication/Dockerfile
Normal file
23
TimetableDesigner.API.Services.Authentication/Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
|
||||||
|
USER $APP_UID
|
||||||
|
WORKDIR /app
|
||||||
|
EXPOSE 8080
|
||||||
|
EXPOSE 8081
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
WORKDIR /src
|
||||||
|
COPY ["TimetableDesigner.API.Services.Authentication.csproj", "./"]
|
||||||
|
RUN dotnet restore "TimetableDesigner.API.Services.Authentication.csproj"
|
||||||
|
COPY . .
|
||||||
|
WORKDIR "/src/"
|
||||||
|
RUN dotnet build "./TimetableDesigner.API.Services.Authentication.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||||
|
|
||||||
|
FROM build AS publish
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
RUN dotnet publish "./TimetableDesigner.API.Services.Authentication.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||||
|
|
||||||
|
FROM base AS final
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=publish /app/publish .
|
||||||
|
ENTRYPOINT ["dotnet", "TimetableDesigner.API.Services.Authentication.dll"]
|
||||||
59
TimetableDesigner.API.Services.Authentication/Program.cs
Normal file
59
TimetableDesigner.API.Services.Authentication/Program.cs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using TimetableDesigner.API.Services.Authentication.API;
|
||||||
|
using TimetableDesigner.API.Services.Authentication.Database;
|
||||||
|
|
||||||
|
namespace TimetableDesigner.API.Services.Authentication;
|
||||||
|
|
||||||
|
public static class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
WebApplication app = WebApplication.CreateBuilder(args)
|
||||||
|
.SetupOpenApi()
|
||||||
|
.SetupSecurity()
|
||||||
|
.SetupDatabase()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
app.MapOpenApi();
|
||||||
|
app.InitializeDatabase();
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
app.MapEndpoints();
|
||||||
|
|
||||||
|
app.Run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WebApplicationBuilder SetupOpenApi(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
builder.Services.AddOpenApi();
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WebApplicationBuilder SetupSecurity(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
//builder.Services.AddAuthorization();
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WebApplicationBuilder SetupDatabase(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
builder.Services.AddDbContext<DatabaseContext>(x => x.UseNpgsql(builder.Configuration.GetConnectionString("Database")), ServiceLifetime.Transient);
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WebApplication InitializeDatabase(this WebApplication app)
|
||||||
|
{
|
||||||
|
using (IServiceScope scope = app.Services.CreateScope())
|
||||||
|
{
|
||||||
|
DatabaseContext database = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
|
||||||
|
while (!database.Database.CanConnect())
|
||||||
|
{
|
||||||
|
app.Logger.LogInformation("Waiting for database...");
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
database.Database.Migrate();
|
||||||
|
}
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "http://localhost:5000",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"https": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "https://localhost:7001;http://localhost:5000",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.9">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Workers\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TimetableDesigner.API.Services.Authentication.DTO\TimetableDesigner.API.Services.Authentication.DTO.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*",
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"Database": "Host=localhost;Port=5433;Database=ttd_authentication;Username=postgres;Password=l4JxOIuSoyod86N;Include Error Detail=True"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user