private function handle2fa(Client $client, TwoFactorAuthenticationRequiredException $e) { $authenticationAttempts = 0; $authorization = []; $type = trim($e->getType()); // Stupid API gives text with spaces $message = ['Username and password were correct.', 'Two factor authentication is required to continue authentication.']; if ('app' === $type) { $message[] = 'Open the two-factor authentication app on your device to view your authentication code and verify your identity.'; } elseif ('sms' === $type) { $message[] = 'You have been sent an SMS message with an authentication code to verify your identity.'; } $this->styleHelper->note($message); // We already know the password is valid, we just need a valid code // Don't want to fill in everything again when you know it's valid ;) while (!isset($authorization['token'])) { if ($authenticationAttempts > 0) { $this->styleHelper->error('Two factor authentication code was invalid, please try again.'); } try { $code = $this->styleHelper->ask('Two factor authentication code', null, [$this, 'validateNoneEmpty']); $authorization = $this->createAuthorization($client, $code); } catch (TwoFactorAuthenticationRequiredException $e) { // No-op, continue the loop, try again } catch (\Exception $e) { $this->styleHelper->error($e->getMessage()); $this->styleHelper->newLine(); } ++$authenticationAttempts; } return $authorization; }
/** * Retrieves the requirements of the given template and asks the * user for any parameters that are not available from the * input, then binds the parameters to the template. * * @param TemplateInterface $template Template to render */ public function parameterize(TemplateInterface $template) { $params = []; foreach ($template->getRequirements() as $key => $requirement) { if (!$this->input->hasOption($key) || !$this->input->getOption($key)) { list($prompt, $default) = $requirement; if ('description' === $key) { $v = $this->style->ask($prompt . ' (enter "e" to open editor)', $default); if ('e' === $v) { $editor = $this->getHelperSet()->get('editor'); $v = $editor->fromString(''); } } else { if ('branch' === $key && $this->input->hasOption('base') && $this->input->getOption('base')) { $default = $this->input->getOption('base'); } if (1 < count($choices = explode('|', $default))) { $v = $this->style->choice($prompt . ' ', $choices, $choices[0]); } else { $v = $this->style->ask($prompt . ' ', $default); } } } else { $v = $this->input->getOption($key); } $params[$key] = $v; } $template->bind($params); }