|
@@ -1,43 +1,29 @@
|
|
import 'package:dio/dio.dart';
|
|
import 'package:dio/dio.dart';
|
|
-import 'package:ente_auth/core/configuration.dart';
|
|
|
|
import 'package:ente_auth/core/errors.dart';
|
|
import 'package:ente_auth/core/errors.dart';
|
|
|
|
+import 'package:ente_auth/core/network.dart';
|
|
import 'package:ente_auth/models/authenticator/auth_entity.dart';
|
|
import 'package:ente_auth/models/authenticator/auth_entity.dart';
|
|
import 'package:ente_auth/models/authenticator/auth_key.dart';
|
|
import 'package:ente_auth/models/authenticator/auth_key.dart';
|
|
|
|
|
|
class AuthenticatorGateway {
|
|
class AuthenticatorGateway {
|
|
- final Dio _dio;
|
|
|
|
- final Configuration _config;
|
|
|
|
- late String _basedEndpoint;
|
|
|
|
|
|
+ late Dio _enteDio;
|
|
|
|
|
|
- AuthenticatorGateway(this._dio, this._config) {
|
|
|
|
- _basedEndpoint = _config.getHttpEndpoint() + "/authenticator";
|
|
|
|
|
|
+ AuthenticatorGateway() {
|
|
|
|
+ _enteDio = Network.instance.enteDio;
|
|
}
|
|
}
|
|
|
|
|
|
Future<void> createKey(String encKey, String header) async {
|
|
Future<void> createKey(String encKey, String header) async {
|
|
- await _dio.post(
|
|
|
|
- _basedEndpoint + "/key",
|
|
|
|
|
|
+ await _enteDio.post(
|
|
|
|
+ "/authenticator/key",
|
|
data: {
|
|
data: {
|
|
"encryptedKey": encKey,
|
|
"encryptedKey": encKey,
|
|
"header": header,
|
|
"header": header,
|
|
},
|
|
},
|
|
- options: Options(
|
|
|
|
- headers: {
|
|
|
|
- "X-Auth-Token": _config.getToken(),
|
|
|
|
- },
|
|
|
|
- ),
|
|
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
Future<AuthKey> getKey() async {
|
|
Future<AuthKey> getKey() async {
|
|
try {
|
|
try {
|
|
- final response = await _dio.get(
|
|
|
|
- _basedEndpoint + "/key",
|
|
|
|
- options: Options(
|
|
|
|
- headers: {
|
|
|
|
- "X-Auth-Token": _config.getToken(),
|
|
|
|
- },
|
|
|
|
- ),
|
|
|
|
- );
|
|
|
|
|
|
+ final response = await _enteDio.get("/authenticator/key");
|
|
return AuthKey.fromMap(response.data);
|
|
return AuthKey.fromMap(response.data);
|
|
} on DioError catch (e) {
|
|
} on DioError catch (e) {
|
|
if (e.response != null && (e.response!.statusCode ?? 0) == 404) {
|
|
if (e.response != null && (e.response!.statusCode ?? 0) == 404) {
|
|
@@ -51,17 +37,12 @@ class AuthenticatorGateway {
|
|
}
|
|
}
|
|
|
|
|
|
Future<AuthEntity> createEntity(String encryptedData, String header) async {
|
|
Future<AuthEntity> createEntity(String encryptedData, String header) async {
|
|
- final response = await _dio.post(
|
|
|
|
- _basedEndpoint + "/entity",
|
|
|
|
|
|
+ final response = await _enteDio.post(
|
|
|
|
+ "/authenticator/entity",
|
|
data: {
|
|
data: {
|
|
"encryptedData": encryptedData,
|
|
"encryptedData": encryptedData,
|
|
"header": header,
|
|
"header": header,
|
|
},
|
|
},
|
|
- options: Options(
|
|
|
|
- headers: {
|
|
|
|
- "X-Auth-Token": _config.getToken(),
|
|
|
|
- },
|
|
|
|
- ),
|
|
|
|
);
|
|
);
|
|
return AuthEntity.fromMap(response.data);
|
|
return AuthEntity.fromMap(response.data);
|
|
}
|
|
}
|
|
@@ -71,50 +52,35 @@ class AuthenticatorGateway {
|
|
String encryptedData,
|
|
String encryptedData,
|
|
String header,
|
|
String header,
|
|
) async {
|
|
) async {
|
|
- await _dio.put(
|
|
|
|
- _basedEndpoint + "/entity",
|
|
|
|
|
|
+ await _enteDio.put(
|
|
|
|
+ "/authenticator/entity",
|
|
data: {
|
|
data: {
|
|
"id": id,
|
|
"id": id,
|
|
"encryptedData": encryptedData,
|
|
"encryptedData": encryptedData,
|
|
"header": header,
|
|
"header": header,
|
|
},
|
|
},
|
|
- options: Options(
|
|
|
|
- headers: {
|
|
|
|
- "X-Auth-Token": _config.getToken(),
|
|
|
|
- },
|
|
|
|
- ),
|
|
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
Future<void> deleteEntity(
|
|
Future<void> deleteEntity(
|
|
String id,
|
|
String id,
|
|
) async {
|
|
) async {
|
|
- await _dio.delete(
|
|
|
|
- _basedEndpoint + "/entity",
|
|
|
|
|
|
+ await _enteDio.delete(
|
|
|
|
+ "/authenticator/entity",
|
|
queryParameters: {
|
|
queryParameters: {
|
|
"id": id,
|
|
"id": id,
|
|
},
|
|
},
|
|
- options: Options(
|
|
|
|
- headers: {
|
|
|
|
- "X-Auth-Token": _config.getToken(),
|
|
|
|
- },
|
|
|
|
- ),
|
|
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
Future<List<AuthEntity>> getDiff(int sinceTime, {int limit = 500}) async {
|
|
Future<List<AuthEntity>> getDiff(int sinceTime, {int limit = 500}) async {
|
|
try {
|
|
try {
|
|
- final response = await _dio.get(
|
|
|
|
- _basedEndpoint + "/entity/diff",
|
|
|
|
|
|
+ final response = await _enteDio.get(
|
|
|
|
+ "/authenticator/entity/diff",
|
|
queryParameters: {
|
|
queryParameters: {
|
|
"sinceTime": sinceTime,
|
|
"sinceTime": sinceTime,
|
|
"limit": limit,
|
|
"limit": limit,
|
|
},
|
|
},
|
|
- options: Options(
|
|
|
|
- headers: {
|
|
|
|
- "X-Auth-Token": _config.getToken(),
|
|
|
|
- },
|
|
|
|
- ),
|
|
|
|
);
|
|
);
|
|
final List<AuthEntity> authEntities = <AuthEntity>[];
|
|
final List<AuthEntity> authEntities = <AuthEntity>[];
|
|
final diff = response.data["diff"] as List;
|
|
final diff = response.data["diff"] as List;
|