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
+7 -42
View File
@@ -43,7 +43,7 @@ export class AgrarmonitorConnector implements AgrarmonitorConnectorResult {
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;
}
@@ -426,50 +426,17 @@ export class AgrarmonitorConnector implements AgrarmonitorConnectorResult {
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');
}
private async performAutoLogin(): Promise<void> {
try {
await this.performAuthLogin();
} catch (authError) {
this.logger?.warn?.('Agrarmonitor-Login via /auth/login fehlgeschlagen, versuche Legacy-Login', authError);
await this.performLegacyLogin();
}
}
private async performAuthLogin(): Promise<void> {
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');
}
}
private async performLegacyLogin(): Promise<void> {
private async performRedirectLogin(): Promise<void> {
const loginPageResponse = await this.http.get('/');
const loginPageText = typeof loginPageResponse.data === 'string' ? loginPageResponse.data : '';
@@ -493,7 +460,7 @@ export class AgrarmonitorConnector implements AgrarmonitorConnectorResult {
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');
}
}
@@ -513,8 +480,6 @@ export class AgrarmonitorConnector implements AgrarmonitorConnectorResult {
return (
response.status === 401 ||
response.status === 403 ||
responseUrl.includes('/auth/login') ||
responseText.includes('/auth/login') ||
this.isLoginPageText(responseText) ||
responseText.includes('Anmeldung') ||
responseText.includes('Einloggen')
+1 -1
View File
@@ -19,7 +19,7 @@ export interface CookieStore {
clear(): Promise<void>;
}
export type AgrarmonitorLoginStrategy = 'auto' | 'auth' | 'legacy';
export type AgrarmonitorLoginStrategy = 'redirect' | 'legacy' | 'auto';
export interface AgrarmonitorConnectorOptions {
baseUrl?: string;