2013-08-23 2 views
1

그래서 나는 다음과 같은 시나리오를 가지고 :폰갭 + 페이스 북 + PHP 백엔드 : 페이스 북 사용자 로그인

이미

한 폰갭 앱은 존재합니다 (JS SDK와 함께) 사용자를 인증하는 페이스 북의 로그인을 사용

한 PHP 백엔드 이미 페이스 북 플러그인이 작동하고 있습니다.

이제 제 질문은 : 내 phonegap 앱이 Facebook으로 인증 한 후 토큰 등이 있습니다.하지만 PHP 백엔드로 사용자를 인증해야합니다. Facebook PHP SDK는 쿠키를 사용하며 Phonegap은 쿠키를 지원하지 않습니다.

PHP SDK에 토큰을 보내고 토큰의 유효성을 처리하고 실제로 백엔드에서 해당 사용자의 세션을 생성하는 방법이 있습니까? 즉, 해당 전자 메일과 관련된 백엔드 사용자를 찾으십시오. 사용자가 실제로 인증되어 앱을 사용하기 시작할 수 있다고 phonegap 앱에 알립니다.)

/** 
* Extends the BaseFacebook class with the intent of NOT using 
* PHP sessions to store user ids and access tokens. 
* @Author Felipe Guaycuru <[email protected]> 
*/ 
class FacebookVolatile extends BaseFacebook 
{ 
    // Stores the shared session ID if one is set. 
    //protected $sharedSessionID; 

    // Stores data non-persistently 
    private $storage = array(); 

    /** 
    * Identical to the parent constructor. 
    * 
    * @param Array $config the application configuration. 
    * @param String $access_token the supplied access token. 
    * @see BaseFacebook::__construct in facebook.php 
    */ 
    public function __construct($config, $access_token) { 
    parent::__construct($config); 
    $this->setAccessToken($access_token); 
    } 

    protected static $kSupportedKeys = 
    array('state', 'code', 'access_token', 'user_id'); 

    /** 
    * Provides the implementations of the inherited abstract 
    * methods. The implementation uses class properties to maintain 
    * a store for authorization codes, user ids, CSRF states, and 
    * access tokens. 
    */ 
    protected function setPersistentData($key, $value) { 
    if (!in_array($key, self::$kSupportedKeys)) { 
     self::errorLog('Unsupported key passed to setPersistentData.'); 
     return; 
    } 

    $this->storage[$key] = $value; 
    } 

    protected function getPersistentData($key, $default = false) { 
    if (!in_array($key, self::$kSupportedKeys)) { 
     self::errorLog('Unsupported key passed to getPersistentData.'); 
     return $default; 
    } 

    return isset($this->storage[$key]) ? 
     $this->storage[$key] : $default; 
    } 

    protected function clearPersistentData($key) { 
    if (!in_array($key, self::$kSupportedKeys)) { 
     self::errorLog('Unsupported key passed to clearPersistentData.'); 
     return; 
    } 

    unset($this->storage[$key]); 
    } 

    protected function clearAllPersistentData() { 
    foreach (self::$kSupportedKeys as $key) { 
     $this->clearPersistentData($key); 
    } 
    } 
} 

그래서 내 PHP 백엔드에서 나는 $access_token을 받고이 같이 사용할 수 :

$FB = new FacebookVolatile(array(
    'appId' => CONFIG_FACEBOOK_APP_ID, 
    'secret' => CONFIG_FACEBOOK_APP_SECRET, 
), $access_token); 

가 그럼 난 사용할 수 있습니다

답변

1

그래서 나는이 같은 "Facebook_Volatile"클래스를 구현 결국 $FB 일반적으로 JS SDK와 함께 사용하는 것과 정확히 동일합니다.