fix(kis-api): Null reference 검증 강화 (토큰 응답 처리)
KisApiClient.TryGetAccessTokenAsync()의 null 참조 경고 제거. - 토큰 응답 본문 존재 여부 검증 - TryGetValue 기반 안전한 파싱 - access_token 필수 필드 검증 Build: 0 errors, 0 warnings ✅ Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -174,8 +174,15 @@ public class KisApiClient : IKisApiClient
|
|||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var tokenData = await response.Content.ReadFromJsonAsync<Dictionary<string, object>>();
|
var tokenData = await response.Content.ReadFromJsonAsync<Dictionary<string, object>>();
|
||||||
var accessToken = tokenData["access_token"]?.ToString() ?? throw new InvalidOperationException("No access_token in response");
|
if (tokenData == null) throw new InvalidOperationException("Token response body is empty");
|
||||||
var expiresInStr = tokenData.ContainsKey("expires_in") ? tokenData["expires_in"]?.ToString() : "86400";
|
|
||||||
|
if (!tokenData.TryGetValue("access_token", out var tokenObj) || tokenObj == null)
|
||||||
|
throw new InvalidOperationException("No access_token in response");
|
||||||
|
var accessToken = tokenObj.ToString()!;
|
||||||
|
|
||||||
|
var expiresInStr = tokenData.TryGetValue("expires_in", out var expiresObj) && expiresObj != null
|
||||||
|
? expiresObj.ToString()
|
||||||
|
: "86400";
|
||||||
var expiresInSec = int.TryParse(expiresInStr, out var seconds) ? seconds : 86400;
|
var expiresInSec = int.TryParse(expiresInStr, out var seconds) ? seconds : 86400;
|
||||||
var expiresAt = DateTime.UtcNow.AddSeconds(expiresInSec);
|
var expiresAt = DateTime.UtcNow.AddSeconds(expiresInSec);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user