public async Task <string> FetchToken() { var now = DateTime.UtcNow; if (_token == null || _tokenExpiry == null || _tokenExpiry < now) { _token = await _fetcher.FetchToken().ConfigureAwait(false); _tokenExpiry = ParseExpiry(_token); } if (_token == null) { throw new CredentialsException("Could not refresh token"); } return(_token); }
private async Task <Metadata> GetMetadataAsync(bool includeToken) { var metadata = new Metadata(); metadata.Add("sdk_language", "csharp"); metadata.Add("sdk_version", _version); if (!includeToken || this._auth == null) { return(metadata); } var token = await _auth.FetchToken().ConfigureAwait(false); metadata.Add("authorization", $"Bearer {token}"); return(metadata); }