From 84dde640903e7a517db716c978399b7877933ab2 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Wed, 26 Apr 2023 11:13:00 +0200 Subject: [PATCH 1/2] specs,nextcloud: Add endpoint for deleting app password --- .../nextcloud/lib/src/nextcloud.openapi.dart | 24 +++++++++++++++++++ .../nextcloud/lib/src/nextcloud.openapi.json | 20 ++++++++++++++++ specs/core.json | 20 ++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.dart b/packages/nextcloud/lib/src/nextcloud.openapi.dart index ef49897d..db9e6912 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.dart +++ b/packages/nextcloud/lib/src/nextcloud.openapi.dart @@ -433,6 +433,30 @@ class NextcloudCoreClient { } throw NextcloudApiException.fromResponse(response); // coverage:ignore-line } + + Future deleteAppPassword() async { + const path = '/ocs/v2.php/core/apppassword'; + final queryParameters = {}; + final headers = { + 'Accept': 'application/json', + }; + Uint8List? body; + if (rootClient.authentications.map((final a) => a.id).contains('basic_auth')) { + headers.addAll(rootClient.authentications.singleWhere((final a) => a.id == 'basic_auth').headers); + } else { + throw Exception('Missing authentication for basic_auth'); + } + final response = await rootClient.doRequest( + 'delete', + Uri(path: path, queryParameters: queryParameters.isNotEmpty ? queryParameters : null).toString(), + headers, + body, + ); + if (response.statusCode == 200) { + return; + } + throw NextcloudApiException.fromResponse(response); // coverage:ignore-line + } } class NextcloudNewsClient { diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.json b/packages/nextcloud/lib/src/nextcloud.openapi.json index f41dcb88..3b7e4a4f 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.json +++ b/packages/nextcloud/lib/src/nextcloud.openapi.json @@ -2343,6 +2343,26 @@ } } }, + "/ocs/v2.php/core/apppassword": { + "delete": { + "tags": [ + "core" + ], + "operationId": "delete-app-password", + "responses": { + "200": { + "description": "App password deleted successfully", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + } + } + } + }, "/index.php/apps/news/api": { "get": { "operationId": "get-supported-api-versions", diff --git a/specs/core.json b/specs/core.json index a88c14d2..6ed8a375 100644 --- a/specs/core.json +++ b/specs/core.json @@ -1318,6 +1318,26 @@ } } } + }, + "/ocs/v2.php/core/apppassword": { + "delete": { + "tags": [ + "core" + ], + "operationId": "delete-app-password", + "responses": { + "200": { + "description": "App password deleted successfully", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + } + } + } } } } From 36345a12a01ff721ec4a45a99fbb04f53724f0dc Mon Sep 17 00:00:00 2001 From: jld3103 Date: Wed, 26 Apr 2023 11:13:16 +0200 Subject: [PATCH 2/2] neon: Delete app password when logging out --- packages/neon/neon/lib/src/blocs/accounts.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/neon/neon/lib/src/blocs/accounts.dart b/packages/neon/neon/lib/src/blocs/accounts.dart index fc12a79d..63fcf732 100644 --- a/packages/neon/neon/lib/src/blocs/accounts.dart +++ b/packages/neon/neon/lib/src/blocs/accounts.dart @@ -97,6 +97,15 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState if (aa != null && aa.id == account.id) { setActiveAccount(as.isNotEmpty ? as[0] : null); } + + unawaited(() async { + try { + await account.client.core.deleteAppPassword(); + } catch (e, s) { + debugPrint(e.toString()); + debugPrint(s.toString()); + } + }()); } @override