Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static RiotAuthToken GetLoginToken(string username, string password, RegionData regionData, RiotAuthOpenIdConfiguration config)
- {
- HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(config.TokenEndpoint);
- httpWebRequest.Method = "POST";
- ProxyData proxy = ProxyHelper.GetProxy(true);
- httpWebRequest.Proxy = new WebProxy(proxy.Host, proxy.Port);
- httpWebRequest.Host = config.TokenEndpoint.Replace("//", "/").Split(new char[]
- {
- '/'
- })[1];
- httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
- httpWebRequest.UserAgent = "RiotClient/18.0.0 (rso-auth)";
- httpWebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
- httpWebRequest.ProtocolVersion = HttpVersion.Version11;
- httpWebRequest.ContentType = "application/x-www-form-urlencoded";
- string value = Guid.NewGuid().ToString("N");
- httpWebRequest.Headers.Set("X-Riot-DSID", value);
- httpWebRequest.Accept = "application/json";
- string s = string.Concat(new string[]
- {
- "client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&client_assertion=",
- regionData.Rso.Token,
- "&grant_type=password&",
- string.Format("username={0}|{1}&", regionData.PlatformId, username),
- "password=",
- password,
- "&scope=openid offline_access lol ban profile email phone"
- });
- byte[] bytes = Encoding.UTF8.GetBytes(s);
- httpWebRequest.ContentLength = (long)bytes.Length;
- httpWebRequest.ServicePoint.Expect100Continue = false;
- httpWebRequest.Headers.Remove(HttpRequestHeader.Pragma);
- try
- {
- Stream requestStream = httpWebRequest.GetRequestStream();
- requestStream.Write(bytes, 0, bytes.Length);
- requestStream.Close();
- }
- catch
- {
- return StaticHelper.SettingsSave.Proxy ? new RiotAuthToken(RiotAuthResult.BadProxy, null, proxy.Host, regionData) : new RiotAuthToken(RiotAuthResult.ConProblem, null, proxy.Host, regionData);
- }
- RiotAuthToken result;
- try
- {
- Stream responseStream = ((HttpWebResponse)httpWebRequest.GetResponse()).GetResponseStream();
- if (responseStream == null)
- {
- throw new InvalidOperationException();
- }
- using (StreamReader streamReader = new StreamReader(responseStream))
- {
- string accessTokenJson = streamReader.ReadToEnd();
- result = new RiotAuthToken(RiotAuthResult.Success, accessTokenJson, proxy.Host, regionData);
- }
- }
- catch (WebException ex)
- {
- using (WebResponse response = ex.Response)
- {
- using (Stream responseStream2 = response.GetResponseStream())
- {
- Stream stream = responseStream2;
- if (stream == null)
- {
- throw new InvalidOperationException();
- }
- using (StreamReader streamReader2 = new StreamReader(stream))
- {
- string text = streamReader2.ReadToEnd();
- if (text.Contains("invalid_credentials"))
- {
- result = new RiotAuthToken(RiotAuthResult.InvalidCredentials, null, proxy.Host, regionData);
- }
- else if (text.Contains("rate_limited"))
- {
- result = new RiotAuthToken(RiotAuthResult.TooManyReq, null, proxy.Host, regionData);
- }
- else
- {
- result = new RiotAuthToken(RiotAuthResult.UnknownReason, null, proxy.Host + text, regionData);
- }
- }
- }
- }
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement