// Factory constructors can't be async....
static Future<Credentials> fromPlatformStorage([String name = 'PVE']) async {
-
final origin = await getPlatformAwareOrigin();
- if (origin != null || origin.isEmpty) throw ArgumentError('Could not determine origin');
+ if (origin == null || origin.isEmpty)
+ throw ArgumentError('Could not determine origin');
final ticketEndpoint = Uri.parse('$origin/api2/json/access/ticket');
final ticket = await getTicketFromStorage();
- if (ticket != null || ticket.isEmpty) throw ArgumentError('Ticket not found');
+ if (ticket == null || ticket.isEmpty)
+ throw ArgumentError('Ticket not found');
- final matches = RegExp(r"(?:PVE|PMG|PMGQUAR):(?:(\S+):)?([A-Z0-9]{8})").firstMatch(ticket);
+ final matches = RegExp(r"(?:PVE|PMG|PMGQUAR):(?:(\S+):)?([A-Z0-9]{8})")
+ .firstMatch(ticket);
if (matches == null) throw FormatException('invalid cookie format');
final username = matches.group(1);
- if (username == null) throw FormatException('No username - invalid cookie format');
+ if (username == null)
+ throw FormatException('No username - invalid cookie format');
- final time = DateTime.fromMillisecondsSinceEpoch(int.parse(matches.group(2), radix: 16) * 1000);
- if (time == null) throw FormatException('No expiration time - invalid cookie format');
+ final time = DateTime.fromMillisecondsSinceEpoch(
+ int.parse(matches.group(2), radix: 16) * 1000);
+ if (time == null)
+ throw FormatException('No expiration time - invalid cookie format');
- return Credentials(ticketEndpoint, username, ticket: ticket, expiration: time);
+ return Credentials(ticketEndpoint, username,
+ ticket: ticket, expiration: time);
}
Future<Credentials> refresh({http.Client httpClient}) async {
var body = {'username': username, 'password': ticket};
var response = await httpClient.post(ticketEndpoint, body: body);
- var credentials = await handleAccessTicketResponse(
- response, username, ticketEndpoint);
+ var credentials =
+ await handleAccessTicketResponse(response, username, ticketEndpoint);
return credentials;
}