accessToken method
The access token for serverUrl, refreshed when it has expired; null
when there is none (the server's 401 starts an authorization).
Implementation
Future<String?> accessToken(String serverUrl) async {
final resource = canonicalResourceUri(serverUrl);
final grant = await options.store.loadGrant(resource);
if (grant == null) return null;
if (!grant.token.isExpired) return grant.token.accessToken;
final refresh = grant.token.refreshToken;
if (refresh == null) return null;
try {
return (await _refresh(grant, refresh)).token.accessToken;
} on OAuthError catch (e) {
_logger.warning('Refreshing the token for $resource failed: $e');
await options.store.deleteGrant(resource);
return null;
}
}