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


PHP UserResponseInterface::getAccessToken方法代码示例

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


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

示例1: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     #        $username = $response->getUsername();
     #        var_dump($username);exit;
     $username = $response->getResponse()["username"];
     var_dump($username);
     $user = $this->userManager->findUserBy(array('username' => $username));
     //when the user is registrating
     if (null === $user) {
         $service = $response->getResourceOwner()->getName();
         $setter = 'set' . ucfirst($service);
         $setter_id = $setter . 'Id';
         $setter_token = $setter . 'AccessToken';
         // create new user here
         $user = $this->userManager->createUser();
         $user->{$setter_id}($username);
         $user->{$setter_token}($response->getAccessToken());
         //I have set all requested data with the user's username
         //modify here with relevant data
         $user->setUsername($username);
         #    $user->setNickname($response->getNickName());
         $user->setEmail($username . '@yoursite.com');
         $user->setPassword($username);
         #    $user->setPath($response->getProfilePicture());
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         return $user;
     }
     //if user exists - go with the HWIOAuth way
     $serviceName = $response->getResourceOwner()->getName();
     $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
     //update access token
     $user->{$setter}($response->getAccessToken());
     return $user;
 }
开发者ID:michaelwang,项目名称:openshop,代码行数:35,代码来源:Member.php

示例2: handleResponse

 public function handleResponse(UserResponseInterface $response, UserService $userService)
 {
     $fields = $response->getResponse();
     $gitHubLogin = $fields['login'];
     $accessToken = $response->getAccessToken();
     $user = $userService->findByGitHubLogin($gitHubLogin);
     if (null === $user) {
         throw new UsernameNotFoundException();
     }
     $oAuthUser = new OAuthUser($user);
     $oAuthUser->addRole('ROLE_GITHUB_USER');
     $oAuthUser->setAccessToken($accessToken);
     if (array_key_exists('name', $fields)) {
         $gitHubName = $fields['name'];
         $oAuthUser->setRealName($gitHubName);
     } else {
         $oAuthUser->setRealName($gitHubLogin);
     }
     $client = new Client();
     $client->setOption('api_version', 'v3');
     $client->authenticate($response->getAccessToken(), Client::AUTH_HTTP_TOKEN);
     /* @var \Github\Api\CurrentUser $currentUserApi */
     $currentUserApi = $client->api('current_user');
     $emails = $currentUserApi->emails();
     $allEMails = $emails->all();
     $oAuthUser->setEmail($this->getPrimaryEmailAddress($allEMails));
     return $oAuthUser;
 }
开发者ID:terretta,项目名称:gitki.php,代码行数:28,代码来源:GitHubResponseHandler.php

示例3: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     $useremail = $response->getEmail();
     // get facebook email id
     $user = $this->userManager->findUserByEmail($useremail);
     //$user = $this->userManager->findUserBy(array($this->getProperty($response) => $useremail));
     //when the user is registrating
     if (null === $user) {
         $service = $response->getResourceOwner()->getName();
         $setter = 'set' . ucfirst($service);
         $setter_id = $setter . 'Id';
         $setter_token = $setter . 'AccessToken';
         // create new user here
         $user = $this->userManager->createUser();
         $user->{$setter_id}($username);
         $user->{$setter_token}($response->getAccessToken());
         $user->setUsername($useremail);
         $user->setEmail($useremail);
         $user->setPassword($username);
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         return $user;
     }
     $user = $this->userManager->findUserByEmail($useremail);
     $serviceName = $response->getResourceOwner()->getName();
     $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
     //update access token
     $user->{$setter}($response->getAccessToken());
     return $user;
 }
开发者ID:krombox,项目名称:motion,代码行数:34,代码来源:FOSUBUserProvider.php

示例4: loadUserByOAuthUserResponse

 /**
  * {@inheritDoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     $email = $response->getEmail();
     $nickname = $response->getRealName();
     //var_dump($email); die();
     $user = $this->userManager->findUserByUsernameOrEmail($email);
     //$user = $this->userManager->findUserBy(array($this->getProperty($response) => $username));
     //when the user is registrating
     if (null === $user) {
         $service = $response->getResourceOwner()->getName();
         $setter = 'set' . ucfirst($service);
         $setter_id = $setter . 'Id';
         $setter_token = $setter . 'AccessToken';
         // create new user here
         $user = $this->userManager->createUser();
         $user->{$setter_id}($username);
         $user->{$setter_token}($response->getAccessToken());
         //I have set all requested data with the user's username
         //modify here with relevant data
         $user->setUsername($nickname);
         $user->setEmail($email);
         $user->setPlainPassword($username);
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         return $user;
     }
     //if user exists - go with the HWIOAuth way
     //$user = parent::loadUserByOAuthUserResponse($response);
     $serviceName = $response->getResourceOwner()->getName();
     $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
     //update access token
     $user->{$setter}($response->getAccessToken());
     return $user;
 }
开发者ID:podisto,项目名称:openwecco,代码行数:38,代码来源:FOSUBUserProvider.php

示例5: loadUserByOAuthUserResponse

 /**
  * @param UserResponseInterface $response
  * @return mixed
  * @throws OAuthAwareException
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $tokenLoggedUser = $this->container->get('security.token_storage')->getToken();
     $oauthServiceName = $response->getResourceOwner()->getName();
     $oauthServiceUserId = $response->getUsername();
     $oauthServiceAccessToken = $response->getAccessToken();
     $user = $this->entityManager->getRepository('AppBundle:User')->findOneBy(array($oauthServiceName . '_id' => $oauthServiceUserId));
     $setter = 'set' . ucfirst($oauthServiceName);
     $setter_id = $setter . 'Id';
     $setter_token = $setter . 'AccessToken';
     if (null === $user) {
         if (null === $tokenLoggedUser) {
             throw new AccountNotLinkedException(sprintf('Not linked "%s" account could be found', $oauthServiceName));
         }
         $currentLoggedUser = $tokenLoggedUser->getUser();
         if (in_array('ROLE_ADMIN', $currentLoggedUser->getRoles())) {
             $currentLoggedUser->{$setter_id}($oauthServiceUserId);
             $currentLoggedUser->{$setter_token}($oauthServiceAccessToken);
             $this->entityManager->persist($currentLoggedUser);
             $this->entityManager->flush();
             $user = $this->entityManager->getRepository('AppBundle:User')->find($currentLoggedUser->getId());
             return $user;
         } else {
             throw new OAuthAwareException(sprintf('Only users with role "ROLE_ADMIN" can link OAuth accounts.', $oauthServiceName));
         }
     } else {
         $user->{$setter_token}($response->getAccessToken());
         $this->entityManager->persist($user);
         $this->entityManager->flush();
         return $user;
     }
 }
开发者ID:alfonsomga,项目名称:symfony.demo.on.roids,代码行数:37,代码来源:UserProvider.php

示例6: loadUserByOAuthUserResponse

 /**
  * {@inheritDoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     $user = $this->userManager->findUserBy(array('githubId' => $username));
     if (!$user) {
         throw new AccountNotLinkedException(sprintf('No user with github username "%s" was found.', $username));
     }
     if ($user->getGithubToken() !== $response->getAccessToken()) {
         $user->setGithubToken($response->getAccessToken());
         $this->userManager->updateUser($user);
     }
     return $user;
 }
开发者ID:yjqg6666,项目名称:packagist,代码行数:16,代码来源:UserProvider.php

示例7: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $userEmail = $response->getEmail();
     $user = $this->userManager->findUserByEmail($userEmail);
     // if null just create new user and set it properties
     if (null === $user) {
         $userData = $response->getResponse();
         $user = new User();
         $user->setUsername($userData['formattedName']);
         $user->setPlainPassword(rand(1000000, 10000000));
         //TODO:find a better option
         //TODO: add location, company name, ..
         $user->setEmail($response->getEmail());
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         $this->em->flush();
         return $user;
     }
     // else update access token of existing user
     $serviceName = $response->getResourceOwner()->getName();
     $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
     $user->{$setter}($response->getAccessToken());
     //update access token
     return $user;
 }
开发者ID:OpenSkills,项目名称:skillsprofile,代码行数:28,代码来源:MyFOSUBUserProvider.php

示例8: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $name = $response->getRealName();
     $email = $response->getEmail();
     $clientId = $response->getUsername();
     $token = $response->getAccessToken();
     $user = $this->doctrine->getRepository('UserUserBundle:Users')->findOneByOAuthUser($clientId);
     /** @var Users $user */
     if (!$user) {
         $service = $response->getResourceOwner()->getName();
         $setter = 'set' . ucfirst($service);
         $setterId = $setter . "Id";
         $setterToken = $setter . 'AccessToken';
         $user = new Users();
         $user->setRealname($name);
         $user->setUsername($email);
         $user->{$setterId}($clientId);
         $user->{$setterToken}($token);
         $user->setPassword(sha1($clientId));
         $roles = $this->doctrine->getRepository('UserUserBundle:Roles')->findOneBy(['role' => 'ROLE_USER']);
         $user->addRole($roles);
         $this->doctrine->getManager()->persist($user);
         $this->doctrine->getManager()->flush();
         $userId = $user->getId();
     } else {
         $userId = $user->getId();
     }
     if (!$userId) {
         throw new UsernameNotFoundException('Возникла проблема добавления или определения пользователя');
     }
     return $this->loadUserByUsername($userId);
 }
开发者ID:rdbn,项目名称:shopsnmarkets,代码行数:32,代码来源:OAuthProvider.php

示例9: loadUserByOAuthUserResponse

 /**
  * @param UserResponseInterface $response
  * @return User
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     /** @var User $user */
     $user = $this->userManager->findUserBy(['slackUserName' => $response->getUsername()]);
     if ($user === null) {
         $user = $this->userManager->createUser();
         $user->setSlackUserName($username);
         $user->setSlackAccessToken($response->getAccessToken());
         $user->setUsername($response->getNickname());
         $user->setEmail($response->getEmail());
         $user->setRealName($response->getRealName());
         $user->setPassword($username);
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         $token = new Token($user);
         $this->tokenRepository->persist($token);
         $user->addToken($token);
         $this->userManager->updateUser($user);
         return $user;
     }
     $user = parent::loadUserByOAuthUserResponse($response);
     $user->setSlackAccessToken($response->getAccessToken());
     $user->setRealName($response->getRealName());
     $token = new Token($user);
     $this->tokenRepository->persist($token);
     $user->addToken($token);
     $this->userManager->updateUser($user);
     return $user;
 }
开发者ID:jordi12100,项目名称:ExpertTools,代码行数:34,代码来源:UserProvider.php

示例10: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     // echa($response->getAccessToken());
     // 		echa($response->getResponse(), __FILE__);
     // -- Load user's data from P4S
     $data = $response->getResponse();
     if (null != $data && array_key_exists('status', $data) && ResponseHelper::OK == $data['status'] && array_key_exists('data', $data) && null != $data['data']) {
         $p4sId = $data['data']['id'];
     } else {
         throw new UsernameNotFoundException("Unable to load this user info");
     }
     $result = $this->em->getRepository('Amisure\\P4SApiBundle\\Entity\\User\\SessionUser')->findOneBy(array('username' => $p4sId));
     // - Create an account
     if (null == $result) {
         $user = $this->fillUser($data['data']);
         $this->createNewUser($user);
     } else {
         // $user = $result;
         $user = $this->fillUser($data['data']);
         $user->setId($result->getId());
     }
     // -- Save access token
     $this->session->set('access_token', $response->getAccessToken());
     return $user;
 }
开发者ID:trialog,项目名称:p4s-api-bundle,代码行数:25,代码来源:UserProvider.php

示例11: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     $email = $response->getEmail();
     $service = $response->getResourceOwner()->getName();
     /** @var UserOauthAccount $connection */
     $connection = $this->em->getRepository('OjsUserBundle:UserOauthAccount')->findOneBy(['providerId' => $username, 'provider' => $service]);
     if (!$connection && !empty($email)) {
         $userByEmail = $this->userManager->findUserByEmail($email);
         if ($userByEmail) {
             $connection = new UserOauthAccount();
             $connection->setUser($userByEmail);
             $connection->setProvider($service);
             $connection->setProviderId($response->getUsername());
         }
     }
     if (!$connection || $connection->getUser() === null) {
         $message = sprintf("User not found. Please register first and then connect the account from your profile.", $username);
         throw new AccountNotLinkedException($message);
     }
     $connection->setToken($response->getAccessToken());
     $this->em->persist($connection);
     $this->em->flush();
     return $connection->getUser();
 }
开发者ID:beyzakokcan,项目名称:ojs,代码行数:25,代码来源:FOSUBUserProvider.php

示例12: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getNickname();
     $twitterId = $response->getUsername();
     $accessToken = $response->getAccessToken();
     $secretToken = $response->getTokenSecret();
     $user = $this->userManager->findUserByUsername($username);
     //when the user is registrating
     if (is_null($user)) {
         // create new user here
         $user = $this->userManager->createUser();
         $user->setUsername($username);
         $user->setAccessToken($accessToken);
         $user->setTwitterId($twitterId);
         $user->setSecretToken($secretToken);
         //I have set all requested data with the user's username
         //modify here with relevant data
         $user->setEmail($username);
         $user->setPlainPassword($username);
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         return $user;
     }
     //if user exists - go with the HWIOAuth way
     $user->setAccessToken($accessToken);
     $user->setSecretToken($secretToken);
     return $user;
 }
开发者ID:josenava,项目名称:showHashtag,代码行数:31,代码来源:FOSUBUserProvider.php

示例13: buildBasedOnOAuthResponse

 public function buildBasedOnOAuthResponse(UserResponseInterface $response)
 {
     $user = new UserImpl();
     $user->setOAuthAccessToken($response->getAccessToken());
     $user->setOAuthId($response->getUsername());
     $user->setOAuthProviderClass(get_class($response->getResourceOwner()));
     $user->setUsername($response->getEmail());
     return $user;
 }
开发者ID:lukaszmakuch,项目名称:question-sheet-storage,代码行数:9,代码来源:UserFactory.php

示例14: createUserFromResponse

 /**
  * Create user from response
  *
  * @param UserResponseInterface $response
  *
  * @return User
  */
 private function createUserFromResponse(UserResponseInterface $response)
 {
     /** @var User $user User */
     $user = $this->userManager->createUser();
     $user->setUsername($response->getUsername())->setFullName($response->getRealName())->setEmail($response->getEmail())->setEnabled(true)->setPlainPassword(uniqid())->setFacebookId($response->getUsername())->setFacebookAccessToken($response->getAccessToken());
     $this->eventDispatcher->dispatch(AppEvents::FACEBOOK_USER_CONNECTED, new FacebookUserConnectedEvent($user));
     $this->userManager->updateUser($user);
     return $user;
 }
开发者ID:stfalcon-studio,项目名称:lost-and-found,代码行数:16,代码来源:AuthProvider.php

示例15: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response, $email = "")
 {
     $useremail = $response->getEmail();
     if ($useremail == "") {
         $useremail = $email;
     }
     if ($useremail != "") {
         $username = $useremail;
     } else {
         $username = $response->getUsername();
     }
     /** @var User $user */
     $user = $this->userManager->findUserByUsernameOrEmail($username);
     $service = $response->getResourceOwner()->getName();
     $setterID = $service . "Id";
     $setter = 'set' . ucfirst($service);
     $setter_id = $setter . 'Id';
     $setter_token = $setter . 'AccessToken';
     $getter = 'get' . ucfirst($service);
     $getter_id = $getter . 'Id';
     //when the user is registrating
     if (null === $user) {
         if ($this->userManager->findUserBy(array($setterID => $response->getUsername())) != null) {
             $user = $this->userManager->findUserBy(array($setterID => $response->getUsername()));
             return $user;
         } else {
             // create new user here
             $user = $this->userManager->createUser();
             $user->{$setter_id}($username);
             $user->{$setter_token}($response->getAccessToken());
             $user->setUsername($username);
             $user->setFullname($response->getRealName());
             if ($response->getResourceOwner()->getName() == 'facebook') {
                 $user->setPhoto('https://graph.facebook.com/' . $response->getUsername() . '/picture?type=large');
             } else {
                 $user->setPhoto($response->getProfilePicture());
             }
             $user->setPassword($username);
             $user->setEnabled(true);
             if (filter_var($response->getEmail(), FILTER_VALIDATE_EMAIL)) {
                 $user->setEmail($response->getEmail());
                 $user->setConfirmationToken(null);
             } else {
                 $user->setEmail($username);
             }
             $this->userManager->updateUser($user);
             return $user;
         }
     } else {
         $user->{$setter_id}($response->getUsername());
         $user->{$setter_token}($response->getAccessToken());
         $this->userManager->updateUser($user);
         return $user;
     }
 }
开发者ID:Alex223124,项目名称:edela,代码行数:58,代码来源:FOSUBUserProvider.php


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