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
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public interface IAuthenticationHook
{
Task<User> Authenticate(string id, string password);
void AddClaims(List<Claim> claims);
void BeforeSending(Token token);
}
15 changes: 11 additions & 4 deletions src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public async Task<Token> GetToken(string authorization)
record = db.GetUserByUserName(id);
}

var hooks = _services.GetServices<IAuthenticationHook>();
if (record == null || record.Source != "internal")
{
// check 3rd party user
var validators = _services.GetServices<IAuthenticationHook>();
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;
Expand Down Expand Up @@ -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)
Expand Down