GOG Login: Nahtloser Auth-Flow wie Steam (kein Code-Paste noetig)

- Electron: Fängt GOG Redirect automatisch ab (will-redirect Interceptor)
- Code-Exchange passiert im Hintergrund, User sieht nur Erfolgs-Popup
- GOG Auth-URLs (auth.gog.com, login.gog.com, embed.gog.com) in Popup erlaubt
- Server: GET /gog/login Redirect + POST /gog/exchange Endpoint
- Browser-Fallback: Code-Paste Dialog falls nicht in Electron
- gog.ts: Feste redirect_uri (embed.gog.com/on_login_success)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Daniel 2026-03-08 14:41:08 +01:00
parent af2448a5bd
commit 3e8febb851
5 changed files with 281 additions and 34 deletions

View file

@ -10,6 +10,7 @@ const GOG_CLIENT_SECRET =
const GOG_AUTH_URL = 'https://auth.gog.com/auth';
const GOG_TOKEN_URL = 'https://auth.gog.com/token';
const GOG_EMBED_URL = 'https://embed.gog.com';
const GOG_REDIRECT_URI = 'https://embed.gog.com/on_login_success?origin=client';
// ── Types ────────────────────────────────────────────────────────────────────
@ -37,13 +38,13 @@ export interface GogGame {
/**
* Build the GOG OAuth authorization URL that the user should visit to grant
* access. After approval, GOG will redirect to `redirectUri` with a `code`
* query parameter.
* access. After approval, GOG redirects to `embed.gog.com/on_login_success`
* with a `code` query parameter that the user copies back into the app.
*/
export function getGogAuthUrl(redirectUri: string): string {
export function getGogAuthUrl(): string {
const params = new URLSearchParams({
client_id: GOG_CLIENT_ID,
redirect_uri: redirectUri,
redirect_uri: GOG_REDIRECT_URI,
response_type: 'code',
layout: 'client2',
});
@ -53,10 +54,10 @@ export function getGogAuthUrl(redirectUri: string): string {
/**
* Exchange an authorization code for GOG access + refresh tokens.
* Uses the fixed GOG_REDIRECT_URI that matches the OAuth registration.
*/
export async function exchangeGogCode(
code: string,
redirectUri: string,
): Promise<GogTokens> {
console.log('[GOG] Exchanging authorization code for tokens...');
@ -65,7 +66,7 @@ export async function exchangeGogCode(
client_secret: GOG_CLIENT_SECRET,
grant_type: 'authorization_code',
code,
redirect_uri: redirectUri,
redirect_uri: GOG_REDIRECT_URI,
});
const res = await fetch(`${GOG_TOKEN_URL}?${params.toString()}`);