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


PHP LinkedIn::is_authenticated方法代码示例

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


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

示例1: indexAction

 public function indexAction(Request $request, $provider)
 {
     try {
         // get previous url
         $session = $request->getSession();
         $loginUrl = $this->getRequest()->headers->get('referer');
         // make sure we find the configuration
         if ($this->container->hasParameter($provider) && !$this->getUser()) {
             // get current configuration for provider
             $configs = $this->container->getParameter($provider);
             if ($provider == 'twitter') {
                 define('TWITTER_CONSUMER_KEY', $configs['api_key']);
                 define('TWITTER_CONSUMER_SECRET', $configs['api_secret']);
                 define('TWITTER_OAUTH_CALLBACK', $this->getRequest()->getUri());
                 if (!$session->get('oauth_token')) {
                     $connection = new \TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
                     $request_token = $connection->getRequestToken(TWITTER_OAUTH_CALLBACK);
                     $session->set('oauth_token', $request_token['oauth_token']);
                     $session->set('oauth_token_secret', $request_token['oauth_token_secret']);
                     switch ($connection->http_code) {
                         case 200:
                             return $this->redirect($connection->getAuthorizeURL($request_token['oauth_token']));
                             break;
                         default:
                             throw new \Exception('Could not connect to Twitter. Refresh the page or try again later.');
                             break;
                     }
                 } else {
                     $connection = new \TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, $session->get('oauth_token'), $session->get('oauth_token_secret'));
                     $access_token = $connection->getAccessToken($request->get('oauth_verifier'));
                     $session->set('access_token', $access_token);
                     $content = $connection->get('account/verify_credentials');
                     $this->findUser($provider, array('id' => (string) $content->id, 'first_name' => (string) $content->name, 'last_name' => (string) $content->name, 'email' => (string) $content->id . '@twitter.com'));
                 }
             } elseif ($provider == 'google') {
                 // include google library
                 include dirname(__DIR__) . '/Vendor/Google/autoload.php';
                 $client = new \Google_Client();
                 $client->addScope("email");
                 $client->addScope("profile");
                 $client->setClientId($configs['api_key']);
                 $client->setClientSecret($configs['api_secret']);
                 $client->setRedirectUri($this->get_clean_url($this->getRequest()->getUri()));
                 if ($request->get('code', false)) {
                     $client->authenticate($request->get('code'));
                     $service = new \Google_Service_Oauth2($client);
                     $user = $service->userinfo->get();
                     //get user info
                     $this->findUser($provider, array('id' => (string) $user->id, 'first_name' => (string) $user->givenName, 'last_name' => (string) $user->familyName, 'email' => (string) $user->email));
                 } else {
                     return $this->redirect($client->createAuthUrl());
                 }
             } elseif ($provider == 'facebook') {
                 $facebook = new \FaceBook($configs['api_key'], $configs['api_secret'], $this->getRequest()->getUri());
                 if (!$facebook->is_authenticated()) {
                     return $this->redirect($facebook->get_redirect_url());
                 } else {
                     $this->findUser($provider, $facebook->get_user($session));
                 }
             } elseif ($provider == 'linkedin') {
                 $linkedin = new \LinkedIn($configs['api_key'], $configs['api_secret'], $this->getRequest()->getUri());
                 if (!$linkedin->is_authenticated()) {
                     return $this->redirect($linkedin->get_redirect_url());
                 } else {
                     $this->findUser($provider, $linkedin->get_user($session));
                 }
             }
         }
     } catch (\Exception $e) {
         $this->get('session')->getFlashBag()->add('error', $e->getMessage());
     }
     return $this->redirect($this->generateUrl($this->container->getParameter('login_path')));
 }
开发者ID:phpcodebooster,项目名称:social-login,代码行数:73,代码来源:DefaultController.php


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