Skip to content

Commit

Permalink
Improve formatTokenForLogs
Browse files Browse the repository at this point in the history
  • Loading branch information
fflorent committed Jul 23, 2024
1 parent 21d1b80 commit 522e6ac
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions app/server/lib/OIDCConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,13 @@ const CALLBACK_URL = '/oauth2/callback';

function formatTokenForLogs(token: TokenSet) {
const showValueInClear = ['token_type', 'expires_in', 'expires_at', 'scope'];
const originalEntries = Object.entries(token);

return Object.fromEntries(
originalEntries.flatMap(([key, value]: [string, any]) => {
if (typeof value === 'function') {
return []; // Discard functions for logs
}
const newValue = showValueInClear.includes(key) ? value : 'REDACTED';
return [[key, newValue]];
})
);
const result: Record<string, any> = {};
for (const [key, value] of Object.entries(token)) {
if (typeof value !== 'function') {
result[key] = showValueInClear.includes(key) ? value : 'REDACTED';
}
}
return result;
}

class ErrorWithUserFriendlyMessage extends Error {
Expand Down

0 comments on commit 522e6ac

Please sign in to comment.