public function testInstance() { $uid = uniqid(); $tokenString = uniqid(); $token = new Token(); $token->setUid($uid); $token->setToken($tokenString); $this->assertSame($uid, $token->getUid()); $this->assertSame($tokenString, $token->getToken()); }
/** * Authenticates a user and returns an authentication token. * * @param string $username * @param string $password * @return TokenInterface * @throws AccountDisabledException * @throws AccountNotConfirmedException * @throws AuthenticationException * @throws AuthorizationLimitReachedException * @throws UserNotFoundException * @throws WrongPasswordException */ public function authenticate($username, $password) { $response = $this->httpClient->post('/auth', ['body' => ['username' => $username, 'password' => $password]])->json(); if (isset($response['error'])) { switch ($response['code']) { case 101: throw new UserNotFoundException(); case 102: throw new AccountNotConfirmedException(); case 103: case 104: case 105: throw new AccountDisabledException(); case 106: throw new AuthorizationLimitReachedException(); case 107: throw new WrongPasswordException(); default: throw new AuthenticationException('An error occurred during the authentication'); } } $token = new Token(); $token->setUid($response['uid']); $token->setToken($response['token']); return $token; }