fix: fall back to manual login when epic device code api fails
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 11s
build-and-push / docker (push) Successful in 1m9s

This commit is contained in:
nocci 2025-12-31 13:04:00 +00:00
parent 051363ed5f
commit 5c7a945be0
2 changed files with 17 additions and 6 deletions

View file

@ -67,6 +67,7 @@ Common options:
- `TIMEOUT`, `LOGIN_TIMEOUT` (seconds)
- Epic: `EG_MODE=legacy|new` (legacy Playwright flow or neuer API-getriebener Claimer), `EG_PARENTALPIN`, `EG_EMAIL`, `EG_PASSWORD`, `EG_OTPKEY`
- Epic (new mode): Cookies werden unter `data/browser/epic-cookies.json` persistiert; OAuth Device Code Flow benötigt ggf. einmalige Freigabe im Browser.
- Falls Device-Code-Endpunkt nicht erreichbar ist (404/Bad Request), fällt der neue Modus automatisch auf manuellen Browser-Login zurück.
- Login: `EMAIL`, `PASSWORD` global; per store `EG_EMAIL`, `EG_PASSWORD`, `EG_OTPKEY`, `PG_EMAIL`, `PG_PASSWORD`, `PG_OTPKEY`, `GOG_EMAIL`, `GOG_PASSWORD`
- Prime Gaming: `PG_REDEEM=1` (auto-redeem keys, experimental), `PG_CLAIMDLC=1`, `PG_TIMELEFT=<days>` to skip long-remaining offers
- Screenshots: `SCREENSHOTS_DIR` (default `data/screenshots`)

View file

@ -80,10 +80,16 @@ const getValidAuth = async ({ otpKey, reuseCookies, cookiesPath }) => {
}
console.log('🔐 Starting fresh OAuth device flow (manual approval required)...');
const deviceResponse = await axios.post('https://api.epicgames.dev/epic/oauth/deviceCode', {
client_id: '34a02cf8f4414e29b159cdd02e6184bd',
scope: 'account.basicprofile account.userentitlements',
});
let deviceResponse;
try {
deviceResponse = await axios.post('https://api.epicgames.dev/epic/oauth/deviceCode', {
client_id: '34a02cf8f4414e29b159cdd02e6184bd',
scope: 'account.basicprofile account.userentitlements',
});
} catch (e) {
console.error('Device code flow failed (fallback to manual login):', e.response?.status || e.message);
return { bearerToken: null, cookies: [] };
}
const { device_code, user_code, verification_uri_complete } = deviceResponse.data;
console.log(`📱 Open: ${verification_uri_complete}`);
console.log(`💳 Code: ${user_code}`);
@ -258,8 +264,12 @@ export const claimEpicGamesNew = async () => {
cookiesPath: COOKIES_PATH,
});
await context.addCookies(auth.cookies);
console.log('✅ Cookies loaded:', auth.cookies.length);
if (auth.cookies?.length) {
await context.addCookies(auth.cookies);
console.log('✅ Cookies loaded:', auth.cookies.length);
} else {
console.log('⚠️ No cookies loaded; using manual login via browser.');
}
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' });
user = await ensureLoggedIn(page, context);