diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/IAuthenticationHook.cs b/src/Infrastructure/BotSharp.Abstraction/Users/IAuthenticationHook.cs index 267a997c0..33b8086f5 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Users/IAuthenticationHook.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Users/IAuthenticationHook.cs @@ -7,4 +7,5 @@ public interface IAuthenticationHook { Task Authenticate(string id, string password); void AddClaims(List claims); + void BeforeSending(Token token); } diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index c9521dffe..ce9a9d602 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -71,13 +71,13 @@ public async Task GetToken(string authorization) record = db.GetUserByUserName(id); } + var hooks = _services.GetServices(); if (record == null || record.Source != "internal") { // check 3rd party user - var validators = _services.GetServices(); - foreach (var validator in validators) + foreach (var hook in hooks) { - var user = await validator.Authenticate(id, password); + var user = await hook.Authenticate(id, password); if (user == null) { continue; @@ -120,13 +120,20 @@ record = db.GetUserByUserName(id); var accessToken = GenerateJwtToken(record); var jwt = new JwtSecurityTokenHandler().ReadJwtToken(accessToken); - return new Token + var token = new Token { AccessToken = accessToken, ExpireTime = jwt.Payload.Exp.Value, TokenType = "Bearer", Scope = "api" }; + + foreach (var hook in hooks) + { + hook.BeforeSending(token); + } + + return token; } private string GenerateJwtToken(User user)