create method
Validates and stores a record, pruning expired entries first.
Duplicate device or user-code digests throw StateError. At capacity, the oldest insertion-order record is evicted.
Implementation
@override
Future<AuthDeviceAuthorization> create(
AuthDeviceAuthorization authorization,
) async {
_validate(authorization);
_removeExpired(DateTime.now().toUtc());
if (_records.containsKey(authorization.deviceCodeHash) ||
_records.values.any(
(record) => record.userCodeHash == authorization.userCodeHash,
)) {
throw StateError('Device authorization code already exists');
}
while (_records.length >= maxEntries) {
_records.remove(_records.keys.first);
}
_records[authorization.deviceCodeHash] = authorization;
return authorization;
}