Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
public interface ITokenSignInManager<TUser>
where TUser : IdentityUser<Guid>
{
/// <summary>
/// Signs in a user with their password asynchronously.
/// </summary>
/// <param name="user">The user.</param>
/// <param name="password">The password.</param>
/// <returns>The JWT if signed in; otherwise <c>null</c>.</returns>
Task<JsonWebToken?> PasswordSignInAsync(TUser user, string password);

/// <summary>
/// Sign-in with a password.
/// </summary>
Expand Down
23 changes: 15 additions & 8 deletions Neolution.Extensions.Identity/TokenSignManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ public TokenSignManager(ILogger<TokenSignManager<TUser>> logger, IUserManager<TU
this.jwtGenerator = jwtGenerator;
}

/// <inheritdoc />
public async Task<JsonWebToken?> 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;
}

/// <inheritdoc />
public async Task<JsonWebToken?> PasswordSignInAsync(string email, string password)
{
Expand All @@ -59,14 +73,7 @@ public TokenSignManager(ILogger<TokenSignManager<TUser>> logger, IUserManager<TU
return null;
}

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={User} failed", email);
return null;
return await this.PasswordSignInAsync(user, password);
}

/// <inheritdoc />
Expand Down