/** * {@inheritDoc} */ public function authenticate(TokenInterface $token) { $psr7Factory = new DiactorosFactory(); $psr7Request = $psr7Factory->createRequest($token->getRequest()); try { $key = $this->authenticator->authenticate($psr7Request); return new HmacToken($token->getRequest(), $key); } catch (\Exception $e) { throw new AuthenticationException($e->getMessage()); } }
/** * {@inheritdoc} */ public function authenticate(TokenInterface $token) { /** @var HmacUserToken $token */ if ($this->validateServiceLabel($token->getServiceLabel())) { $user = $this->userProvider->loadUserByUsername($token->getUsername()); if ($this->validateSignature($token->getRequest(), $token->getSignature(), $user->getPassword())) { $authenticatedToken = new HmacUserToken(); $authenticatedToken->setUser($user); $authenticatedToken->setServiceLabel($token->getServiceLabel()); $authenticatedToken->setRequest($token->getRequest()); return $authenticatedToken; } } throw new AuthenticationException('The HMAC authentication failed.'); }
/** * Attempts to authenticate a TokenInterface object. * * @param TokenInterface $token The TokenInterface instance to authenticate * * @return TokenInterface An authenticated TokenInterface instance, never null * * @throws AuthenticationException if the authentication fails */ public function authenticate(TokenInterface $token) { /** @var SignedTokenInterface $token */ $user = $this->userProvider->loadUserByUsername($token->getUsername()); $signData = $this->getAuthSignData($token->getRequest()); $signData[] = $user->{$this->config['secret_getter']}(); $expectedSignature = hash($this->config['hash_alg'], implode($this->config['data_delimiter'], $signData)); if ($token->getSignature() == $expectedSignature) { $token->setUser($user); return $token; } $this->logger->critical(sprintf('Invalid auth signature. Expect "%s", got "%s"', $expectedSignature, $token->getSignature()), ['signData' => $signData]); throw new AuthenticationException("Invalid auth signature " . $token->getSignature()); }