From 617a0119f461a5ec4e1eda61cf2d8d187abb9c21 Mon Sep 17 00:00:00 2001 From: YouWeiDH Date: Sat, 14 Dec 2024 18:36:51 +0800 Subject: [PATCH] hdong: create token by current user. --- .../BotSharp.Abstraction/Users/IUserService.cs | 1 + .../BotSharp.Core/Users/Services/UserService.cs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs index 134ca25b..5e56b431 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs @@ -17,6 +17,7 @@ public interface IUserService Task GetAffiliateToken(string authorization); Task GetAdminToken(string authorization); Task GetToken(string authorization); + Task CreateTokenByUser(User user); Task GetMyProfile(); Task VerifyUserNameExisting(string userName); Task VerifyEmailExisting(string email); diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index a87c55fa..18deb7d8 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -506,6 +506,20 @@ public class UserService : IUserService return token; } + public async Task CreateTokenByUser(User user) + { + var accessToken = GenerateJwtToken(user); + var jwt = new JwtSecurityTokenHandler().ReadJwtToken(accessToken); + var token = new Token + { + AccessToken = accessToken, + ExpireTime = jwt.Payload.Exp.Value, + TokenType = "Bearer", + Scope = "api" + }; + return token; + } + public async Task VerifyUserNameExisting(string userName) { if (string.IsNullOrEmpty(userName))