fix: align backend APIs and upload flow
This commit is contained in:
@@ -26,13 +26,13 @@ namespace IM.Jwt
|
||||
var bytes = RandomNumberGenerator.GetBytes(32);
|
||||
return Convert.ToBase64String(bytes);
|
||||
}
|
||||
public async Task<string> CreateRefreshTokenAsync(Guid userId, CancellationToken cancellationToken = default)
|
||||
public async Task<string> CreateRefreshTokenAsync(Guid userId, CancellationToken cancellationToken = default, string? stamp = null, int? days = null)
|
||||
{
|
||||
string token = GenerateTokenStr();
|
||||
var payload = new { UserId = userId, CreateAt = DateTime.Now };
|
||||
var payload = new { UserId = userId, CreateAt = DateTime.UtcNow, Stamp = stamp };
|
||||
string json = JsonConvert.SerializeObject(payload);
|
||||
//token写入redis
|
||||
await _redis.StringSetAsync(RedisHelper.GetRefreshTokenKey(token), json, TimeSpan.FromDays(_options.Value.RefreshTokenDays));
|
||||
await _redis.StringSetAsync(RedisHelper.GetRefreshTokenKey(token), json, TimeSpan.FromDays(days is > 0 ? days.Value : _options.Value.RefreshTokenDays));
|
||||
return token;
|
||||
}
|
||||
|
||||
@@ -51,19 +51,19 @@ namespace IM.Jwt
|
||||
await _redis.KeyDeleteAsync(RedisHelper.GetRefreshTokenKey(refreshToken));
|
||||
}
|
||||
|
||||
public async Task<(bool ok, Guid userId)> ValidateRefreshTokenAsync(string token, CancellationToken cancellation = default)
|
||||
public async Task<(bool ok, Guid userId, string? stamp)> ValidateRefreshTokenAsync(string token, CancellationToken cancellation = default)
|
||||
{
|
||||
var json = await _redis.StringGetAsync(RedisHelper.GetRefreshTokenKey(token));
|
||||
if (json.IsNullOrEmpty) return (false, Guid.Empty);
|
||||
if (json.IsNullOrEmpty) return (false, Guid.Empty, null);
|
||||
try
|
||||
{
|
||||
using var doc = JsonDocument.Parse(json.ToString());
|
||||
var userId = doc.RootElement.GetProperty("UserId").GetGuid();
|
||||
return (true, userId);
|
||||
return (true, userId, doc.RootElement.TryGetProperty("Stamp", out var stamp) ? stamp.GetString() : null);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return (false, Guid.Empty);
|
||||
return (false, Guid.Empty, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user