isTokenValid static method
Method that checks if the current token is still valid to be used by the Fitbit APIs OAuth or it is expired.
Implementation
static FutureOr<bool> isTokenValid(
{required FitbitCredentials fitbitCredentials}) async {
// Instantiate Dio and its Response
Dio dio = Dio();
late Response response;
final fitbitUrl = FitbitAuthAPIURL.isTokenValid(
fitbitAccessToken: fitbitCredentials.fitbitAccessToken);
//Get the response
try {
response = await dio.post(
fitbitUrl.url,
data: fitbitUrl.data,
options: Options(
contentType: Headers.formUrlEncodedContentType,
headers: {
'Authorization': fitbitUrl.authorizationHeader,
},
),
);
} on DioError catch (e) {
if (e.response!.statusCode == 401) {
return false;
}
}
// Debugging
final logger = Logger();
logger.i('$response');
// get token status and return it
return response.data['active'] as bool;
}