parseGrant static method
Parse { "token": ..., "expires_at"|"expires_in": ... } from your backend.
Implementation
static Grant parseGrant(Map<String, dynamic> json) {
final token = json['token'];
if (token is! String) {
throw ArgumentError("Backend token response missing 'token'");
}
final expiresAt = json['expires_at'];
if (expiresAt is String) {
final parsed = DateTime.tryParse(expiresAt);
if (parsed != null) return Grant(token, parsed);
}
final expiresIn = json['expires_in'];
if (expiresIn is num) {
return Grant(token, DateTime.now().add(Duration(seconds: expiresIn.toInt())));
}
return Grant(token, DateTime.now().add(const Duration(seconds: 60)));
}