refreshToken method
Refreshes the authorization token.
Implementation
Future<TokenResponse> refreshToken({String refreshToken = ""}) async {
if (refreshToken.isEmpty) {
refreshToken = _lastTokenResponse?.refresh_token ?? "";
}
var credentials = "$clientId:$clientSecret";
Codec<String, String> stringToBase64Url = utf8.fuse(base64Url);
String encoded = stringToBase64Url.encode(credentials);
Map<String, String> headers = {
"Authorization": "Basic " + encoded,
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
};
Map<String, String> body = {
"refresh_token": refreshToken,
"grant_type": "refresh_token"
};
Uri tokenUri = Uri.parse(tokenEndpoint);
//print("tokenUri $tokenUri}");
final response = await http.post(tokenUri, body: body,
headers: headers);
if(response.statusCode == 200) {
//print (response.body);
_lastTokenResponse = TokenResponse.fromJson(jsonDecode(response.body));
return _lastTokenResponse!;
}
else {
//print(response.body);
throw TokenRequestFailedException(response.statusCode, response.body);
}
}