Skip to content

Commit

Permalink
Merge pull request #164 from bytehead/feature/configurabe-delay
Browse files Browse the repository at this point in the history
Make the challenge delay configurable
  • Loading branch information
pgrimaud authored Nov 15, 2020
2 parents ffbece3 + 8a35f10 commit d008401
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
15 changes: 11 additions & 4 deletions src/Instagram/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,21 @@ class Api
*/
protected $session = null;

/**
* @var int|null
*/
protected $challengeDelay;

/**
* @param CacheItemPoolInterface $cachePool
* @param ClientInterface|null $client
* @param int|null $challengeDelay
*/
public function __construct(CacheItemPoolInterface $cachePool, ClientInterface $client = null)
public function __construct(CacheItemPoolInterface $cachePool, ClientInterface $client = null, ?int $challengeDelay = null)
{
$this->cachePool = $cachePool;
$this->client = $client ?: new Client();
$this->cachePool = $cachePool;
$this->client = $client ?: new Client();
$this->challengeDelay = $challengeDelay;
}

/**
Expand All @@ -81,7 +88,7 @@ public function __construct(CacheItemPoolInterface $cachePool, ClientInterface $
*/
public function login(string $username, string $password, ?ImapClient $imapClient = null): void
{
$login = new Login($this->client, $username, $password, $imapClient);
$login = new Login($this->client, $username, $password, $imapClient, $this->challengeDelay);

// fetch previous session an re-use it
$sessionData = $this->cachePool->getItem(Session::SESSION_KEY . '.' . CacheHelper::sanitizeUsername($username));
Expand Down
19 changes: 13 additions & 6 deletions src/Instagram/Auth/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,25 @@ class Login
*/
private $imapClient;

/**
* @var int|null
*/
private $challengeDelay;

/**
* @param ClientInterface $client
* @param string $login
* @param string $password
* @param ImapClient|null $imapClient
* @param int|null $challengeDelay
*/
public function __construct(ClientInterface $client, string $login, string $password, ?ImapClient $imapClient = null)
public function __construct(ClientInterface $client, string $login, string $password, ?ImapClient $imapClient = null, ?int $challengeDelay = null)
{
$this->client = $client;
$this->login = $login;
$this->password = $password;
$this->imapClient = $imapClient;
$this->client = $client;
$this->login = $login;
$this->password = $password;
$this->imapClient = $imapClient;
$this->challengeDelay = $challengeDelay;
}

/**
Expand Down Expand Up @@ -124,7 +131,7 @@ private function checkpointChallenge(CookieJar $cookieJar, \StdClass $data): Coo
throw new InstagramAuthException('Checkpoint required, please provide IMAP credentials to process authentication.');
}

$challenge = new Challenge($this->client, $cookieJar, $data->checkpoint_url);
$challenge = new Challenge($this->client, $cookieJar, $data->checkpoint_url, $this->challengeDelay);

$challengeContent = $challenge->fetchChallengeContent();

Expand Down

0 comments on commit d008401

Please sign in to comment.