public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $user = $this->userRepository->findOneBy(['spotifyId' => $response->getUsername()]);
     if (!$user instanceof SpotifyUser) {
         $user = new SpotifyUser($response->getUsername());
     }
     $user->setSpotifyId($response->getUsername())->setDisplayName($response->getRealName())->setAccessToken($response->getAccessToken())->setAccessTokenExpires(time() + $response->getExpiresIn())->setRefreshToken($response->getRefreshToken())->setProfileUrl($response->getResponse()['href']);
     $responseHasImages = isset($response->getResponse()['images']) && is_array($response->getResponse()['images']);
     $responseImageExists = array_key_exists('url', $response->getResponse()['images'][0]);
     if ($responseHasImages && $responseImageExists) {
         $user->setImageUrl($response->getResponse()['images'][0]['url']);
     }
     $this->em->persist($user);
     $this->em->flush();
     return $this->loadUserByUsername($user->getUsername());
 }
예제 #2
0
 /**
  * Updates an existing authorization with data from the resource owner
  *
  * @param Authorization         $authorization Authorization
  * @param UserResponseInterface $response      Response of the resource owner
  *
  * @return Authorization
  */
 protected function updateAuthorization(Authorization $authorization, UserResponseInterface $response)
 {
     $expirationDate = $this->getExpirationDate($response->getExpiresIn());
     $authorization->setAuthorizationToken($response->getAccessToken())->setExpirationDate($expirationDate);
     return $authorization;
 }