* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file netdiag/api/auth.php * \ingroup netdiag * \brief API-Endpunkt: Anmeldung der mobilen App, liefert ein Token. * * POST {login, password} -> {token, expiresIn, user} * * Das Token stellt seit v1.4.0 das zentrale Auth-Modul awlauth aus (gleicher * Schlüssel und gleiche Sitzungs-Registry wie alle anderen AWL-Apps, damit ein * verlorenes Handy an EINER Stelle abgemeldet werden kann). Da die App im * Capacitor-WebView auf einem eigenen Origin läuft, kann sie das SSO-Cookie * nicht nutzen — sie bekommt denselben Token im Antwort-Body und schickt ihn * als "Authorization: Bearer ..." zurück. * * Die ANTWORTFORM ist bewusst unverändert geblieben: bereits installierte * APKs lesen {token, expiresIn, user} und laufen nach einer einmaligen * Neuanmeldung ohne Update weiter. */ require_once __DIR__.'/netdiag_api.lib.php'; netdiag_api_bootstrap(); /** @var DoliDB $db */ if ($_SERVER['REQUEST_METHOD'] !== 'POST') { netdiag_api_error('Nur POST erlaubt', 405); } $body = netdiag_api_read_body(); $login = isset($body['login']) ? trim((string) $body['login']) : ''; $password = isset($body['password']) ? (string) $body['password'] : ''; if ($login === '' || $password === '') { netdiag_api_error('Login und Passwort erforderlich', 400); } require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; /* * Anmeldung ausschließlich über awlauth — Rate-Limit, Passwortprüfung, * SSO-Eignung und die zentrale Sitzungsliste kommen von dort, wie in allen * anderen AWL-Apps. * * Der frühere Rückfallweg mit modul-eigenem JWT ist am 17.08.2026 entfallen * (APK-Rollout abgeschlossen). Er stellte Tokens aus, die an der * awlauth-Geräteliste vorbeiliefen: „Gerät abmelden" hatte darauf keine * Wirkung. Lieber ein klarer Fehler als eine zweite, unsichtbare Sitzungsart. * * Die Gültigkeit bestimmt jetzt allein `AWLAUTH_TTL` (awlauth-Setup, * Standard 7 Tage) — es gibt keine konkurrierende Einstellung mehr im * NetDiag-Setup. */ if (!netdiag_awlauth_available()) { netdiag_api_error('Anmeldung nicht möglich: das Modul AWL-Auth ist nicht aktiv', 503); } { $res = awlauth_login($login, $password); if (empty($res['success'])) { netdiag_api_error($res['error'], (int) $res['http']); } $user = $res['user']; if (!$user->hasRight('netdiag', 'protocol', 'read')) { netdiag_api_error('Keine Berechtigung für NetDiag', 403); } // Gerätebezeichnung für die awlauth-Geräteliste. Ein WebView meldet sich // als Chrome — ohne eigenen Namen wäre die App dort nicht wiederzuerkennen. $ua = isset($_SERVER['HTTP_USER_AGENT']) ? (string) $_SERVER['HTTP_USER_AGENT'] : ''; $label = 'NetDiag-App'; if ($ua !== '' && function_exists('awlauth_device_label')) { $parts = explode(' · ', awlauth_device_label($ua)); if (!empty($parts[0])) { $label .= ' · '.$parts[0]; } } $issued = awlauth_issue_bearer($user, 0, 'password', $label); if ($issued === null) { netdiag_api_error('Anmeldung konnte nicht abgeschlossen werden', 500); } $token = $issued['token']; $ttl = (int) $issued['expiresIn']; } netdiag_api_respond(array( 'token' => $token, 'expiresIn' => $ttl, 'user' => array( 'id' => (int) $user->id, 'login' => $user->login, 'name' => $user->getFullName($langs), 'email' => $user->email, 'canWrite' => (bool) $user->hasRight('netdiag', 'protocol', 'write'), ), ));