From bf84d4a87ada08dca81d53ad6b08ed2f7fdcc3f3 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Sat, 19 Oct 2024 10:06:24 -0500 Subject: [PATCH] UserAuthenticated --- .../BotSharp.Abstraction.csproj | 1 + .../Users/IAuthenticationHook.cs | 49 ++++++++++++++++++- .../Users/Services/UserService.cs | 2 +- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj b/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj index e94cf839..474dcf56 100644 --- a/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj +++ b/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj @@ -32,6 +32,7 @@ + diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/IAuthenticationHook.cs b/src/Infrastructure/BotSharp.Abstraction/Users/IAuthenticationHook.cs index afb0e40e..36b07f11 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Users/IAuthenticationHook.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Users/IAuthenticationHook.cs @@ -1,15 +1,60 @@ using BotSharp.Abstraction.Users.Models; +using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; namespace BotSharp.Abstraction.Users; public interface IAuthenticationHook { + /// + /// Interupt the authentication process, and return the user object if the user is authenticated + /// + /// + /// + /// Task Authenticate(string id, string password); - void AddClaims(List claims); - void BeforeSending(Token token); + + /// + /// Add extra claims to user + /// + /// + /// + bool AddClaims(List claims) + => true; + + /// + /// User authenticated successfully + /// + /// + /// + bool UserAuthenticated(JwtSecurityToken token) + => true; + + /// + /// Bfore user updating + /// + /// + /// Task UserUpdating(User user); + + /// + /// After user created + /// + /// + /// Task UserCreated(User user); + + /// + /// Reset password + /// + /// + /// Task VerificationCodeResetPassword(User user); + + /// + /// Delete users + /// + /// + /// Task DelUsers(List userIds); } diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index 10dbe8de..5d08c51f 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -275,7 +275,7 @@ public class UserService : IUserService foreach (var hook in hooks) { - hook.BeforeSending(token); + hook.UserAuthenticated(jwt); } return token;