Symfony2 HwioAuth - 从linkedin获取完整的配置文件

Posted

技术标签:

【中文标题】Symfony2 HwioAuth - 从linkedin获取完整的配置文件【英文标题】:Symfony2 HwioAuth - getting full profildetail from linkedin 【发布时间】:2013-09-08 03:03:19 【问题描述】:

我昨天已经为我关于 symfony2 中的 hwioauthbundle 的问题打开了一个主题。 Symfony2 HWIOauthBundle error with response

感谢 stloyd 的回答,这帮助我弄清楚了如何使用捆绑包来访问linkedin。

我现在不仅尝试从linkedin获取格式化名称,还尝试获取其他信息,如教育、技能等。

我不确定 HwioAuth 通常是否可以做到这一点? 那是我的 config.yml

hwi_oauth:
firewall_name: main
resource_owners:
    linkedin:
        type: linkedin
        client_id: %linkedin_client_id%
        client_secret: %linkedin_client_secret%
        scope: r_fullprofile
        infos_url: 'https://api.linkedin.com/v1/people/~:(id,educations,languages,skills)?format=json'
        scope:     'r_fullprofile'
        paths:
            educations: educations
            languages: languages
            skills: skills

那是我的 security.yml:

    providers:
     ....
     my_custom_hwi_provider:
        id: linkedin.oauth_user_provider

firewalls:
    main:
       ...
        oauth:
            resource_owners:
                linkedin: "/login/check-linkedin"
            login_path: /login
            failure_path: /login
            oauth_user_provider:
                service: linkedin.oauth_user_provider

这是我的服务类 Provider:

    <?php

namespace XXXX\UtilBundle\Util\OAuthProvider;

use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUserProvider;
use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;

class Provider

   protected $session, $doctrine;
   public function __construct($session, $doctrine) 
       $this->session = $session;
       $this->doctrine = $doctrine;

   



   public function loadUserByOAuthUserResponse(UserResponseInterface $response)
   
      //data from LINKEDIN response
      var_dump($response);
      exit;
   
 

如你所见,我将我从linkedin 获得的json 输出。 Hier 可能是响应和教育领域,技能是空的!

    class HWI\Bundle\OAuthBundle\OAuth\Response\PathUserResponse#694 (4) 
 protected $paths =>
 array(8) 
'identifier' =>
string(2) "id"
'nickname' =>
string(13) "formattedName"
'realname' =>
string(13) "formattedName"
'email' =>
string(12) "emailAddress"
'profilepicture' =>
string(10) "pictureUrl"
'educations' =>
string(10) "educations"
'languages' =>
string(9) "languages"
'skills' =>
string(6) "skills"

protected $response =>
 array(1) 
 'id' =>
 string(10) "XYXYXYXYXYXYXY"

protected $resourceOwner =>
class HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\LinkedinResourceOwner#699 (8) 
  protected $options =>
    array(8) 
    'authorization_url' =>
    string(49) "https://www.linkedin.com/uas/oauth2/authorization"
    'access_token_url' =>
    string(47) "https://www.linkedin.com/uas/oauth2/accessToken"
    'infos_url' =>
    string(81) "https://api.linkedin.com/v1/people/~:(id,educations,languages,skills)?format=json"
    'csrf' =>
    bool(true)
    'client_id' =>
    string(12) "XYXYXYXYXYXYXY"
    'client_secret' =>
    string(16) "XYXYXYXYXYXYXY"
    'scope' =>
    string(29) "r_fullprofile"
    'options' =>
    array(0) 
    ...
   
  
  protected $paths =>
   array(8) 
    'identifier' =>
      string(2) "id"
     'nickname' =>
       string(13) "formattedName"
     'realname' =>
       string(13) "formattedName"
     'email' =>
       string(12) "emailAddress"
     'profilepicture' =>
       string(10) "pictureUrl"
     'educations' =>
       string(10) "educations"
     'languages' =>
       string(9) "languages"
     'skills' =>
       string(6) "skills"
    
    protected $defaultOptions =>
     array(6) 
      'client_id' =>
        NULL
      'client_secret' =>
        NULL
      'infos_url' =>
        NULL
      'user_response_class' =>
        string(54) "HWI\Bundle\OAuthBundle\OAuth\Response\PathUserResponse"
      'scope' =>
        NULL
      'csrf' =>
        bool(false)
     
   protected $httpClient =>
   class Buzz\Client\Curl#700 (7) 
      private $lastCurl =>
      resource(286) of type (curl)
      protected $options =>
       array(2) 
       ...
    
   protected $ignoreErrors =>
    bool(true)
   protected $maxRedirects =>
    int(5)
   protected $timeout =>
    int(5)
   protected $verifyPeer =>
    bool(true)
   protected $proxy =>
    NULL
  
   protected $name =>
    string(8) "linkedin"
    protected $state =>
    NULL
    protected $storage =>
  class HWI\Bundle\OAuthBundle\OAuth\RequestDataStorage\SessionStorage#701 (1) 
    private $session =>
      class Symfony\Component\HttpFoundation\Session\Session#220 (3) 
      ...
   
  
    public $httpUtils =>
    class Symfony\Component\Security\Http\HttpUtils#230 (2) 
    private $urlGenerator =>
    class Symfony\Bundle\FrameworkBundle\Routing\Router#233 (9) 
     ...
    
    private $urlMatcher =>
    class Symfony\Bundle\FrameworkBundle\Routing\Router#233 (9) 
     ...
   
  

 protected $oAuthToken =>
 class HWI\Bundle\OAuthBundle\Security\Core\Authentication\Token\OAuthToken#696 (11) 
  private $accessToken =>
   string(179) "XYXYXYXYXYXYXY"
   private $rawToken =>
    array(2) 
     'expires_in' =>
     int(5183807)
     'access_token' =>
      string(179) "XYXYXYXYXYXYXYXY"
   
   private $refreshToken =>
  NULL
   private $expiresIn =>
   int(5183807)
   private $createdAt =>
   int(1378302276)
   private $tokenSecret =>
   NULL
   private $resourceOwnerName =>
   NULL
   private $user =>
   NULL
   private $roles =>
    array(0) 
   
   private $authenticated =>
    bool(false)
    private $attributes =>
    array(0) 
    
 

在受保护的 $oAuthToken => 中是值 私人 $authenticated => 布尔(假)

我被认证了吗? 以及如何从 Linkedin 访问以 r_fullprofile 作为范围的其他字段?

问候

【问题讨论】:

【参考方案1】:

看看这个LinkedIn API client 和它的第一个例子。你通过

来取东西
$linkedIn->api('v1/people/~:(firstName,lastName)');

另外,看看API documentation。它清楚地说明了您可以获取哪些字段以及如何获取。

【讨论】:

以上是关于Symfony2 HwioAuth - 从linkedin获取完整的配置文件的主要内容,如果未能解决你的问题,请参考以下文章

symfony2:试图从命名空间加载类“Memcache”

Symfony2 从服务发送电子邮件

如何从 symfony2 中删除实体

Symfony2.8。如何从发布请求中获取数据

从 Symfony2 中的控制器访问集合表单字段

Symfony2 自定义选民:无法从选民内部访问 getDoctrine