validate function Null safety

Future<bool> validate(
  1. String accessToken,
  2. {String? clientToken}
)

Checks if given accessToken and clientToken are still valid.

clientToken is optional, though if provided should match the client token that was used to obtained given accessToken.

Implementation

Future<bool> validate(String accessToken, {String? clientToken}) async {
  final headers = {
    'content-type': 'application/json',
  };
  final payload = {
    'accessToken': accessToken,
  };
  if (clientToken != null) {
    payload.putIfAbsent('clientToken', () => clientToken);
  }

  final response = await requestBody(
      http.post, _authServerApi, 'validate', payload,
      headers: headers);
  return response.statusCode == 204;
}