2023-04-29 13:18:46 -04:00
|
|
|
class AuthenticationData {
|
2023-09-30 05:15:17 -04:00
|
|
|
static const _unauthenticated = AuthenticationData(
|
|
|
|
userId: "",
|
|
|
|
token: "",
|
|
|
|
secretMachineIdHash: "",
|
|
|
|
isAuthenticated: false,
|
|
|
|
uid: "",
|
|
|
|
);
|
2023-04-29 13:18:46 -04:00
|
|
|
final String userId;
|
|
|
|
final String token;
|
2023-09-29 03:51:46 -04:00
|
|
|
final String secretMachineIdHash;
|
2023-04-29 13:18:46 -04:00
|
|
|
final bool isAuthenticated;
|
2023-09-30 05:15:17 -04:00
|
|
|
final String uid;
|
2023-04-29 13:18:46 -04:00
|
|
|
|
|
|
|
const AuthenticationData({
|
2023-09-30 05:15:17 -04:00
|
|
|
required this.userId,
|
|
|
|
required this.token,
|
|
|
|
required this.secretMachineIdHash,
|
|
|
|
required this.isAuthenticated,
|
|
|
|
required this.uid,
|
2023-04-29 13:18:46 -04:00
|
|
|
});
|
2023-09-30 05:15:17 -04:00
|
|
|
|
2023-04-29 15:26:12 -04:00
|
|
|
factory AuthenticationData.fromMap(Map map) {
|
2023-09-29 03:51:46 -04:00
|
|
|
map = map["entity"];
|
2023-04-29 15:26:12 -04:00
|
|
|
final userId = map["userId"];
|
|
|
|
final token = map["token"];
|
2023-09-29 03:51:46 -04:00
|
|
|
final machineId = map["secretMachineIdHash"];
|
2023-09-30 05:15:17 -04:00
|
|
|
final uid = map["uid"];
|
|
|
|
if (userId == null || token == null || machineId == null || uid == null) {
|
2023-04-29 13:18:46 -04:00
|
|
|
return _unauthenticated;
|
|
|
|
}
|
2023-09-30 05:15:17 -04:00
|
|
|
return AuthenticationData(userId: userId, token: token, secretMachineIdHash: machineId, isAuthenticated: true, uid: uid);
|
2023-04-29 13:18:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
factory AuthenticationData.unauthenticated() => _unauthenticated;
|
2023-05-01 11:34:34 -04:00
|
|
|
|
|
|
|
Map<String, String> get authorizationHeader => {
|
2023-09-30 05:15:17 -04:00
|
|
|
"Authorization": "res $userId:$token",
|
|
|
|
"UID": uid,
|
|
|
|
};
|
2023-05-04 07:13:24 -04:00
|
|
|
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {
|
|
|
|
"userId": userId,
|
|
|
|
"token": token,
|
2023-09-29 03:51:46 -04:00
|
|
|
"secretMachineId": secretMachineIdHash,
|
2023-09-30 05:15:17 -04:00
|
|
|
"uid": uid,
|
2023-05-04 07:13:24 -04:00
|
|
|
};
|
|
|
|
}
|
2023-09-30 05:15:17 -04:00
|
|
|
}
|