mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-02 21:32:10 +03:00
fix: extract email from id_token for Codex OAuth to allow multiple accounts (#97)
- Parse JWT id_token to extract email in mapTokens function - Allows database to distinguish between different Codex accounts - Fixes issue where adding 3rd+ Codex account would update existing connection instead of creating new one
This commit is contained in:
@@ -44,10 +44,24 @@ export const codex = {
|
||||
|
||||
return await response.json();
|
||||
},
|
||||
mapTokens: (tokens) => ({
|
||||
accessToken: tokens.access_token,
|
||||
refreshToken: tokens.refresh_token,
|
||||
idToken: tokens.id_token,
|
||||
expiresIn: tokens.expires_in,
|
||||
}),
|
||||
mapTokens: (tokens) => {
|
||||
// Extract email from id_token JWT to distinguish between accounts
|
||||
let email = null;
|
||||
if (tokens.id_token) {
|
||||
try {
|
||||
const payload = tokens.id_token.split(".")[1];
|
||||
const decoded = JSON.parse(Buffer.from(payload, "base64").toString());
|
||||
email = decoded.email || null;
|
||||
} catch {
|
||||
// Ignore JWT parsing errors
|
||||
}
|
||||
}
|
||||
return {
|
||||
accessToken: tokens.access_token,
|
||||
refreshToken: tokens.refresh_token,
|
||||
idToken: tokens.id_token,
|
||||
expiresIn: tokens.expires_in,
|
||||
email,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user