⚙️ Improve OAuth token handling with enhanced logging and configuration usage

This commit is contained in:
2026-01-29 13:19:46 +00:00
parent 46808cf279
commit 05371a35f5

View File

@@ -42,7 +42,8 @@ app.use('/api/gamemaster', gamemasterRouter);
* POST /oauth/token
*/
app.post('/oauth/token', async (req, res) => {
if (!hasChallongeAuth) {
if (!config.challonge.configured) {
logger.warn('OAuth token request received but Challonge not configured');
return res.status(503).json({
error: 'Challonge OAuth not configured',
message:
@@ -53,10 +54,12 @@ app.post('/oauth/token', async (req, res) => {
const { code } = req.body;
if (!code) {
logger.warn('OAuth token request missing authorization code');
return res.status(400).json({ error: 'Missing authorization code' });
}
try {
logger.debug('Exchanging authorization code for access token');
const response = await fetch('https://api.challonge.com/oauth/token', {
method: 'POST',
headers: {
@@ -64,24 +67,24 @@ app.post('/oauth/token', async (req, res) => {
},
body: new URLSearchParams({
grant_type: 'authorization_code',
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
client_id: config.challonge.clientId,
client_secret: config.challonge.clientSecret,
code: code,
redirect_uri: REDIRECT_URI
redirect_uri: config.challonge.redirectUri
})
});
const data = await response.json();
if (!response.ok) {
console.error('Token exchange failed:', data);
logger.error('Token exchange failed', { status: response.status, data });
return res.status(response.status).json(data);
}
console.log('Token exchange successful');
logger.info('Token exchange successful');
res.json(data);
} catch (error) {
console.error('Token exchange error:', error);
logger.error('Token exchange error', { error: error.message });
res.status(500).json({
error: 'Token exchange failed',
message: error.message