refreshToken method
Refresh an expired access token.
Implementation
Future<OAuthTokens> refreshToken({
required String refreshToken,
List<String>? scopes,
}) async {
final response = await _httpClient.post(
Uri.parse(config.tokenUrl),
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: {
'grant_type': 'refresh_token',
'refresh_token': refreshToken,
'client_id': config.clientId,
'scope': (scopes ?? config.scopes).join(' '),
},
);
if (response.statusCode != 200) {
throw OAuthException(
'Token refresh failed (${response.statusCode}): ${response.body}',
);
}
return _parseTokenResponse(response.body);
}