Przeglądaj źródła

update Admin.NET/Admin.NET.Core/SignatureAuth/SignatureAuthenticationHandler.cs.

Signed-off-by: Denny <kingxi@163.com>
Denny 1 rok temu
rodzic
commit
1ebd2bf669

+ 5 - 4
Admin.NET/Admin.NET.Core/SignatureAuth/SignatureAuthenticationHandler.cs

@@ -68,13 +68,14 @@ public sealed class SignatureAuthenticationHandler : AuthenticationHandler<Signa
             return await AuthenticateResultFailAsync("timestamp 值不合法");
 
         var requestDate = DateTimeUtil.ToLocalTimeDateBySeconds(timestamp);
+        
 #if NET6_0
-        if (requestDate > Clock.UtcNow.Add(Options.AllowedDateDrift).LocalDateTime || requestDate < Clock.UtcNow.Subtract(Options.AllowedDateDrift).LocalDateTime)
-            return await AuthenticateResultFailAsync("timestamp 值已超过允许的偏差范围");
+        var utcNow = Clock.UtcNow;
 #else
-        if (requestDate > TimeProvider.GetUtcNow().Add(Options.AllowedDateDrift).LocalDateTime || requestDate < TimeProvider.GetUtcNow().Subtract(Options.AllowedDateDrift).LocalDateTime)
-            return await AuthenticateResultFailAsync("timestamp 值已超过允许的偏差范围");
+        var utcNow = TimeProvider.GetUtcNow();
 #endif
+        if (requestDate > utcNow.Add(Options.AllowedDateDrift).LocalDateTime || requestDate < utcNow.Subtract(Options.AllowedDateDrift).LocalDateTime)
+            return await AuthenticateResultFailAsync("timestamp 值已超过允许的偏差范围");
 
         // 获取 accessSecret
         var getAccessSecretContext = new GetAccessSecretContext(Context, Scheme, Options) { AccessKey = accessKey };