Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. private static string baseUrl = "https://snoonotes.com/auth/connect/token";
  2.  
  3. static void Main(string[] args)
  4. {
  5.  
  6.     string username = "CMVModBot";
  7.     string password = "";
  8.     string clientId = "cLGbNpLYg9gt_Q";
  9.  
  10.     LoginTokenResult accessToken = GetLoginToken(username, password, clientId);
  11.     if (accessToken.AccessToken != null)
  12.     {
  13.         Console.WriteLine(accessToken);
  14.     }
  15.     else
  16.     {
  17.         Console.WriteLine("Error Occurred:{0}, {1}", accessToken.Error, accessToken.ErrorDescription);
  18.     }
  19.  
  20.  
  21.     Console.ReadLine();
  22. }
  23.  
  24. private static LoginTokenResult GetLoginToken(string username, string password, string clientId)
  25. {
  26.     string content = $"grant_type=password&username={HttpUtility.UrlEncode(username)}&password={HttpUtility.UrlEncode(password)}&client_id={HttpUtility.UrlEncode(clientId)}";
  27.  
  28.     HttpClient client = new HttpClient();
  29.     client.BaseAddress = new Uri(baseUrl);
  30.     HttpResponseMessage response = client.PostAsync("Token", new StringContent(content, Encoding.UTF8, "application/x-www-form-urlencoded")).Result;
  31.  
  32.     string resultJSON = response.Content.ReadAsStringAsync().Result;
  33.     LoginTokenResult result = JsonConvert.DeserializeObject<LoginTokenResult>(resultJSON);
  34.  
  35.     return result;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement