public function __construct(GrantDecision $grantDecision, AccessToken $accessToken, RefreshToken $refreshToken = null) { if ($grantDecision->isDenied()) { throw new \LogicException('Could not construct SuccessfulTokenRequestResult with a denied GrantDecision'); } $this->grantDecision = $grantDecision; $this->accessToken = $accessToken; $this->refreshToken = $refreshToken; }
private function buildAccessToken(TokenRequestAttempt $tokenRequestAttempt, GrantDecision $grantDecision) { if ($grantDecision->isDenied()) { throw new \LogicException('Unable to build an access token with a denied decision'); } $token = $this->configuration->getTokenGenerator()->generate(['length' => $this->configuration->getAccessTokenLength()]); $expiresAt = new \DateTime('now', new \DateTimeZone('UTC')); $expiresAt->add(\DateInterval::createFromDateString(sprintf("%d seconds", $this->configuration->getAccessTokenTTL()))); $accessToken = new AccessToken($token, \DateTimeImmutable::createFromMutable($expiresAt), $tokenRequestAttempt->getInputData()->getClientId(), $grantDecision->getResourceOwner(), []); $this->accessTokenStorage->save($accessToken); return $accessToken; }