authenticate method
Implementation
Future<bool> authenticate() async {
try {
String auth = base64.encode(("$consumer_key:$consumer_secret").codeUnits);
final response = await _client.post(Uri.https(Constants.url, "/token"), headers: {"Authorization" : "Basic $auth"}, body: {
"grant_type" : "client_credentials",
"scope" : Constants.scope
});
final data = jsonDecode(response.body) as Map<String, dynamic>;
_token = data["access_token"];
_expireTime = DateTime.now().millisecondsSinceEpoch + data["expires_in"] as int;
return _token.isNotEmpty;
} on Exception{
return false;
}
}