getTokenResponse method

Future<TokenResponse> getTokenResponse([
  1. bool forceRefresh = false
])

Implementation

Future<TokenResponse> getTokenResponse([bool forceRefresh = false]) async {
  if (!forceRefresh &&
      _token.accessToken != null &&
      (_token.expiresAt == null ||
          _token.expiresAt!.isAfter(DateTime.now()))) {
    return _token;
  }
  if (_token.accessToken == null && _token.refreshToken == null) {
    return _token;
  }

  var json = await http.post(client.issuer.tokenEndpoint,
      body: {
        'grant_type': 'refresh_token',
        'refresh_token': _token.refreshToken,
        'client_id': client.clientId,
        if (client.clientSecret != null) 'client_secret': client.clientSecret
      },
      client: client.httpClient);

  updateToken(json);
  return _token;
}