From 6ef7b73360a637e49bc0d0a52f993527d68ad162 Mon Sep 17 00:00:00 2001 From: Lucca Santangelo <luccasant95@gmail.com> Date: Wed, 25 Nov 2020 21:34:38 -0300 Subject: [PATCH] get all refresh tokens --- Tsi1.Api/Tsi1.Api/Controllers/UserController.cs | 7 +++++++ Tsi1.Api/Tsi1.Api/Infrastructure/IJwtAuthManager.cs | 2 ++ Tsi1.Api/Tsi1.Api/Infrastructure/JwtAuthManager.cs | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs b/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs index 772ed5d..e0ffd0b 100644 --- a/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs +++ b/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs @@ -482,5 +482,12 @@ namespace Tsi1.Api.Controllers return Ok(); } + + [AllowAnonymous] + [HttpGet("GetAllRefreshTokens")] + public async Task<IActionResult> GetAllRefreshTokens() + { + return Ok(_jwtAuthManager.GetRefreshTokens()); + } } } diff --git a/Tsi1.Api/Tsi1.Api/Infrastructure/IJwtAuthManager.cs b/Tsi1.Api/Tsi1.Api/Infrastructure/IJwtAuthManager.cs index ab8bf68..15caef0 100644 --- a/Tsi1.Api/Tsi1.Api/Infrastructure/IJwtAuthManager.cs +++ b/Tsi1.Api/Tsi1.Api/Infrastructure/IJwtAuthManager.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.Immutable; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; @@ -17,5 +18,6 @@ namespace Tsi1.Api.Infrastructure int GenerateVerificationCode(string username, DateTime now); bool ValidateVerificationCode(string username, int code); public void RemoveExpiredVerificationCodes(DateTime now); + public IEnumerable<RefreshToken> GetRefreshTokens(); } } diff --git a/Tsi1.Api/Tsi1.Api/Infrastructure/JwtAuthManager.cs b/Tsi1.Api/Tsi1.Api/Infrastructure/JwtAuthManager.cs index f1bf057..bad78f3 100644 --- a/Tsi1.Api/Tsi1.Api/Infrastructure/JwtAuthManager.cs +++ b/Tsi1.Api/Tsi1.Api/Infrastructure/JwtAuthManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Concurrent; +using System.Collections.Generic; using System.Collections.Immutable; using System.IdentityModel.Tokens.Jwt; using System.Linq; @@ -150,6 +151,11 @@ namespace Tsi1.Api.Infrastructure } } + public IEnumerable<RefreshToken> GetRefreshTokens() + { + return _usersRefreshTokens.Select(x => x.Value).ToList(); + } + private static string GenerateRefreshTokenString() { var randomNumber = new byte[32]; -- GitLab