Skip to content

Commit

Permalink
Merge pull request #3 from Tankonyako/master
Browse files Browse the repository at this point in the history
added code argument to login method
  • Loading branch information
Allyans3 authored Jun 21, 2023
2 parents 10033a9 + e7813a7 commit 9c7c9a6
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions src/SteamAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class SteamAuth
private $cookieStorage = [];
private $cookieFile = '';

private $steamID = -1;
private $accessToken = null;
private $refreshToken = null;
private $clientId = -1;

const HEADERS = [
'Origin' => "https://steamcommunity.com",
'Referer' => "https://steamcommunity.com/"
Expand Down Expand Up @@ -71,7 +76,7 @@ private function setCookieOptions(array $options)
* @throws SteamResponseException
* @throws SteamErrorException
*/
public function login(): bool
public function login(string $code = null): bool
{
if (self::isAuthorized())
return true;
Expand All @@ -85,7 +90,7 @@ public function login(): bool

if ($authSession->getAllowedConfirmations()) {
if (self::isTwoFactorRequired($authSession->getAllowedConfirmations()[0])) {
$twoFactorCode = SteamTotp::getAuthCode($this->sharedSecret);
$twoFactorCode = $code ?? SteamTotp::getAuthCode($this->sharedSecret);

self::updateAuthSession($authSession->getClientId(), $authSession->getSteamid(), $twoFactorCode,
EAuthSessionGuardType::k_EAuthSessionGuardType_DeviceCode);
Expand All @@ -104,6 +109,12 @@ public function login(): bool
self::getAdditionalCookies($domain);
}

$this->steamID = $authSession->getSteamid();
$this->login = $session->getAccountName();
$this->accessToken = $session->getAccessToken();
$this->refreshToken = $session->getRefreshToken();
$this->clientId = $session->getNewClientId();

return true;
}

Expand Down Expand Up @@ -402,6 +413,47 @@ private function getAdditionalCookies($url)
self::updateCookieStorage($curl->responseCookies, self::getHostFromUrl($url));
}

public function getSteamID()
{
return $this->steamID;
}

public function getAccountName()
{
return $this->login;
}

/**
* @return mixed|null
*/
public function getSharedSecret(): mixed
{
return $this->sharedSecret;
}

/**
* @return null
*/
public function getAccessToken()
{
return $this->accessToken;
}

/**
* @return null
*/
public function getRefreshToken()
{
return $this->refreshToken;
}

/**
* @return int
*/
public function getClientId(): int
{
return $this->clientId;
}

/**
* @param string $url
Expand Down Expand Up @@ -441,4 +493,4 @@ private function checkSteamError($errorCode)
throw new SteamErrorException(SteamConfig::CODES[$errorCode]);
}
}
}
}

0 comments on commit 9c7c9a6

Please sign in to comment.