added support for 2fa login with browser flow

This commit is contained in:
2026-08-10 20:00:38 +02:00
parent 889d8f67c5
commit ccb22a497d
13 changed files with 805 additions and 35 deletions
+18 -5
View File
@@ -7,18 +7,31 @@ import '../../api_response.dart';
abstract class WebdavApi<T> {
T genericParams;
WebdavApi(this.genericParams) {
establishWebdavConnection();
}
WebdavApi(this.genericParams);
Future<ApiResponse> run();
static Future<WebDavClient> webdav = establishWebdavConnection();
static Future<WebDavClient>? _webdav;
static String? _webdavSecret;
/// Shared WebDAV client. Rebuilt whenever the effective Nextcloud secret
/// changes (app password minted/renewed, account switch) so it never keeps
/// authenticating with stale credentials.
static Future<WebDavClient> get webdav {
final secret = AccountData().getNextcloudSecret();
if (_webdav == null || _webdavSecret != secret) {
_webdavSecret = secret;
_webdav = establishWebdavConnection();
}
return _webdav!;
}
static Future<WebDavClient> establishWebdavConnection() async =>
NextcloudClient(
Uri.parse('https://${EndpointData().nextcloud().full()}'),
password: AccountData().getPassword(),
// App password preferred — with 2FA the real password is not accepted
// by Nextcloud at all (see AccountData.usesLoginFlow).
password: AccountData().getNextcloudSecret(),
loginName: AccountData().getUsername(),
).webdav;