当前位置: 首页>>代码示例>>PHP>>正文


PHP UserResponseInterface::getRefreshToken方法代码示例

本文整理汇总了PHP中HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface::getRefreshToken方法的典型用法代码示例。如果您正苦于以下问题:PHP UserResponseInterface::getRefreshToken方法的具体用法?PHP UserResponseInterface::getRefreshToken怎么用?PHP UserResponseInterface::getRefreshToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface的用法示例。


在下文中一共展示了UserResponseInterface::getRefreshToken方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadUserByOAuthUserResponse

 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());
 }
开发者ID:palmfjord,项目名称:sr-playlist,代码行数:16,代码来源:SpotifyOAuthUserProvider.php

示例2: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     //data from facebook response
     //		dump($response->getAccessToken(), $response->getRefreshToken());
     //		die();
     $id = $response->getUsername();
     $nickname = $response->getNickname();
     $email = $response->getEmail();
     //set data in session
     $this->session->set('id', $id);
     $this->session->set('email', $email);
     $this->session->set('access_token', $response->getAccessToken());
     $this->session->set('refresh_token', $response->getRefreshToken());
     /*
     //get user by fid
     $qb = $this->doctrine->getManager()->createQueryBuilder();
     $qb ->select('u.id')
     	->from('AcmeDemoBundle:User', 'u')
     	->where('u.fid = :fid')
     	->setParameter('fid', $facebook_id)
     	->setMaxResults(1);
     $result = $qb->getQuery()->getResult();
     
     //add to database if doesn't exists
     if ( !count($result) ) {
     	$User = new User();
     	$User->setCreatedAt(new \DateTime());
     	$User->setNickname($nickname);
     	$User->setRealname($realname);
     	$User->setEmail($email);
     	$User->setAvatar($avatar);
     	$User->setFID($facebook_id);
     
     	$em = $this->doctrine->getManager();
     	$em->persist($User);
     	$id = $em->flush();
     } else {
     	$id = $result[0]['id'];
     }
     */
     //@TODO: hmm : is admin
     if ($this->isUserAdmin($nickname)) {
         $this->session->set('is_admin', true);
     }
     //parent:: returned value
     return $this->loadUserByUsername($response->getNickname());
 }
开发者ID:Avazanga1,项目名称:OAuth-Client-Demo,代码行数:47,代码来源:Provider.php

示例3: updateUserByOAuthUserResponse

 /**
  * Attach OAuth sign-in provider account to existing user.
  *
  * @param UserInterface         $user
  * @param UserResponseInterface $response
  *
  * @return UserInterface
  */
 protected function updateUserByOAuthUserResponse(UserInterface $user, UserResponseInterface $response)
 {
     $oauth = $this->oauthFactory->createNew();
     $oauth->setIdentifier($response->getUsername());
     $oauth->setProvider($response->getResourceOwner()->getName());
     $oauth->setAccessToken($response->getAccessToken());
     $oauth->setRefreshToken($response->getRefreshToken());
     /* @var $user SyliusUserInterface */
     $user->addOAuthAccount($oauth);
     $this->userManager->persist($user);
     $this->userManager->flush();
     return $user;
 }
开发者ID:ReissClothing,项目名称:Sylius,代码行数:21,代码来源:UserProvider.php

示例4: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     // First, check if it's an Azure User
     if (get_class($response->getResourceOwner()) != "HWI\\Bundle\\OAuthBundle\\OAuth\\ResourceOwner\\AzureResourceOwner") {
         throw new UnsupportedUserException("Can not load a user by " . get_class($response->getResourceOwner()) . ".");
     }
     // Check if this user exists
     $user = $this->userManager->findUserByEmail($response->getEmail());
     // Load groups ids
     $groups = $this->entityManager->createQueryBuilder()->select("azureRole.azureGid")->from("BdEMainBundle:AzureRole", 'azureRole')->getQuery()->getArrayResult();
     $request = ['groupIds' => []];
     foreach ($groups as $group) {
         $request['groupIds'][] = $group['azureGid'];
     }
     // Load groups for this user
     $client = new Curl();
     $client->setTimeout(20000);
     $client = new Browser($client);
     $uid = $response->getResponse()['oid'];
     $uri = "https://graph.windows.net" . "/" . $this->tenant . "/me/checkMemberGroups?api-version=1.6";
     $r = $client->post($uri, array("Authorization: Bearer " . $response->getAccessToken() . "", "Content-Type: application/json", "Accept: application/json"), json_encode($request));
     $r = json_decode($r->getContent());
     $groups = $r->value;
     $roleRepo = $this->entityManager->getRepository("BdEMainBundle:AzureRole");
     /** @var AzureRole[] $azureRoles */
     $azureRoles = $roleRepo->createQueryBuilder('azureRole')->where('azureRole.azureGid IN (?1)')->setParameter(1, $groups)->getQuery()->getResult();
     /** @var Role[] $roles */
     $roles = array();
     foreach ($azureRoles as $azureRole) {
         $roles = array_merge($roles, $azureRole->getRoles());
     }
     $roles = array_unique($roles);
     if (sizeof($roles) == 0) {
         // Try to get if it's a SuperAdmin
         $uri = "https://graph.windows.net" . "/" . $this->tenant . "/me/memberOf?api-version=1.6";
         $r = $client->get($uri, array("authorization: Bearer " . $response->getAccessToken()));
         $userRoles = json_decode($r->getContent());
         if (!property_exists($userRoles, 'value')) {
             throw new UsernameNotFoundException(sprintf("Impossible to log you !", $response->getRealName()));
         }
         $userRoles = $userRoles->value;
         foreach ($userRoles as $userRole) {
             if ($userRole->objectType == 'Role') {
                 if ($userRole->displayName == "Company Administrator" && strpos($response->getEmail(), $this->tenant) !== false) {
                     // We found an Admin !
                     $roles[] = new Role("ROLE_SUPER_ADMIN");
                     break;
                 }
             }
         }
         if (count($roles) == 0) {
             $this->flashBag->add("error", $response->getEmail() . " ne peut pas se connecter à cette application");
             throw new UsernameNotFoundException(sprintf("User '%s' has no power here!", $response->getRealName()));
         }
     }
     /** @var User $user */
     if ($user == null) {
         $user = $this->userManager->createUser();
     }
     $user->setRoles($roles);
     $user->setEmail($response->getEmail());
     $user->setEmailCanonical($response->getEmail());
     $user->setEnabled(true);
     $user->setUsername($response->getEmail());
     $user->setPlainPassword($response->getAccessToken());
     $user->setAzureAccessToken($response->getAccessToken());
     $user->setAzureRenewAccessToken($response->getRefreshToken());
     $this->userManager->updateUser($user);
     return $user;
 }
开发者ID:PhilippeGeek,项目名称:adhesion,代码行数:73,代码来源:UserProvider.php

示例5: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $user = new WebHomeUser($response->getNickname(), null, $response->getFirstName(), $response->getLastName(), $response->getLocale(), $response->getAccessToken(), $response->getRefreshToken());
     $user->initRolesAndApplications($response->getRoles());
     return $user;
 }
开发者ID:nicolasdewez,项目名称:webhome-common,代码行数:9,代码来源:WebHomeUserProvider.php

示例6:

 function it_should_create_new_user_when_none_was_found($userManager, FactoryInterface $customerFactory, FactoryInterface $userFactory, FactoryInterface $oauthFactory, RepositoryInterface $oauthRepository, CustomerInterface $customer, ShopUserInterface $user, UserResponseInterface $response, ResourceOwnerInterface $resourceOwner, UserOAuthInterface $oauth)
 {
     $resourceOwner->getName()->willReturn('google');
     $response->getEmail()->willReturn(null);
     $response->getUsername()->willReturn('username');
     $response->getNickname()->willReturn('user');
     $response->getRealName()->willReturn('Name');
     $response->getResourceOwner()->willReturn($resourceOwner);
     $response->getAccessToken()->willReturn('access_token');
     $response->getRefreshToken()->willReturn('refresh_token');
     $oauthRepository->findOneBy(['provider' => 'google', 'identifier' => 'username'])->willReturn(null);
     $oauthFactory->createNew()->willReturn($oauth);
     $userFactory->createNew()->willReturn($user);
     $customerFactory->createNew()->willReturn($customer);
     $customer->setFirstName('Name')->shouldBeCalled();
     $oauth->setIdentifier('username');
     $oauth->setProvider('google');
     $oauth->setAccessToken('access_token');
     $oauth->setRefreshToken('refresh_token');
     $user->setCustomer($customer)->shouldBeCalled();
     $user->getUsername()->willReturn(null);
     $user->setUsername('user')->shouldBeCalled();
     $user->setPlainPassword('2ff2dfe363')->shouldBeCalled();
     $user->setEnabled(true)->shouldBeCalled();
     $user->addOAuthAccount($oauth)->shouldBeCalled();
     $userManager->persist($user)->shouldBeCalled();
     $userManager->flush()->shouldBeCalled();
     $this->loadUserByOAuthUserResponse($response)->shouldReturn($user);
 }
开发者ID:TheMadeleine,项目名称:Sylius,代码行数:29,代码来源:UserProviderSpec.php


注:本文中的HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface::getRefreshToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。