Use redirect login flow only

This commit is contained in:
2026-05-25 11:37:21 +02:00
parent cf6bc1b5cc
commit cd89a30631
9 changed files with 21 additions and 89 deletions
+6 -39
View File
@@ -29,7 +29,7 @@ class AgrarmonitorConnector {
this.timeoutMs = options.timeoutMs ?? 15000;
this.autoLogin = options.autoLogin ?? true;
this.autoRetry = options.autoRetry ?? true;
this.loginStrategy = options.loginStrategy ?? 'auto';
this.loginStrategy = options.loginStrategy ?? 'redirect';
this.logger = options.logger;
}
async init() {
@@ -315,45 +315,14 @@ class AgrarmonitorConnector {
throw new Error('Agrarmonitor-Credentials nicht konfiguriert');
}
this.logger?.info?.('Fuehre Agrarmonitor-Login durch');
if (this.loginStrategy === 'auth') {
await this.performAuthLogin();
}
else if (this.loginStrategy === 'legacy') {
await this.performLegacyLogin();
}
else {
await this.performAutoLogin();
if (this.loginStrategy === 'auto') {
this.logger?.warn?.('loginStrategy "auto" ist veraltet; verwende Redirect-Login');
}
await this.performRedirectLogin();
await this.options.cookieStore.save(this.cookieJar);
this.logger?.info?.('Agrarmonitor-Login erfolgreich');
}
async performAutoLogin() {
try {
await this.performAuthLogin();
}
catch (authError) {
this.logger?.warn?.('Agrarmonitor-Login via /auth/login fehlgeschlagen, versuche Legacy-Login', authError);
await this.performLegacyLogin();
}
}
async performAuthLogin() {
await this.http.get('/auth/login');
const loginData = new URLSearchParams({
email: this.options.username,
password: this.options.password,
remember: 'on',
});
const response = await this.http.post('/auth/login', loginData, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});
const responseText = typeof response.data === 'string' ? response.data : '';
if (responseText.includes('Anmeldung fehlgeschlagen')) {
throw new Error('Agrarmonitor-Login fehlgeschlagen');
}
}
async performLegacyLogin() {
async performRedirectLogin() {
const loginPageResponse = await this.http.get('/');
const loginPageText = typeof loginPageResponse.data === 'string' ? loginPageResponse.data : '';
if (!this.isLoginPageText(loginPageText)) {
@@ -372,7 +341,7 @@ class AgrarmonitorConnector {
});
const responseText = typeof response.data === 'string' ? response.data : '';
if (this.isLoginPageText(responseText)) {
throw new Error('Agrarmonitor-Legacy-Login fehlgeschlagen');
throw new Error('Agrarmonitor-Redirect-Login fehlgeschlagen');
}
}
async isSessionValid() {
@@ -389,8 +358,6 @@ class AgrarmonitorConnector {
const responseText = typeof response.data === 'string' ? response.data : '';
return (response.status === 401 ||
response.status === 403 ||
responseUrl.includes('/auth/login') ||
responseText.includes('/auth/login') ||
this.isLoginPageText(responseText) ||
responseText.includes('Anmeldung') ||
responseText.includes('Einloggen'));