Skip to content

Commit

Permalink
Added support for proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Allyans3 committed Nov 12, 2023
1 parent 3439b32 commit 8aa6c5a
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 1 deletion.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down
60 changes: 60 additions & 0 deletions src/SteamAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SteamAuth
private $password;
private $sharedSecret;

private $proxy = [];
private $cookieStorage = [];
private $cookieFile = '';

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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/');
Expand All @@ -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);

Expand All @@ -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);
Expand Down
138 changes: 137 additions & 1 deletion src/Traits/SteamAuthMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'];

Expand Down

0 comments on commit 8aa6c5a

Please sign in to comment.