示例#1
0
        private async Task <string> GetAccessToken(string login, string password)
        {
            using (var client = new HttpClient())
            {
                var dict = new Dictionary <string, string>();
                dict.Add("client_id", "gamecenter.mail.ru");
                dict.Add("grant_type", "password");
                dict.Add("username", login);
                dict.Add("password", password.Decrypt(EnvironmentExtensions.GetSecret()));

                var content = new FormUrlEncodedContent(dict);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
                client.DefaultRequestHeaders.Add("User-Agent", _userAgent);

                var response = client.PostAsync(
                    "https://o2.mail.ru/token",
                    content).Result;
                response.EnsureSuccessStatusCode();
                var token = await response.Content.ReadAsAsync <AuthModel>();

                return(token.AccessToken);
            }
        }