Merge pull request #3754 from SillyTavern/fix-openrouter-oauth

OpenRouter: Fix OAuth flow with enabled accounts
This commit is contained in:
Cohee
2025-03-25 23:20:42 +02:00
committed by GitHub
2 changed files with 18 additions and 4 deletions

View File

@ -189,14 +189,17 @@ export async function findSecret(key) {
}
function authorizeOpenRouter() {
const openRouterUrl = `https://openrouter.ai/auth?callback_url=${encodeURIComponent(location.origin)}`;
const redirectUrl = new URL('/callback/openrouter', window.location.origin);
const openRouterUrl = `https://openrouter.ai/auth?callback_url=${encodeURIComponent(redirectUrl.toString())}`;
location.href = openRouterUrl;
}
async function checkOpenRouterAuth() {
const params = new URLSearchParams(location.search);
if (params.has('code')) {
const code = params.get('code');
const source = params.get('source');
if (source === 'openrouter') {
const query = new URLSearchParams(params.get('query'));
const code = query.get('code');
try {
const response = await fetch('https://openrouter.ai/api/v1/auth/keys', {
method: 'POST',