public function testValidPasswordGetsToken()
 {
     $grantType = new PasswordCredentials($this->createClient(), ['client_id' => 'testClient', 'client_secret' => 'clientSecret', 'username' => 'validUsername', 'password' => 'validPassword']);
     $token = $grantType->getToken();
     $this->assertNotEmpty($token->getToken());
     $this->assertTrue($token->getExpires()->getTimestamp() > time());
 }
Exemplo n.º 2
0
 /**
  * @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();
 }