Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. public static RiotAuthToken GetLoginToken(string username, string password, RegionData regionData, RiotAuthOpenIdConfiguration config)
  2. {
  3. HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(config.TokenEndpoint);
  4. httpWebRequest.Method = "POST";
  5. ProxyData proxy = ProxyHelper.GetProxy(true);
  6. httpWebRequest.Proxy = new WebProxy(proxy.Host, proxy.Port);
  7. httpWebRequest.Host = config.TokenEndpoint.Replace("//", "/").Split(new char[]
  8. {
  9. '/'
  10. })[1];
  11. httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
  12. httpWebRequest.UserAgent = "RiotClient/18.0.0 (rso-auth)";
  13. httpWebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
  14. httpWebRequest.ProtocolVersion = HttpVersion.Version11;
  15. httpWebRequest.ContentType = "application/x-www-form-urlencoded";
  16. string value = Guid.NewGuid().ToString("N");
  17. httpWebRequest.Headers.Set("X-Riot-DSID", value);
  18. httpWebRequest.Accept = "application/json";
  19. string s = string.Concat(new string[]
  20. {
  21. "client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&client_assertion=",
  22. regionData.Rso.Token,
  23. "&grant_type=password&",
  24. string.Format("username={0}|{1}&", regionData.PlatformId, username),
  25. "password=",
  26. password,
  27. "&scope=openid offline_access lol ban profile email phone"
  28. });
  29. byte[] bytes = Encoding.UTF8.GetBytes(s);
  30. httpWebRequest.ContentLength = (long)bytes.Length;
  31. httpWebRequest.ServicePoint.Expect100Continue = false;
  32. httpWebRequest.Headers.Remove(HttpRequestHeader.Pragma);
  33. try
  34. {
  35. Stream requestStream = httpWebRequest.GetRequestStream();
  36. requestStream.Write(bytes, 0, bytes.Length);
  37. requestStream.Close();
  38. }
  39. catch
  40. {
  41. return StaticHelper.SettingsSave.Proxy ? new RiotAuthToken(RiotAuthResult.BadProxy, null, proxy.Host, regionData) : new RiotAuthToken(RiotAuthResult.ConProblem, null, proxy.Host, regionData);
  42. }
  43. RiotAuthToken result;
  44. try
  45. {
  46. Stream responseStream = ((HttpWebResponse)httpWebRequest.GetResponse()).GetResponseStream();
  47. if (responseStream == null)
  48. {
  49. throw new InvalidOperationException();
  50. }
  51. using (StreamReader streamReader = new StreamReader(responseStream))
  52. {
  53. string accessTokenJson = streamReader.ReadToEnd();
  54. result = new RiotAuthToken(RiotAuthResult.Success, accessTokenJson, proxy.Host, regionData);
  55. }
  56. }
  57. catch (WebException ex)
  58. {
  59. using (WebResponse response = ex.Response)
  60. {
  61. using (Stream responseStream2 = response.GetResponseStream())
  62. {
  63. Stream stream = responseStream2;
  64. if (stream == null)
  65. {
  66. throw new InvalidOperationException();
  67. }
  68. using (StreamReader streamReader2 = new StreamReader(stream))
  69. {
  70. string text = streamReader2.ReadToEnd();
  71. if (text.Contains("invalid_credentials"))
  72. {
  73. result = new RiotAuthToken(RiotAuthResult.InvalidCredentials, null, proxy.Host, regionData);
  74. }
  75. else if (text.Contains("rate_limited"))
  76. {
  77. result = new RiotAuthToken(RiotAuthResult.TooManyReq, null, proxy.Host, regionData);
  78. }
  79. else
  80. {
  81. result = new RiotAuthToken(RiotAuthResult.UnknownReason, null, proxy.Host + text, regionData);
  82. }
  83. }
  84. }
  85. }
  86. }
  87. return result;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement