Fixes for nested query parsing and MFA route authentication types

This commit is contained in:
Jake Barnby
2024-02-07 19:23:32 +13:00
parent 3020664d09
commit f8081dd2ce
8 changed files with 9 additions and 210 deletions
@@ -1,23 +0,0 @@
import 'package:appwrite/appwrite.dart';
void main() { // Init SDK
Client client = Client();
Users users = Users(client);
client
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
.setProject('5df5acd0d48c2') // Your project ID
;
Future result = users.deleteAuthenticator(
userId:'[USER_ID]' ,
provider: AuthenticatorProvider.totp.value,
otp:'[OTP]' ,
);
result
.then((response) {
print(response);
}).catchError((error) {
print(error.response);
});
}
-21
View File
@@ -1,21 +0,0 @@
import 'package:appwrite/appwrite.dart';
void main() { // Init SDK
Client client = Client();
Users users = Users(client);
client
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
.setProject('5df5acd0d48c2') // Your project ID
;
Future result = users.listProviders(
userId:'[USER_ID]' ,
);
result
.then((response) {
print(response);
}).catchError((error) {
print(error.response);
});
}
-1
View File
@@ -38,4 +38,3 @@ part 'services/locale.dart';
part 'services/messaging.dart';
part 'services/storage.dart';
part 'services/teams.dart';
part 'services/users.dart';
-44
View File
@@ -1,44 +0,0 @@
part of appwrite;
/// The Users service allows you to manage your project users.
class Users extends Service {
/// Initializes a [Users] service
Users(super.client);
/// Delete Authenticator
///
Future<models.User> deleteAuthenticator({required String userId, required enums.AuthenticatorProvider provider, required String otp}) async {
final String apiPath = '/users/{userId}/mfa/{provider}'.replaceAll('{userId}', userId).replaceAll('{provider}', provider);
final Map<String, dynamic> apiParams = {
'otp': otp,
};
final Map<String, String> apiHeaders = {
'content-type': 'application/json',
};
final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders);
return models.User.fromMap(res.data);
}
/// List Providers
///
Future<models.MfaProviders> listProviders({required String userId}) async {
final String apiPath = '/users/{userId}/providers'.replaceAll('{userId}', userId);
final Map<String, dynamic> apiParams = {
};
final Map<String, String> apiHeaders = {
'content-type': 'application/json',
};
final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders);
return models.MfaProviders.fromMap(res.data);
}
}
+1 -1
View File
@@ -53,7 +53,7 @@ class Session implements Model {
/// Returns true if this the current user session.
final bool current;
/// Returns a list of active session factors.
final int factors;
final List factors;
/// Secret used to authenticate the user. Only included if the request was made with an API key
final String secret;
+6 -6
View File
@@ -641,7 +641,7 @@ void main() {
'countryCode': 'US',
'countryName': 'United States',
'current': true,
'factors': 1,
'factors': [],
'secret': '5e5bb8c16897e',};
@@ -683,7 +683,7 @@ void main() {
'countryCode': 'US',
'countryName': 'United States',
'current': true,
'factors': 1,
'factors': [],
'secret': '5e5bb8c16897e',};
@@ -727,7 +727,7 @@ void main() {
'countryCode': 'US',
'countryName': 'United States',
'current': true,
'factors': 1,
'factors': [],
'secret': '5e5bb8c16897e',};
@@ -783,7 +783,7 @@ void main() {
'countryCode': 'US',
'countryName': 'United States',
'current': true,
'factors': 1,
'factors': [],
'secret': '5e5bb8c16897e',};
@@ -827,7 +827,7 @@ void main() {
'countryCode': 'US',
'countryName': 'United States',
'current': true,
'factors': 1,
'factors': [],
'secret': '5e5bb8c16897e',};
@@ -870,7 +870,7 @@ void main() {
'countryCode': 'US',
'countryName': 'United States',
'current': true,
'factors': 1,
'factors': [],
'secret': '5e5bb8c16897e',};
-112
View File
@@ -1,112 +0,0 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:appwrite/models.dart' as models;
import 'package:appwrite/src/enums.dart';
import 'package:appwrite/src/response.dart';
import 'dart:typed_data';
import 'package:appwrite/appwrite.dart';
class MockClient extends Mock implements Client {
Map<String, String> config = {'project': 'testproject'};
String endPoint = 'https://localhost/v1';
@override
Future<Response> call(
HttpMethod? method, {
String path = '',
Map<String, String> headers = const {},
Map<String, dynamic> params = const {},
ResponseType? responseType,
}) async {
return super.noSuchMethod(Invocation.method(#call, [method]),
returnValue: Response());
}
@override
Future webAuth(
Uri? url,
{
String? callbackUrlScheme,
}
) async {
return super.noSuchMethod(Invocation.method(#webAuth, [url]), returnValue: 'done');
}
@override
Future<Response> chunkedUpload({
String? path,
Map<String, dynamic>? params,
String? paramName,
String? idParamName,
Map<String, String>? headers,
Function(UploadProgress)? onProgress,
}) async {
return super.noSuchMethod(Invocation.method(#chunkedUpload, [path, params, paramName, idParamName, headers]), returnValue: Response(data: {}));
}
}
void main() {
group('Users test', () {
late MockClient client;
late Users users;
setUp(() {
client = MockClient();
users = Users(client);
});
test('test method deleteAuthenticator()', () async {
final Map<String, dynamic> data = {
'\$id': '5e5ea5c16897e',
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
'\$updatedAt': '2020-10-15T06:38:00.000+00:00',
'name': 'John Doe',
'registration': '2020-10-15T06:38:00.000+00:00',
'status': true,
'labels': [],
'passwordUpdate': '2020-10-15T06:38:00.000+00:00',
'email': 'john@appwrite.io',
'phone': '+4930901820',
'emailVerification': true,
'phoneVerification': true,
'mfa': true,
'totp': true,
'prefs': <String, dynamic>{},
'targets': [],
'accessedAt': '2020-10-15T06:38:00.000+00:00',};
when(client.call(
HttpMethod.delete,
)).thenAnswer((_) async => Response(data: data));
final response = await users.deleteAuthenticator(
userId: '[USER_ID]',
provider: 'totp',
otp: '[OTP]',
);
expect(response, isA<models.User>());
});
test('test method listProviders()', () async {
final Map<String, dynamic> data = {
'totp': true,
'phone': true,
'email': true,};
when(client.call(
HttpMethod.get,
)).thenAnswer((_) async => Response(data: data));
final response = await users.listProviders(
userId: '[USER_ID]',
);
expect(response, isA<models.MfaProviders>());
});
});
}
+2 -2
View File
@@ -31,7 +31,7 @@ void main() {
countryCode: 'US',
countryName: 'United States',
current: true,
factors: 1,
factors: [],
secret: '5e5bb8c16897e',
);
@@ -63,7 +63,7 @@ void main() {
expect(result.countryCode, 'US');
expect(result.countryName, 'United States');
expect(result.current, true);
expect(result.factors, 1);
expect(result.factors, []);
expect(result.secret, '5e5bb8c16897e');
});
});