@@ -6,91 +6,6 @@ class AuthenticationProvider {
66 AppAuthentication ? currentAppAuthentication;
77 dio.CancelToken ? _cancelToken;
88
9- Future <AppAuthentication > authenticate ({
10- required String serverUrl,
11- required String username,
12- required String originalBasicAuth,
13- required bool isSelfSignedCertificate,
14- }) async {
15- assert (URLUtils .isSanitized (serverUrl));
16-
17- final urlInitialCall = '$serverUrl /ocs/v2.php/core/getapppassword' ;
18-
19- dio.Response response;
20- try {
21- final client = dio.Dio ();
22- if (isSelfSignedCertificate) {
23- client.httpClientAdapter = IOHttpClientAdapter (
24- onHttpClientCreate: (client) {
25- client.badCertificateCallback = (cert, host, port) => true ;
26- return client;
27- },
28- );
29- }
30-
31- response = await client.get (
32- urlInitialCall,
33- options: dio.Options (
34- headers: {
35- 'OCS-APIREQUEST' : 'true' ,
36- 'User-Agent' : 'Cookbook App' ,
37- 'authorization' : originalBasicAuth
38- },
39- validateStatus: (status) => status! < 500 ,
40- ),
41- cancelToken: _cancelToken,
42- );
43- } on dio.DioError catch (e) {
44- if (e.message? .contains ('SocketException' ) ?? false ) {
45- throw translate (
46- 'login.errors.not_reachable' ,
47- args: {'server_url' : serverUrl, 'error_msg' : e},
48- );
49- } else if (e.message? .contains ('CERTIFICATE_VERIFY_FAILED' ) ?? false ) {
50- throw translate (
51- 'login.errors.certificate_failed' ,
52- args: {'server_url' : serverUrl, 'error_msg' : e},
53- );
54- }
55- throw translate ('login.errors.request_failed' , args: {'error_msg' : e});
56- }
57- _cancelToken = null ;
58-
59- if (response.statusCode == 200 ) {
60- String appPassword;
61- try {
62- appPassword = XmlDocument .parse (response.data as String )
63- .findAllElements ('apppassword' )
64- .first
65- .text;
66- } on XmlParserException catch (e) {
67- throw translate ('login.errors.parse_failed' , args: {'error_msg' : e});
68- // ignore: avoid_catching_errors
69- } on StateError catch (e) {
70- throw translate ('login.errors.parse_missing' , args: {'error_msg' : e});
71- }
72-
73- final basicAuth = AppAuthentication .parseBasicAuth (username, appPassword);
74-
75- return AppAuthentication (
76- server: serverUrl,
77- loginName: username,
78- basicAuth: basicAuth,
79- isSelfSignedCertificate: isSelfSignedCertificate,
80- );
81- } else if (response.statusCode == 401 ) {
82- throw translate ('login.errors.auth_failed' );
83- } else {
84- throw translate (
85- 'login.errors.failure' ,
86- args: {
87- 'status_code' : response.statusCode,
88- 'status_message' : response.statusMessage,
89- },
90- );
91- }
92- }
93-
949 Future <AppAuthentication > authenticateAppPassword ({
9510 required String serverUrl,
9611 required String username,
@@ -125,7 +40,7 @@ class AuthenticationProvider {
12540 return AppAuthentication (
12641 server: serverUrl,
12742 loginName: username,
128- basicAuth : basicAuth,
43+ appPassword : basicAuth,
12944 isSelfSignedCertificate: isSelfSignedCertificate,
13045 );
13146 } else {
@@ -221,10 +136,14 @@ class AuthenticationProvider {
221136 Future <void > deleteAppAuthentication () async {
222137 dio.Response ? response;
223138 try {
224- response = await currentAppAuthentication ? .authenticatedClient .delete (
139+ response = await Dio () .delete (
225140 '${currentAppAuthentication !.server }/ocs/v2.php/core/apppassword' ,
226141 options: dio.Options (
227142 headers: {
143+ 'Authorization' : AppAuthentication .parsePassword (
144+ currentAppAuthentication! .loginName,
145+ currentAppAuthentication! .appPassword,
146+ ),
228147 'OCS-APIREQUEST' : 'true' ,
229148 },
230149 ),
0 commit comments