Last active
February 25, 2020 19:29
-
-
Save moorer2k/562199c183222b201f09ffb402ca6b65 to your computer and use it in GitHub Desktop.
A quick php class I put together to interface with the new mobile LoL chat (data captured from my iPad). Allows you to login to your LoL account and pull the basic info on a summoner ID. It's super fast and supports multiple ID queries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class leagueChat | |
*/ | |
class leagueChat { | |
protected $username; | |
protected $password; | |
protected $region; | |
protected $lang; | |
protected $authKey; | |
/** | |
* leagueChat constructor. | |
* @param $username | |
* @param $password | |
* @param string $region | |
* @param string $lang | |
*/ | |
public function __construct($username, $password, $region = 'NA1', $lang = 'en_US') | |
{ | |
$this->username = $username; | |
$this->password = $password; | |
$this->region = $region; | |
$this->lang = $lang; | |
$this->Login($username, $password, $region, $lang); | |
} | |
/** | |
* Get summoner by ID. | |
* | |
* @param integer $id | |
* @return string | |
*/ | |
public function getSummonerById($id){ | |
return $this->getData('https://na.api.pvp.net/api/lol/na/v1.4/summoner/' . $id); | |
} | |
/** | |
* Login procedure used in the mobile LoLChat client. | |
* | |
* @param $username | |
* @param $password | |
* @param $region | |
* @param $lang | |
* | |
* @return bool | |
*/ | |
protected function Login($username, $password, $region, $lang) { | |
$url = 'https://auth.riotgames.com/authz/status'; | |
$jsonRequest = json_encode(['query' => 'redirect_uri=http://localhost/oauth2-callback&client_id=leagueconnect&response_type=code&scope=openid&ui_locales=en-US']); | |
// First we get the initial session data to store for our next request. | |
$session1 = $this->postData($url, $jsonRequest, true); | |
$uri = 'https://auth.riotgames.com/authz/auth'; | |
$login = json_encode(['username' => $username, 'password' => $password, 'region' => $region, 'remember' => 'true', 'lang' => $lang]); | |
// Now we can send our credentials to login with. | |
$session2 = $this->postData($uri, $login, false, $session1); | |
// The auth token is required as part of the next post data, so we must parse and store it for our final request. | |
$authToken = explode('"', explode('code=', $session2)[1])[0]; | |
$uri2 = 'https://auth.riotgames.com/token'; | |
// The post paramter (at the end of $pData) client_secret is generated for each users device when installed on the mobile device. So far this has always worked for any user/pass! | |
$pData = 'grant_type=authorization_code&code=' . trim($authToken) . '&redirect_uri=http%3A%2F%2Flocalhost%2Foauth2-callback&client_id=leagueconnect&client_secret=amVYw7iK_qSaGUNqxRvzgs16EMgdEUdu1mDVdMNJDC4'; | |
// Fire off the final request and check if access_token has been set! | |
$jRequest = $this->postData($uri2, $pData, false, '', true); | |
$this->authKey = trim(json_decode($jRequest)->access_token); | |
if(!empty($this->authKey)){ | |
return true; | |
} | |
return false; | |
} | |
/** | |
* Send a GET request with the AuthKey provided from successfully authenticating. | |
* | |
* @param $url | |
* @return string | |
*/ | |
protected function getData($uri){ | |
$response = \Httpful\Request::get($uri) | |
->addHeader('Authorization', 'Bearer ' . $this->authKey) | |
->send(); | |
return $response->body; | |
} | |
/** | |
* Send specific POST requests as per required. | |
* | |
* @param $uri | |
* @param $postData | |
* @param bool $returnCookie | |
* @param string $cookieSession | |
* @param bool $lastRequest | |
* @return \Httpful\Response | |
*/ | |
protected function postData($uri, $postData, $returnCookie = false, $cookieSession = '', $lastRequest = false) { | |
if(!empty($cookieSession)){ | |
$response = \Httpful\Request::post($uri) | |
->body($postData) | |
->addHeader('Referer', 'https://auth.riotgames.com/authorize?redirect_uri=http://localhost/oauth2-callback&client_id=leagueconnect&response_type=code&scope=openid&ui_locales=en-US') | |
->addHeader('Cookie', $cookieSession) | |
->addHeader('Content-Type', 'application/json') | |
->send(); | |
} elseif($lastRequest) { | |
$response = \Httpful\Request::post($uri) | |
->body($postData) | |
->addHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8') | |
->addHeader('Accept', '*') | |
->addHeader('User-Agent', 'LoL%20Friends/490 CFNetwork/758.0.2 Darwin/15.0.0') | |
->send(); | |
} else { | |
$response = \Httpful\Request::post($uri) | |
->body($postData) | |
->addHeader('Referer', 'https://auth.riotgames.com/authorize?redirect_uri=http://localhost/oauth2-callback&client_id=leagueconnect&response_type=code&scope=openid&ui_locales=en-US') | |
->sendsJson() | |
->send(); | |
} | |
if($returnCookie){ | |
$respHeaders = $response->headers->toArray() ; | |
return explode(';', $respHeaders['set-cookie'])[0]; | |
} | |
return $response; | |
} | |
} |
Is this still working?
I'm porting it to Node and I'm receiving mostly Unauthorized
or Invalid Request
(recaptcha).
Hey sorry for the late response, need to setup some notifications on such things!
I will check it out.
UPDATE: I re-installed the league chat on my iPad and it is not logging in at all for me anymore. Do you have success with this?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage:
Response looks like: