UserAuthenticated
This commit is contained in:
parent
1a2685b111
commit
bf84d4a87a
|
|
@ -32,6 +32,7 @@
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
||||||
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.1.2" />
|
||||||
<PackageReference Include="System.Memory.Data" Version="8.0.0" />
|
<PackageReference Include="System.Memory.Data" Version="8.0.0" />
|
||||||
<PackageReference Include="System.Text.Json" Version="8.0.5" />
|
<PackageReference Include="System.Text.Json" Version="8.0.5" />
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
|
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,60 @@
|
||||||
using BotSharp.Abstraction.Users.Models;
|
using BotSharp.Abstraction.Users.Models;
|
||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
|
||||||
namespace BotSharp.Abstraction.Users;
|
namespace BotSharp.Abstraction.Users;
|
||||||
|
|
||||||
public interface IAuthenticationHook
|
public interface IAuthenticationHook
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interupt the authentication process, and return the user object if the user is authenticated
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="password"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task<User> Authenticate(string id, string password);
|
Task<User> Authenticate(string id, string password);
|
||||||
void AddClaims(List<Claim> claims);
|
|
||||||
void BeforeSending(Token token);
|
/// <summary>
|
||||||
|
/// Add extra claims to user
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="claims"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool AddClaims(List<Claim> claims)
|
||||||
|
=> true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// User authenticated successfully
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool UserAuthenticated(JwtSecurityToken token)
|
||||||
|
=> true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Bfore user updating
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task UserUpdating(User user);
|
Task UserUpdating(User user);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// After user created
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task UserCreated(User user);
|
Task UserCreated(User user);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reset password
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task VerificationCodeResetPassword(User user);
|
Task VerificationCodeResetPassword(User user);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete users
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
Task DelUsers(List<string> userIds);
|
Task DelUsers(List<string> userIds);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -275,7 +275,7 @@ public class UserService : IUserService
|
||||||
|
|
||||||
foreach (var hook in hooks)
|
foreach (var hook in hooks)
|
||||||
{
|
{
|
||||||
hook.BeforeSending(token);
|
hook.UserAuthenticated(jwt);
|
||||||
}
|
}
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue