public static StoreInfo GetStoreIpRp(RiotAuthToken token, RegionData regionData) { //Create the Webrequest and make it look like it is coming from the RiotClient var client = (HttpWebRequest)WebRequest.Create(regionData.Servers.Store.StoreUrl + "/storefront/v2/wallet?language=en_US"); client.Method = WebRequestMethods.Http.Get; if (token.Proxy != null) { client.Proxy = token.Proxy; } client.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; client.UserAgent = "RiotClient/18.0.0 (lol-store)"; client.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache); client.ProtocolVersion = HttpVersion.Version11; client.Accept = "application/json"; client.Headers.Set(HttpRequestHeader.Authorization, token.AccessTokenJson.TokenType + " " + token.AccessTokenJson.IdToken); client.KeepAlive = false; try { //Holy shit this is so much shorter than all of the other stuff. I love how POST requests are just that much longer var response = (HttpWebResponse)client.GetResponse(); using (var rdr = new StreamReader(response.GetResponseStream() ?? throw new InvalidOperationException())) { return(JsonConvert.DeserializeObject <StoreInfo>(rdr.ReadToEnd())); } } catch { return(new StoreInfo { ip = 0, rp = 0 }); } }
public static UserData GetUserData(RiotAuthToken token) { var tokenString = token.AccessTokenJson.AccessToken.Split('.')[1]; int mod4 = tokenString.Length % 4; if (mod4 > 0) { tokenString += new string('=', 4 - mod4); } return(JsonConvert.DeserializeObject <UserData>(Encoding.UTF8.GetString(Convert.FromBase64String(tokenString)))); }
public static SpellBook GetUserSpellBook(RiotAuthToken token, UserData userData, RegionData regionData) { //Create the Webrequest and make it look like it is coming from the RiotClient var client = (HttpWebRequest)WebRequest.Create($"https://{regionData.PlatformId}.cap.riotgames.com/lolinventoryservice/v2/inventories?puuid={userData.Sub}&location={regionData.Servers.DiscoverousServiceLocation}&accountId={userData.Dat.U}&inventoryTypes=SPELL_BOOK_PAGE"); client.Method = WebRequestMethods.Http.Get; if (token.Proxy != null) { client.Proxy = token.Proxy; } client.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; client.UserAgent = "RiotClient/18.0.0 (lol-inventory)"; client.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache); client.ProtocolVersion = HttpVersion.Version11; client.ContentType = "application/json"; client.Accept = "application/json"; client.Headers.Set(HttpRequestHeader.Authorization, token.AccessTokenJson.TokenType + " " + token.AccessTokenJson.IdToken); client.KeepAlive = false; try { //Holy shit this is so much shorter than all of the other stuff. I love how POST requests are just that much longer var response = (HttpWebResponse)client.GetResponse(); using (var rdr = new StreamReader(response.GetResponseStream() ?? throw new InvalidOperationException())) { return(JsonConvert.DeserializeObject <SpellBook>(rdr.ReadToEnd())); } } catch { return(new SpellBook { Data = new Data { Items = new Items { SpellBookPage = new[] { new SpellBookPage { Quantity = 0 } } } } }); } }
public static ChampionJwt GetChampionJwt(RiotAuthToken token, UserData userData, RegionData regionData) { //Create the Webrequest and make it look like it is coming from the RiotClient var client = (HttpWebRequest)WebRequest.Create($"https://{regionData.PlatformId}.cap.riotgames.com/lolinventoryservice/v2/inventories?puuid={userData.Sub}&location={regionData.Servers.DiscoverousServiceLocation}&accountId={userData.Dat.U}&inventoryTypes=CHAMPION&signed=true"); client.Method = WebRequestMethods.Http.Get; if (token.Proxy != null) { client.Proxy = token.Proxy; } client.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; client.UserAgent = "RiotClient/18.0.0 (lol-inventory)"; client.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache); client.ProtocolVersion = HttpVersion.Version11; client.ContentType = "application/json"; client.Accept = "application/json"; client.Headers.Set(HttpRequestHeader.Authorization, token.AccessTokenJson.TokenType + " " + token.AccessTokenJson.IdToken); client.KeepAlive = false; try { //Holy shit this is so much shorter than all of the other stuff. I love how POST requests are just that much longer var response = (HttpWebResponse)client.GetResponse(); using (var rdr = new StreamReader(response.GetResponseStream() ?? throw new InvalidOperationException())) { var rawJson = JsonConvert.DeserializeObject <ChampData>(rdr.ReadToEnd()); //ChampData var tokenString = rawJson.Data.ItemsJwt.Split('.')[1]; var mod4 = tokenString.Length % 4; if (mod4 > 0) { tokenString += new string('=', 4 - mod4); } return(JsonConvert.DeserializeObject <ChampionJwt>(Encoding.UTF8.GetString(Convert.FromBase64String(tokenString)))); } } catch { return(null); } }
public static bool Deauth(RiotAuthToken token, RiotAuthOpenIdConfiguration config, RegionData regionData) { //Create the Webrequest and make it look like it is coming from the RiotClient var client = (HttpWebRequest)WebRequest.Create(config.RevocationEndpoint); client.Method = WebRequestMethods.Http.Post; if (token.Proxy != null) { client.Proxy = token.Proxy; } //Lazy Hack client.Host = config.RevocationEndpoint.Replace("//", "/").Split('/')[1]; client.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; client.UserAgent = "RiotClient/18.0.0 (rso-auth)"; client.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache); client.ProtocolVersion = HttpVersion.Version11; client.ContentType = "application/x-www-form-urlencoded"; //Use the DSID from RiotAuthToekn client.Headers.Set("X-Riot-DSID", token.Dsid); client.Accept = "application/json"; //The information to Post in the webrequest var postString = "client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&" + $"client_assertion={regionData.Rso.Token}&" + "grant_type=password&" + $"token={token.AccessTokenJson.RefreshToken}&" + "token_type_hint=refresh_token"; //Convert to bytes var postBytes = Encoding.UTF8.GetBytes(postString); client.ContentLength = postBytes.Length; //More things to try to make it look like it is coming from the riot client client.ServicePoint.Expect100Continue = false; client.Headers.Remove(HttpRequestHeader.Pragma); //Send the POST request var requestStream = client.GetRequestStream(); requestStream.Write(postBytes, 0, postBytes.Length); requestStream.Close(); //Retrieve the response try { var response = (HttpWebResponse)client.GetResponse(); using (var rdr = new StreamReader(response.GetResponseStream() ?? throw new InvalidOperationException())) { //Success return(true); } } catch { //Something happened return(false); } }