The OAuth client ID.
The OAuth client secret.
The redirect URI used for authentication.
The authorization code to exchange.
Promise resolving to the token response.
export async function getAccessToken(
clientId: string,
clientSecret: string,
redirectUri: string,
code: string,
): Promise<{ access_token: string; token_type: string; expires_in: number }> {
console.log("🔑 getAccessToken starting with:", {
clientId: clientId.substring(0, 2) + "...",
redirectUri,
codeLength: code.length,
});
// Use the main process to exchange the token
const result = await window.electronAPI.anilist.exchangeToken({
clientId,
clientSecret,
redirectUri,
code,
});
if (!result.success || !result.token) {
throw new Error(
`Failed to exchange code for token: ${result.error || "Unknown error"}`,
);
}
return result.token;
}
Exchange an authorization code for an access token through the main process.