Posted By

khalidity on 02/23/11


Tagged

php facebook OAuth


Versions (?)

Generating Session Parameters from Facebook Access Token


 / Published in: PHP
 

Useful if you want to generate a cookie to be used by facebook PHP-SDK, when you only have an access_token generate from "code" query string

  1. define('APP_SECRET','XXXXXXXXXXXXXXXXX');
  2.  
  3. function generateSessionVars($accessToken)
  4. {
  5. $e = explode('|',$accessToken);
  6. $s = explode('-',$e[1]);
  7.  
  8.  
  9. $params = array(
  10. 'uid'=>trim($s[1]),
  11. 'session_key'=>trim($e[1]),
  12. 'access_token' => trim($accessToken),
  13. 'secret' => APP_SECRET,
  14. );
  15. $params['sig'] = generateSignature($params,APP_SECRET);
  16.  
  17. return $params;
  18. }
  19.  
  20.  
  21. function generateSignature($params,$secret) {
  22.  
  23. // work with sorted data
  24. ksort($params);
  25.  
  26. // generate the base string
  27. $base_string = '';
  28. foreach($params as $key => $value) {
  29. $base_string .= $key . '=' . $value;
  30. }
  31. $base_string .= $secret;
  32.  
  33. return md5($base_string);
  34. }

Report this snippet  

You need to login to post a comment.