authorization property

Future<String?> get authorization

Implementation

Future<String?> get authorization => _lock.lock(() async {
  var token = _token.value;
  if (token == null) return null;
  if (!isTokenValid(token)) {
    final refresh = refreshToken;
    if (refresh == null) {
      _token.value = null;
      throw TokenException<T>._(token, 'Token expired');
    }
    try {
      token = _token.value = await refresh(token);
    } catch (e) {
      if (errorShouldInvalidateToken?.call(e) ?? false) _token.value = null;
      throw TokenException<T>._(token!, 'Token refresh failed', e);
    }
  }
  return authorize(token);
});