public static async Task <UserObjectResponse> GetUserInfo(AccessCodeResponse authInfo) { using var http = new HttpClient(); http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authInfo.TokenType, authInfo.AccessToken); var res = await http.GetAsync(new Uri("https://discordapp.com/api/users/@me")); if (!res.IsSuccessStatusCode) { throw new HttpRequestException(res.ReasonPhrase); } return(JsonConvert.DeserializeObject <UserObjectResponse>(await res.Content.ReadAsStringAsync())); }
private async Task RefreshAccessInformation(CancellationToken token) { while (true) { if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } if (AccessInformation == null) { await Task.Delay(1000); continue; } await Task.Delay((AccessInformation.ExpiresIn - 100) * 1000, token); AccessInformation = await Refresh(AccessInformation.RefreshToken); } }