/** * Create an authorisation object and persist to the current session. * * @param string $guid * * @return Authorisation */ public function createAuthorisation($guid) { if ($this->accessTokens === null) { throw new \RuntimeException(sprintf('Tokens not added to session for member GUID of %s', $guid)); } if ($this->isTransitional()) { throw new \RuntimeException(sprintf('Transition still in progress for member GUID of %s', $guid)); } $accountEntity = $this->records->getAccountByGuid($guid); $authorisation = new Authorisation(); $authorisation->setGuid($guid)->setCookie(Uuid::uuid4()->toString())->setAccount($accountEntity); foreach ($this->accessTokens as $provider => $accessToken) { $accessToken = $this->setAccessTokenExpires($accessToken); $authorisation->addAccessToken($provider, $accessToken)->setExpiry($accessToken->getExpires()); } $this->setAuthorisation($authorisation); return $authorisation; }