fix: add Discord OAuth token exchange logging for production diagnostics
PR Checks / test-and-build (pull_request) Failing after 6m20s
PR Checks / test-and-build (pull_request) Failing after 6m20s
- Log status code and response body when Discord /oauth2/token fails - Helps identify why ExchangeCodeAsync returns null in production Bump version → 2.8.1 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -66,7 +66,7 @@
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="nav-version">v2.8.0</div>
|
||||
<div class="nav-version">v2.8.1</div>
|
||||
</div>
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace GmRelay.Web.Services;
|
||||
|
||||
public sealed class DiscordAuthService(IHttpClientFactory httpClientFactory, IConfiguration configuration)
|
||||
public sealed class DiscordAuthService(IHttpClientFactory httpClientFactory, IConfiguration configuration, ILogger<DiscordAuthService> logger)
|
||||
{
|
||||
private readonly DiscordOAuthOptions _options = configuration.GetSection("Discord").Get<DiscordOAuthOptions>() ?? new DiscordOAuthOptions();
|
||||
|
||||
@@ -40,10 +40,14 @@ public sealed class DiscordAuthService(IHttpClientFactory httpClientFactory, ICo
|
||||
});
|
||||
|
||||
var response = await client.PostAsync("https://discord.com/api/oauth2/token", content);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
logger.LogError("Discord token exchange failed: {StatusCode} {Body}. client_id={ClientId}, redirect_uri={RedirectUri}",
|
||||
(int)response.StatusCode, json, _options.ClientId, _options.RedirectUri);
|
||||
return null;
|
||||
}
|
||||
|
||||
return JsonSerializer.Deserialize<DiscordTokenResponse>(json);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user