Add authentication and authorization #21
@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameIdeas.Shared", "GameIde
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Client", "Client", "{9598BBAF-CC9F-4F43-82B2-40F57296C9F0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameIdeas.WebAPI.Tests", "Server\GameIdeas.WebAPI.Tests\GameIdeas.WebAPI.Tests.csproj", "{D7B46EB2-590D-4A39-90C6-4D553FC4309A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -37,6 +39,10 @@ Global
|
||||
{9D6D5C6D-AD66-4353-88CC-638887C42477}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9D6D5C6D-AD66-4353-88CC-638887C42477}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9D6D5C6D-AD66-4353-88CC-638887C42477}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D7B46EB2-590D-4A39-90C6-4D553FC4309A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D7B46EB2-590D-4A39-90C6-4D553FC4309A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D7B46EB2-590D-4A39-90C6-4D553FC4309A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D7B46EB2-590D-4A39-90C6-4D553FC4309A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -44,6 +50,7 @@ Global
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{ABBADA2F-9017-49A2-AEB9-AC2DB7D70831} = {9598BBAF-CC9F-4F43-82B2-40F57296C9F0}
|
||||
{61C3985E-15DF-4127-9D1F-CAE39F0ADD17} = {F59BED34-9473-436A-A91A-23510A4E0E87}
|
||||
{D7B46EB2-590D-4A39-90C6-4D553FC4309A} = {F59BED34-9473-436A-A91A-23510A4E0E87}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {6380DD77-53E4-4F3B-BB45-FAD2263D1511}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="MSTest" Version="3.6.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\GameIdeas.Shared\GameIdeas.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
17
src/GameIdeas/Server/GameIdeas.WebAPI.Tests/IdentityTest.cs
Normal file
17
src/GameIdeas/Server/GameIdeas.WebAPI.Tests/IdentityTest.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using GameIdeas.Shared.Model;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace GameIdeas.WebAPI.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public sealed class IdentityTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void GetPasswordHash()
|
||||
{
|
||||
var hasher = new PasswordHasher<User>();
|
||||
var hash = hasher.HashPassword(null!, "GameIdeas");
|
||||
Console.WriteLine(hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
|
||||
@@ -1,39 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace GameIdeas.WebAPI.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class SeedRoles : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetRoles",
|
||||
columns: ["Id", "Name", "NormalizedName", "ConcurrencyStamp"],
|
||||
values: new object[,]
|
||||
{
|
||||
{
|
||||
Guid.NewGuid().ToString(),
|
||||
"Administrateur",
|
||||
"ADMINISTRATEUR",
|
||||
Guid.NewGuid().ToString()
|
||||
},
|
||||
{
|
||||
Guid.NewGuid().ToString(),
|
||||
"Membre",
|
||||
"MEMBRE",
|
||||
Guid.NewGuid().ToString()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql("DELETE FROM [AspNetRoles] WHERE [Name] IN ('Administrateur', 'Membre')");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace GameIdeas.WebAPI.Migrations
|
||||
{
|
||||
[DbContext(typeof(GameIdeasContext))]
|
||||
[Migration("20250420153439_SeedRoles")]
|
||||
partial class SeedRoles
|
||||
[Migration("20250420160158_SeedDefaultUser")]
|
||||
partial class SeedDefaultUser
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@@ -0,0 +1,66 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace GameIdeas.WebAPI.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class SeedDefaultUser : Migration
|
||||
{
|
||||
private readonly Guid AdminId = Guid.Parse("{06CA5CB7-6DE5-4A73-9DDD-8E2D5CCDF104}");
|
||||
private readonly Guid AdminUserId = Guid.Parse("{2AB56FCB-0CDE-4DAE-AC9C-FC7635B0D18A}");
|
||||
private readonly Guid MemberId = Guid.Parse("{BCE14DEA-1748-4A76-8485-ADEE83DF5EFD}");
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetRoles",
|
||||
columns: ["Id", "Name", "NormalizedName", "ConcurrencyStamp"],
|
||||
values: new object[,]
|
||||
{
|
||||
{
|
||||
AdminId.ToString(),
|
||||
"Administrateur",
|
||||
"ADMINISTRATEUR",
|
||||
Guid.NewGuid().ToString()
|
||||
},
|
||||
{
|
||||
MemberId.ToString(),
|
||||
"Membre",
|
||||
"MEMBRE",
|
||||
Guid.NewGuid().ToString()
|
||||
}
|
||||
});
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetUsers",
|
||||
columns:
|
||||
[
|
||||
"Id", "UserName", "NormalizedUserName", "EmailConfirmed", "PhoneNumberConfirmed", "TwoFactorEnabled"
|
||||
, "PasswordHash", "SecurityStamp", "ConcurrencyStamp", "AccessFailedCount", "LockoutEnabled"
|
||||
],
|
||||
values:
|
||||
[
|
||||
AdminUserId.ToString(), "admin", "ADMIN",
|
||||
false, false, false,
|
||||
"AQAAAAIAAYagAAAAEOGx7MFBLpS7awda0ww6jsfXsnhsUjYd4gDK9DaGvQv0X9UZTuHStr5v5+t4Y1S+xg==",
|
||||
Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, false
|
||||
]);
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetUserRoles",
|
||||
columns: ["UserId", "RoleId"],
|
||||
values: [AdminUserId.ToString(), AdminId.ToString()]);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql(@$"DELETE FROM ""AspNetUserRoles"" WHERE ""UserId"" = '{AdminUserId.ToString()}' AND ""RoleId"" = '{AdminId.ToString()}'");
|
||||
migrationBuilder.DeleteData("AspNetUsers", "Id", AdminUserId.ToString());
|
||||
migrationBuilder.DeleteData("AspNetRoles", "Id", AdminId.ToString());
|
||||
migrationBuilder.DeleteData("AspNetRoles", "Id", MemberId.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user