fix : 토큰인증 스펙 수정
This commit is contained in:
@@ -8,23 +8,29 @@ namespace MMOserver.Api;
|
|||||||
|
|
||||||
public class RestApi : Singleton<RestApi>
|
public class RestApi : Singleton<RestApi>
|
||||||
{
|
{
|
||||||
private const string VERIFY_URL = "https://a301.api.tolelom.xyz/api/auth/internal/auth/verify";
|
private const string VERIFY_URL = "https://a301.api.tolelom.xyz";
|
||||||
|
private const string INTERNAL_API_KEY = "017f15b28143fc67d2e5bed283c37d2da858b9f294990a5334238e055e3f5425";
|
||||||
private readonly HttpClient httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(5) };
|
private readonly HttpClient httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(5) };
|
||||||
|
|
||||||
private const int MAX_RETRY = 3;
|
private const int MAX_RETRY = 3;
|
||||||
private static readonly TimeSpan RETRY_DELAY = TimeSpan.FromSeconds(1);
|
private static readonly TimeSpan RETRY_DELAY = TimeSpan.FromSeconds(1);
|
||||||
|
|
||||||
|
public RestApi()
|
||||||
|
{
|
||||||
|
httpClient.DefaultRequestHeaders.Add("X-API-Key", INTERNAL_API_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
// 토큰 검증 - 성공 시 username 반환
|
// 토큰 검증 - 성공 시 username 반환
|
||||||
// 401 → 재시도 없이 즉시 null 반환 (토큰 자체가 무효)
|
// 401 → 재시도 없이 즉시 null 반환 (토큰 자체가 무효)
|
||||||
// 타임아웃/네트워크 오류 → 최대 MAX_RETRY회 재시도 후 null 반환
|
// 타임아웃/네트워크 오류 → 최대 MAX_RETRY회 재시도 후 null 반환
|
||||||
public async Task<string?> VerifyTokenAsync(string token)
|
public async Task<string?> VerifyTokenAsync(string token)
|
||||||
{
|
{
|
||||||
|
string url = VERIFY_URL + "/api/internal/auth/verify";
|
||||||
for (int attempt = 1; attempt <= MAX_RETRY; attempt++)
|
for (int attempt = 1; attempt <= MAX_RETRY; attempt++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpResponseMessage response = await httpClient.PostAsJsonAsync(VERIFY_URL, new { token });
|
HttpResponseMessage response = await httpClient.PostAsJsonAsync(url, new { token });
|
||||||
response.Headers.Add("X-API-Key", token);
|
|
||||||
|
|
||||||
// 401: 토큰 자체가 무효 → 재시도해도 같은 결과, 즉시 반환
|
// 401: 토큰 자체가 무효 → 재시도해도 같은 결과, 즉시 반환
|
||||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||||
|
|||||||
Reference in New Issue
Block a user