From 8aa6c5aae4c92487e88e86c5c6f4aa914e95c49b Mon Sep 17 00:00:00 2001 From: allyans3 Date: Sun, 12 Nov 2023 20:41:46 +0100 Subject: [PATCH] Added support for proxy --- README.md | 46 +++++++++++ src/SteamAuth.php | 60 ++++++++++++++ src/Traits/SteamAuthMethods.php | 138 +++++++++++++++++++++++++++++++- 3 files changed, 243 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8680b5d..36cef20 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,9 @@ require "vendor/autoload.php"; $auth = new SteamAuth('login', 'password', 'shared_secret'); +// For proxy +$auth->setProxy($proxy); + // For WebBrowser $auth->login(); // or for MobileApp @@ -142,6 +145,49 @@ try { } ``` +## Proxy +**v1.0.9 or later is required to use proxy.** + +Keys that can be in an array: +* `ip` + `port` or `domain_name` – `domain_name` used for rotating proxy +* `user` + `pass` – if proxy support auth +* `type` – you can pass constant variable or integer as explained in table below +* `timeout` – in seconds, default infinite +* `connect_timeout` – in seconds, default infinite +* `user_agent` – your Useragent + + +| cURL Proxy Type | Integer | +| ------------------------- | :-----: | +| CURLPROXY_HTTP | 0 | +| CURLPROXY_HTTP_1_0 | 1 | +| CURLPROXY_HTTPS | 2 | +| CURLPROXY_SOCKS4 | 4 | +| CURLPROXY_SOCKS4A | 6 | +| CURLPROXY_SOCKS5 | 5 | +| CURLPROXY_SOCKS5_HOSTNAME | 7 | + +Example: +```php +use SteamAuth\SteamAuth; + +require "vendor/autoload.php"; + +$proxy = [ + 'ip' => '49.12.181.264', + 'port' => 8000, + 'user' => 'user', + 'pass' => 'pass' +]; + +$auth = new SteamAuth('login', 'password', 'shared_secret'); + +$auth->setProxy($proxy); + +$auth->login(); + +``` + ## Support Report bugs on the [issue tracker](https://github.com/Allyans3/protobuf-steam-auth/issues). diff --git a/src/SteamAuth.php b/src/SteamAuth.php index e0ccad2..6d1ff23 100644 --- a/src/SteamAuth.php +++ b/src/SteamAuth.php @@ -27,6 +27,7 @@ class SteamAuth private $password; private $sharedSecret; + private $proxy = []; private $cookieStorage = []; private $cookieFile = ''; @@ -109,6 +110,11 @@ private function setCookieOptions(array $options) $this->cookieFile = isset($options['cookie_file']) ? $options['cookie_file'] : $this->cookieFile; } + public function setProxy($proxy) + { + $this->proxy = $proxy; + } + /** * @param string|null $code * @return bool @@ -252,6 +258,24 @@ public function getStartupCookies() $curl->setConnectTimeout(30); $curl->setTimeout(60); + if ($this->proxy) { + if (array_key_exists('domain_name', $this->proxy)) + $curl->setProxy($this->proxy['domain_name']); + else if (array_key_exists('user', $this->proxy) && array_key_exists('pass', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port'], $this->proxy['user'], $this->proxy['pass']); + else if (array_key_exists('ip', $this->proxy) && array_key_exists('port', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port']); + + if (array_key_exists('type', $this->proxy)) + $curl->setProxyType($this->proxy['type']); + if (array_key_exists('timeout', $this->proxy)) + $curl->setTimeout($this->proxy['timeout']); + if (array_key_exists('connect_timeout', $this->proxy)) + $curl->setConnectTimeout($this->proxy['connect_timeout']); + if (array_key_exists('user_agent', $this->proxy)) + $curl->setUserAgent($this->proxy['user_agent']); + } + $curl->setCookieJar($this->cookieFile); $curl->get('https://steamcommunity.com/'); @@ -273,6 +297,24 @@ public function isAuthorized() $curl->setConnectTimeout(30); $curl->setTimeout(60); + if ($this->proxy) { + if (array_key_exists('domain_name', $this->proxy)) + $curl->setProxy($this->proxy['domain_name']); + else if (array_key_exists('user', $this->proxy) && array_key_exists('pass', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port'], $this->proxy['user'], $this->proxy['pass']); + else if (array_key_exists('ip', $this->proxy) && array_key_exists('port', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port']); + + if (array_key_exists('type', $this->proxy)) + $curl->setProxyType($this->proxy['type']); + if (array_key_exists('timeout', $this->proxy)) + $curl->setTimeout($this->proxy['timeout']); + if (array_key_exists('connect_timeout', $this->proxy)) + $curl->setConnectTimeout($this->proxy['connect_timeout']); + if (array_key_exists('user_agent', $this->proxy)) + $curl->setUserAgent($this->proxy['user_agent']); + } + $curl->setCookies(self::getCookiesByHost()); $curl->setCookieFile($this->cookieFile); @@ -295,6 +337,24 @@ private function getAdditionalCookies($url) $curl->setConnectTimeout(30); $curl->setTimeout(60); + if ($this->proxy) { + if (array_key_exists('domain_name', $this->proxy)) + $curl->setProxy($this->proxy['domain_name']); + else if (array_key_exists('user', $this->proxy) && array_key_exists('pass', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port'], $this->proxy['user'], $this->proxy['pass']); + else if (array_key_exists('ip', $this->proxy) && array_key_exists('port', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port']); + + if (array_key_exists('type', $this->proxy)) + $curl->setProxyType($this->proxy['type']); + if (array_key_exists('timeout', $this->proxy)) + $curl->setTimeout($this->proxy['timeout']); + if (array_key_exists('connect_timeout', $this->proxy)) + $curl->setConnectTimeout($this->proxy['connect_timeout']); + if (array_key_exists('user_agent', $this->proxy)) + $curl->setUserAgent($this->proxy['user_agent']); + } + $curl->setCookies(self::getCookiesByHost(self::getHostFromUrl($url))); $curl->setCookieFile($this->cookieFile); $curl->setCookieJar($this->cookieFile); diff --git a/src/Traits/SteamAuthMethods.php b/src/Traits/SteamAuthMethods.php index f594967..ddb7563 100644 --- a/src/Traits/SteamAuthMethods.php +++ b/src/Traits/SteamAuthMethods.php @@ -28,7 +28,27 @@ trait SteamAuthMethods */ public function getRSAKey(): CAuthentication_GetPasswordRSAPublicKey_Response { - $curl = new Curl();; + $curl = new Curl(); + $curl->setConnectTimeout(30); + $curl->setTimeout(60); + + if ($this->proxy) { + if (array_key_exists('domain_name', $this->proxy)) + $curl->setProxy($this->proxy['domain_name']); + else if (array_key_exists('user', $this->proxy) && array_key_exists('pass', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port'], $this->proxy['user'], $this->proxy['pass']); + else if (array_key_exists('ip', $this->proxy) && array_key_exists('port', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port']); + + if (array_key_exists('type', $this->proxy)) + $curl->setProxyType($this->proxy['type']); + if (array_key_exists('timeout', $this->proxy)) + $curl->setTimeout($this->proxy['timeout']); + if (array_key_exists('connect_timeout', $this->proxy)) + $curl->setConnectTimeout($this->proxy['connect_timeout']); + if (array_key_exists('user_agent', $this->proxy)) + $curl->setUserAgent($this->proxy['user_agent']); + } $message = new CAuthentication_GetPasswordRSAPublicKey_Request(); $message->setAccountName($this->login); @@ -63,6 +83,26 @@ public function getRSAKey(): CAuthentication_GetPasswordRSAPublicKey_Response public function beginAuthSession($encryptedPassword, $rsaTimestamp, $platformType): CAuthentication_BeginAuthSessionViaCredentials_Response { $curl = new Curl(); + $curl->setConnectTimeout(30); + $curl->setTimeout(60); + + if ($this->proxy) { + if (array_key_exists('domain_name', $this->proxy)) + $curl->setProxy($this->proxy['domain_name']); + else if (array_key_exists('user', $this->proxy) && array_key_exists('pass', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port'], $this->proxy['user'], $this->proxy['pass']); + else if (array_key_exists('ip', $this->proxy) && array_key_exists('port', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port']); + + if (array_key_exists('type', $this->proxy)) + $curl->setProxyType($this->proxy['type']); + if (array_key_exists('timeout', $this->proxy)) + $curl->setTimeout($this->proxy['timeout']); + if (array_key_exists('connect_timeout', $this->proxy)) + $curl->setConnectTimeout($this->proxy['connect_timeout']); + if (array_key_exists('user_agent', $this->proxy)) + $curl->setUserAgent($this->proxy['user_agent']); + } $message = new CAuthentication_BeginAuthSessionViaCredentials_Request(); @@ -116,6 +156,26 @@ public function beginAuthSession($encryptedPassword, $rsaTimestamp, $platformTyp public function updateAuthSession($clientId, $steamId, $twoFactoryCode, $codeType) { $curl = new Curl(); + $curl->setConnectTimeout(30); + $curl->setTimeout(60); + + if ($this->proxy) { + if (array_key_exists('domain_name', $this->proxy)) + $curl->setProxy($this->proxy['domain_name']); + else if (array_key_exists('user', $this->proxy) && array_key_exists('pass', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port'], $this->proxy['user'], $this->proxy['pass']); + else if (array_key_exists('ip', $this->proxy) && array_key_exists('port', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port']); + + if (array_key_exists('type', $this->proxy)) + $curl->setProxyType($this->proxy['type']); + if (array_key_exists('timeout', $this->proxy)) + $curl->setTimeout($this->proxy['timeout']); + if (array_key_exists('connect_timeout', $this->proxy)) + $curl->setConnectTimeout($this->proxy['connect_timeout']); + if (array_key_exists('user_agent', $this->proxy)) + $curl->setUserAgent($this->proxy['user_agent']); + } $message = new CAuthentication_UpdateAuthSessionWithSteamGuardCode_Request(); @@ -146,6 +206,26 @@ public function updateAuthSession($clientId, $steamId, $twoFactoryCode, $codeTyp public function pollAuthSessionStatus($clientId, $requestId): CAuthentication_PollAuthSessionStatus_Response { $curl = new Curl(); + $curl->setConnectTimeout(30); + $curl->setTimeout(60); + + if ($this->proxy) { + if (array_key_exists('domain_name', $this->proxy)) + $curl->setProxy($this->proxy['domain_name']); + else if (array_key_exists('user', $this->proxy) && array_key_exists('pass', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port'], $this->proxy['user'], $this->proxy['pass']); + else if (array_key_exists('ip', $this->proxy) && array_key_exists('port', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port']); + + if (array_key_exists('type', $this->proxy)) + $curl->setProxyType($this->proxy['type']); + if (array_key_exists('timeout', $this->proxy)) + $curl->setTimeout($this->proxy['timeout']); + if (array_key_exists('connect_timeout', $this->proxy)) + $curl->setConnectTimeout($this->proxy['connect_timeout']); + if (array_key_exists('user_agent', $this->proxy)) + $curl->setUserAgent($this->proxy['user_agent']); + } $message = new CAuthentication_PollAuthSessionStatus_Request(); @@ -184,6 +264,24 @@ public function finalizeLogin($refreshToken, $sessionId): array $curl->setConnectTimeout(30); $curl->setTimeout(60); + if ($this->proxy) { + if (array_key_exists('domain_name', $this->proxy)) + $curl->setProxy($this->proxy['domain_name']); + else if (array_key_exists('user', $this->proxy) && array_key_exists('pass', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port'], $this->proxy['user'], $this->proxy['pass']); + else if (array_key_exists('ip', $this->proxy) && array_key_exists('port', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port']); + + if (array_key_exists('type', $this->proxy)) + $curl->setProxyType($this->proxy['type']); + if (array_key_exists('timeout', $this->proxy)) + $curl->setTimeout($this->proxy['timeout']); + if (array_key_exists('connect_timeout', $this->proxy)) + $curl->setConnectTimeout($this->proxy['connect_timeout']); + if (array_key_exists('user_agent', $this->proxy)) + $curl->setUserAgent($this->proxy['user_agent']); + } + $curl->post('https://login.steampowered.com/jwt/finalizelogin', [ 'nonce' => $refreshToken, @@ -214,6 +312,24 @@ public function setToken($url, $nonce, $auth, $steamId) $curl->setConnectTimeout(30); $curl->setTimeout(60); + if ($this->proxy) { + if (array_key_exists('domain_name', $this->proxy)) + $curl->setProxy($this->proxy['domain_name']); + else if (array_key_exists('user', $this->proxy) && array_key_exists('pass', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port'], $this->proxy['user'], $this->proxy['pass']); + else if (array_key_exists('ip', $this->proxy) && array_key_exists('port', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port']); + + if (array_key_exists('type', $this->proxy)) + $curl->setProxyType($this->proxy['type']); + if (array_key_exists('timeout', $this->proxy)) + $curl->setTimeout($this->proxy['timeout']); + if (array_key_exists('connect_timeout', $this->proxy)) + $curl->setConnectTimeout($this->proxy['connect_timeout']); + if (array_key_exists('user_agent', $this->proxy)) + $curl->setUserAgent($this->proxy['user_agent']); + } + $curl->setCookies(self::getCookiesByHost(self::getHostFromUrl($url))); $curl->setCookieFile($this->cookieFile); $curl->setCookieJar($this->cookieFile); @@ -241,6 +357,26 @@ public function setToken($url, $nonce, $auth, $steamId) public function updateAccessToken($refreshToken): CAuthentication_AccessToken_GenerateForApp_Response { $curl = new Curl(); + $curl->setConnectTimeout(30); + $curl->setTimeout(60); + + if ($this->proxy) { + if (array_key_exists('domain_name', $this->proxy)) + $curl->setProxy($this->proxy['domain_name']); + else if (array_key_exists('user', $this->proxy) && array_key_exists('pass', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port'], $this->proxy['user'], $this->proxy['pass']); + else if (array_key_exists('ip', $this->proxy) && array_key_exists('port', $this->proxy)) + $curl->setProxy($this->proxy['ip'], $this->proxy['port']); + + if (array_key_exists('type', $this->proxy)) + $curl->setProxyType($this->proxy['type']); + if (array_key_exists('timeout', $this->proxy)) + $curl->setTimeout($this->proxy['timeout']); + if (array_key_exists('connect_timeout', $this->proxy)) + $curl->setConnectTimeout($this->proxy['connect_timeout']); + if (array_key_exists('user_agent', $this->proxy)) + $curl->setUserAgent($this->proxy['user_agent']); + } $steamId = self::decodeJWT($refreshToken)['sub'];