Refactor code for improved readability and consistency
- Updated CSRF middleware to enhance cookie value decoding. - Reformatted OAuth proxy token store initialization for better clarity. - Adjusted Challonge proxy router for consistent line breaks and readability. - Enhanced OAuth router error handling and response formatting. - Improved session router for better readability and consistency in fetching provider records. - Refactored OAuth token store to improve key derivation logging. - Cleaned up cookie options utility for better readability. - Enhanced Challonge client credentials composable for consistent API calls. - Streamlined OAuth composable for improved logging. - Refactored main.js for better readability in session initialization. - Improved Challonge v2.1 service error handling for better clarity. - Cleaned up API client utility for improved readability. - Enhanced ApiKeyManager.vue for better text formatting. - Refactored ChallongeTest.vue for improved readability in composable usage.
This commit is contained in:
@@ -69,7 +69,8 @@ export function createChallongeProxyRouter({ config, tokenStore }) {
|
||||
return res.status(500).json({ error: 'SID middleware not configured' });
|
||||
}
|
||||
|
||||
const challongeRecord = (await tokenStore.getProviderRecord(req.sid, 'challonge')) || {};
|
||||
const challongeRecord =
|
||||
(await tokenStore.getProviderRecord(req.sid, 'challonge')) || {};
|
||||
|
||||
// Determine upstream path relative to this router mount
|
||||
// This router is mounted at /challonge, so req.url starts with /v1/... or /v2.1/...
|
||||
@@ -110,7 +111,8 @@ export function createChallongeProxyRouter({ config, tokenStore }) {
|
||||
const app = challongeRecord.client_credentials;
|
||||
if (!app?.client_id || !app?.client_secret) {
|
||||
return res.status(401).json({
|
||||
error: 'Challonge client credentials not configured for this session',
|
||||
error:
|
||||
'Challonge client credentials not configured for this session',
|
||||
code: 'CHALLONGE_CLIENT_CREDENTIALS_REQUIRED'
|
||||
});
|
||||
}
|
||||
@@ -130,7 +132,11 @@ export function createChallongeProxyRouter({ config, tokenStore }) {
|
||||
expires_at: computeExpiresAt(exchanged.expires_in)
|
||||
};
|
||||
|
||||
await tokenStore.setProviderRecord(req.sid, 'challonge', challongeRecord);
|
||||
await tokenStore.setProviderRecord(
|
||||
req.sid,
|
||||
'challonge',
|
||||
challongeRecord
|
||||
);
|
||||
accessToken = challongeRecord.client_credentials.access_token;
|
||||
}
|
||||
|
||||
@@ -158,7 +164,11 @@ export function createChallongeProxyRouter({ config, tokenStore }) {
|
||||
}
|
||||
|
||||
let accessToken = user.access_token;
|
||||
if (isExpired(user.expires_at) && user.refresh_token && config.challonge.configured) {
|
||||
if (
|
||||
isExpired(user.expires_at) &&
|
||||
user.refresh_token &&
|
||||
config.challonge.configured
|
||||
) {
|
||||
try {
|
||||
const refreshed = await refreshUserOAuth({
|
||||
config,
|
||||
@@ -172,7 +182,11 @@ export function createChallongeProxyRouter({ config, tokenStore }) {
|
||||
scope: refreshed.scope,
|
||||
expires_at: computeExpiresAt(refreshed.expires_in)
|
||||
};
|
||||
await tokenStore.setProviderRecord(req.sid, 'challonge', challongeRecord);
|
||||
await tokenStore.setProviderRecord(
|
||||
req.sid,
|
||||
'challonge',
|
||||
challongeRecord
|
||||
);
|
||||
accessToken = challongeRecord.user_oauth.access_token;
|
||||
} catch (err) {
|
||||
logger.warn('Failed to refresh Challonge user OAuth token', {
|
||||
@@ -213,10 +227,13 @@ export function createChallongeProxyRouter({ config, tokenStore }) {
|
||||
) {
|
||||
const apiKey = challongeRecord.api_key?.token;
|
||||
if (apiKey) {
|
||||
logger.warn('Challonge v2.1 user OAuth unauthorized; retrying with API key', {
|
||||
status: upstreamResponse.status,
|
||||
path: upstreamPath
|
||||
});
|
||||
logger.warn(
|
||||
'Challonge v2.1 user OAuth unauthorized; retrying with API key',
|
||||
{
|
||||
status: upstreamResponse.status,
|
||||
path: upstreamPath
|
||||
}
|
||||
);
|
||||
|
||||
const retryHeaders = { ...headers };
|
||||
delete retryHeaders.authorization;
|
||||
|
||||
Reference in New Issue
Block a user