From 2f573b1e78254a8d2b5ff53fd859cab7f4064740 Mon Sep 17 00:00:00 2001 From: JavRok Date: Mon, 12 Mar 2012 02:07:08 +0100 Subject: [PATCH] Proposed changes for the API to work with Facebook OAuth v2. Instructions on 'CakePHP-Api-Datasources' project --- Lib/HttpSocketOauth.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Lib/HttpSocketOauth.php b/Lib/HttpSocketOauth.php index 8a37269..692bded 100644 --- a/Lib/HttpSocketOauth.php +++ b/Lib/HttpSocketOauth.php @@ -84,7 +84,11 @@ public function request($request = array()) { // authorization header, for example, OAuth Echo as used by Twitpic and // Twitter includes an Authorization Header as required by twitter's verify // credentials API in the X-Verify-Credentials-Authorization header. - $request['header']['Authorization'] = $this->authorizationHeader($request); + if (isset($request['auth']['oauth_version']) && $request['auth']['oauth_version'] == '2.0'){ + $request['header']['Authorization'] = $this->authorizationHeaderV2($request); + }else{ + $request['header']['Authorization'] = $this->authorizationHeader($request); + } // Now the Authorization header is built, fire the request off to the parent // HttpSocket class request method that we intercepted earlier. @@ -247,6 +251,24 @@ public function authorizationHeader($request) { return $authorizationHeader; } + + /** + * Returns the OAuth V2 Authorization Header string for a given request array + * Old V1 params weren't accepted and returned error. + * + * @param array $request As required by HttpSocket::request(). NOTE ONLY + * THE ARRAY TYPE OF REQUEST IS SUPPORTED + * @return String + * @author Javier Rocamora + * @todo Check if other params are needed and build correctly + */ + public function authorizationHeaderV2($request) { + + $authorizationHeader = 'OAuth '; + $authorizationHeader .= $request['auth']['access_token']; + + return $authorizationHeader; + } /** * Builds an Authorization header param string from the supplied name and