Uwierzytelnianie .NET 8 z Identity w Web API
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.11" /><PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0-preview.7.23375.9" /><PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.11" /><PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.11"><PrivateAssets>all</PrivateAssets><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets></PackageReference><PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.11" /><PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.11"><PrivateAssets>all</PrivateAssets><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets></PackageReference><PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /><PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.11" />
Endpoints
ContextDB.
1 - Dodanie możliwość autoryzacji w Swagger
2 - Dodanie Połączenia do DB, oraz struktury IdentityUser.
3 - Generowanie identity token
Rejestrowanie użytkownika w systemie.
Logowanie i poprawny zalogowanie oraz uzyskanie tokena JWT.
Testowanie logowania do endpointa przy użyciu Postman-a :
[HttpGet, Authorize]
public IActionResult Get()
{
return Ok("Test");
}
Struktura DB (wygenerowana automatycznie - Migration)