diff --git a/CHANGELOG.md b/CHANGELOG.md index aa4d5f3..32ad54a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- a new overload for method `PasswordSignInAsync` of `ITokenSignInManager` which accepts TUser entity parameter + ## [0.5.0] - 2025-02-11 ### Added diff --git a/Neolution.Extensions.Identity.Abstractions/ITokenSignInManager.cs b/Neolution.Extensions.Identity.Abstractions/ITokenSignInManager.cs index 29e2659..6c513bb 100644 --- a/Neolution.Extensions.Identity.Abstractions/ITokenSignInManager.cs +++ b/Neolution.Extensions.Identity.Abstractions/ITokenSignInManager.cs @@ -10,6 +10,14 @@ public interface ITokenSignInManager where TUser : IdentityUser { + /// + /// Signs in a user with their password asynchronously. + /// + /// The user. + /// The password. + /// The JWT if signed in; otherwise null. + Task PasswordSignInAsync(TUser user, string password); + /// /// Sign-in with a password. /// diff --git a/Neolution.Extensions.Identity/TokenSignManager.cs b/Neolution.Extensions.Identity/TokenSignManager.cs index ea43a3f..f4195e9 100644 --- a/Neolution.Extensions.Identity/TokenSignManager.cs +++ b/Neolution.Extensions.Identity/TokenSignManager.cs @@ -49,6 +49,20 @@ public TokenSignManager(ILogger> logger, IUserManager + public async Task PasswordSignInAsync(TUser user, string password) + { + this.logger.LogTrace("Perform password sign-in for user email={Email}/username={Username}", user.Email, user.UserName); + var signInResponse = await this.signInManager.CheckPasswordSignInAsync(user, password, true); + if (signInResponse.Succeeded) + { + return await this.CreateAccessTokenAsync(user, "pwd", "identity-store"); + } + + this.logger.LogWarning("Password sign-in for user email={Email}/username={Username} failed", user.Email, user.UserName); + return null; + } + /// public async Task PasswordSignInAsync(string email, string password) { @@ -59,14 +73,7 @@ public TokenSignManager(ILogger> logger, IUserManager