/** * {@inheritdoc} */ public function logIn($username, $password, $force = false, $totp = null) { $this->loggedOut = false; if (!$force && $this->isLoggedIn() && $this->session->get('username') === $username) { return; } $client = $this->getGuzzleClient(['base_url' => $this->config['accounts'], 'defaults' => ['debug' => $this->config['debug'], 'verify' => $this->config['verify'], 'proxy' => $this->config['proxy']]]); $grantType = new PasswordCredentialsWithTfa($client, ['client_id' => $this->config['client_id'], 'client_secret' => $this->config['client_secret'], 'username' => $username, 'password' => $password, 'token_url' => $this->config['token_url']]); if (isset($totp)) { $grantType->setTotp($totp); } $token = $grantType->getToken(); $this->session->set('username', $username); $this->addTokenToSession($token); $this->session->save(); }
/** * @inheritdoc */ public function logIn($username, $password, $force = false) { $this->loggedOut = false; if (!$force && $this->isLoggedIn() && $this->session->get('username') === $username) { return; } $client = $this->getGuzzleClient(['base_url' => $this->config['accounts'], 'defaults' => ['debug' => $this->config['debug'], 'verify' => $this->config['verify'], 'proxy' => $this->config['proxy']]]); $grantType = new PasswordCredentials($client, ['client_id' => $this->config['client_id'], 'client_secret' => $this->config['client_secret'], 'username' => $username, 'password' => $password, 'token_url' => $this->config['token_url']]); try { $token = $grantType->getToken(); } catch (BadResponseException $e) { $response = $e->getResponse(); if ($response && $response->getStatusCode() === 401) { throw new \InvalidArgumentException("Invalid credentials. Please check your username/password combination"); } throw $e; } $this->session->set('username', $username); $this->addTokenToSession($token); $this->session->save(); }