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