authenticate method
Implementation
Future<void> authenticate(Map<String, String> metadata, String uri) async {
if (_accessToken == null ||
_accessToken!.hasExpired ||
!_lastUriSet ||
uri != _lastUri) {
_accessToken = await obtainAccessCredentials(uri);
_lastUri = uri;
_lastUriSet = true;
}
final auth = '${_accessToken!.type} ${_accessToken!.data}';
metadata['authorization'] = auth;
if (_tokenExpiresSoon) {
// Token is about to expire. Extend it prematurely.
try {
await obtainAccessCredentials(_lastUri);
} catch (_) {}
}
}