[geeklog-hg] geeklog: Updated OAuth class and dependant http class to v 1.141...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Fri Sep 18 10:19:45 EDT 2015


changeset 9620:ca097f881197
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/ca097f881197
user: Tom
date: Fri Sep 18 10:19:32 2015 -0400
description:
Updated OAuth class and dependant http class to v 1.141 released 2015/08/22

diffstat:

 system/classes/http/http.php          |   15 +-
 system/classes/oauth/oauth_client.php |  252 +++++++++++++++++++++++++++------
 2 files changed, 216 insertions(+), 51 deletions(-)

diffs (truncated from 597 to 300 lines):

diff -r 71b7aa45075f -r ca097f881197 system/classes/http/http.php
--- a/system/classes/http/http.php	Mon Aug 24 22:48:23 2015 -0400
+++ b/system/classes/http/http.php	Fri Sep 18 10:19:32 2015 -0400
@@ -2,7 +2,7 @@
 /*
  * http.php
  *
- * @(#) $Header: /opt2/ena/metal/http/http.php,v 1.92 2014/08/14 23:17:34 mlemos Exp $
+ * @(#) $Header: /opt2/ena/metal/http/http.php,v 1.93 2015/08/22 18:53:37 mlemos Exp $
  *
  */
 
@@ -27,7 +27,7 @@
 
 	var $protocol="http";
 	var $request_method="GET";
-	var $user_agent='httpclient (http://www.phpclasses.org/httpclient $Revision: 1.92 $)';
+	var $user_agent='httpclient (http://www.phpclasses.org/httpclient $Revision: 1.93 $)';
 	var $accept='';
 	var $authentication_mechanism="";
 	var $user;
@@ -640,6 +640,8 @@
 			$this->socks_host_port=$arguments["SOCKSHostPort"];
 		if(IsSet($arguments["SOCKSVersion"]))
 			$this->socks_version=$arguments["SOCKSVersion"];
+		if(IsSet($arguments["PreferCurl"]))
+			$this->prefer_curl=$arguments["PreferCurl"];
 		if(IsSet($arguments["Protocol"]))
 			$this->protocol=$arguments["Protocol"];
 		switch(strtolower($this->protocol))
@@ -1009,7 +1011,9 @@
 
 	Function ConnectFromProxy($arguments, &$headers)
 	{
-		if(!$this->PutLine('CONNECT '.$this->host_name.':'.($this->host_port ? $this->host_port : 443).' HTTP/1.0')
+		$host = $this->host_name.':'.($this->host_port ? $this->host_port : 443);
+		$this->OutputDebug('Connecting from proxy to host '.$host);
+		if(!$this->PutLine('CONNECT '.$host.' HTTP/1.0')
 		|| (strlen($this->user_agent)
 		&& !$this->PutLine('User-Agent: '.$this->user_agent))
 		|| (strlen($this->accept)
@@ -1034,12 +1038,15 @@
 		switch($this->response_status)
 		{
 			case "200":
-				if(!@stream_socket_enable_crypto($this->connection, 1, STREAM_CRYPTO_METHOD_SSLv23_CLIENT))
+				$this->OutputDebug('Establishing the cryptography layer with host '.$host);
+				if(!stream_socket_enable_crypto($this->connection, 1, STREAM_CRYPTO_METHOD_SSLv23_CLIENT))
 				{
+					$this->OutputDebug('Failed establishing the cryptography layer with host '.$host);
 					$this->SetPHPError('it was not possible to start a SSL encrypted connection via this proxy', $php_errormsg, HTTP_CLIENT_ERROR_COMMUNICATION_FAILURE);
 					$this->Disconnect();
 					return($this->error);
 				}
+				$this->OutputDebug('Succeeded establishing the cryptography layer with host '.$host);
 				$this->state = "Connected";
 				break;
 			case "407":
diff -r 71b7aa45075f -r ca097f881197 system/classes/oauth/oauth_client.php
--- a/system/classes/oauth/oauth_client.php	Mon Aug 24 22:48:23 2015 -0400
+++ b/system/classes/oauth/oauth_client.php	Fri Sep 18 10:19:32 2015 -0400
@@ -2,7 +2,7 @@
 /*
  * oauth_client.php
  *
- * @(#) $Id: oauth_client.php,v 1.125 2014/12/23 03:51:59 mlemos Exp $
+ * @(#) $Id: oauth_client.php,v 1.141 2015/08/22 20:36:36 mlemos Exp $
  *
  */
 
@@ -12,7 +12,7 @@
 
 	<package>net.manuellemos.oauth</package>
 
-	<version>@(#) $Id: oauth_client.php,v 1.125 2014/12/23 03:51:59 mlemos Exp $</version>
+	<version>@(#) $Id: oauth_client.php,v 1.141 2015/08/22 20:36:36 mlemos Exp $</version>
 	<copyright>Copyright © (C) Manuel Lemos 2012</copyright>
 	<title>OAuth client</title>
 	<author>Manuel Lemos</author>
@@ -228,6 +228,7 @@
 				Currently it supports the following servers:
 				<stringvalue>37Signals</stringvalue>,
 				<stringvalue>Amazon</stringvalue>,
+				<stringvalue>AOL</stringvalue>,
 				<stringvalue>Bitbucket</stringvalue>,
 				<stringvalue>Bitly</stringvalue>,
 				<stringvalue>Box</stringvalue>,
@@ -258,6 +259,7 @@
 				<stringvalue>Mavenlink</stringvalue>,
 				<stringvalue>Meetup</stringvalue>,
 				<stringvalue>Microsoft</stringvalue>,
+				<stringvalue>Misfit</stringvalue>,
 				<stringvalue>oDesk</stringvalue>,
 				<stringvalue>Paypal</stringvalue>,
 				<stringvalue>PaypalApplication</stringvalue>,
@@ -358,7 +360,8 @@
 				{SCOPE} - scope of the requested permissions to the granted by the
 				OAuth server with the user permissions<paragraphbreak />
 				{STATE} - identifier of the OAuth session state<paragraphbreak />
-				{API_KEY} - API key to access the server</usage>
+				{API_KEY} - API key to access the server<paragraphbreak />
+				{REALM} - realm name for OpenID Connect</usage>
 		</documentation>
 	</variable>
 {/metadocument}
@@ -660,6 +663,22 @@
 /*
 {metadocument}
 	<variable>
+		<name>realm</name>
+		<type>STRING</type>
+		<value></value>
+		<documentation>
+			<purpose>Realm of authorization for OpenID Connect</purpose>
+			<usage>Set this variable to the realm value when using OpenID
+				Connect.</usage>
+		</documentation>
+	</variable>
+{/metadocument}
+*/
+	var $realm = '';
+
+/*
+{metadocument}
+	<variable>
 		<name>offline</name>
 		<type>BOOLEAN</type>
 		<value>0</value>
@@ -830,7 +849,9 @@
 			<usage>Set this variable to <stringvalue>basic</stringvalue> if the
 				OAuth server requires that the the client ID and secret be passed
 				using HTTP basic authentication headers when retrieving a new
-				token.</usage>
+				token. Set this variable to <stringvalue>none</stringvalue> to
+				avoid that the Authorization header be set in the request to get
+				the access token.</usage>
 		</documentation>
 	</variable>
 {/metadocument}
@@ -840,6 +861,27 @@
 /*
 {metadocument}
 	<variable>
+		<name>refresh_token_authentication</name>
+		<type>STRING</type>
+		<value></value>
+		<documentation>
+			<purpose>Option to determine if the requests to refresh an expired
+				access token should use authentication to pass the application
+				client ID and secret.</purpose>
+			<usage>Leave this value with an empty string to make it use the same
+				as the <variablelink>access_token_authentication</variablelink>
+				variable. Set this variable to <stringvalue>none</stringvalue> to
+				avoid that the Authorization header be set in the request to get
+				the refresh token.</usage>
+		</documentation>
+	</variable>
+{/metadocument}
+*/
+	var $refresh_token_authentication = '';
+
+/*
+{metadocument}
+	<variable>
 		<name>refresh_token</name>
 		<type>STRING</type>
 		<value></value>
@@ -969,7 +1011,32 @@
 */
 	var $grant_type = "authorization_code";
 
-	var $oauth_user_agent = 'PHP-OAuth-API (http://www.phpclasses.org/oauth-api $Revision: 1.125 $)';
+/*
+{metadocument}
+	<variable>
+		<name>http_arguments</name>
+		<type>HASH</type>
+		<value></value>
+		<documentation>
+			<purpose>Define additional arguments to configure the HTTP
+				requests.</purpose>
+			<usage>Set this associative array with argument values that you need
+				to set options of the HTTP requests sent to the OAuth server and
+				API URLs.<paragraphbreak />
+				Check the documentation of the <link>
+					<data>HTTP client class</data>
+					<url>http://www.phpclasses.org/httpclient</url>
+				</link> for more
+				information on the available arguments that can be configured
+				using this option.</usage>
+		</documentation>
+	</variable>
+{/metadocument}
+*/
+	var $http_arguments = array();
+	var $oauth_user_agent = 'PHP-OAuth-API (http://www.phpclasses.org/oauth-api $Revision: 1.141 $)';
+
+	var $response_time = 0;
 
 	Function SetError($error)
 	{
@@ -1014,8 +1081,9 @@
 			'{STATE}', UrlEncode($state), str_replace(
 			'{CLIENT_ID}', UrlEncode($this->client_id), str_replace(
 			'{API_KEY}', UrlEncode($this->api_key), str_replace(
-			'{SCOPE}', UrlEncode($this->scope),
-			$url)))));
+			'{SCOPE}', UrlEncode($this->scope), str_replace(
+			'{REALM}', UrlEncode($this->realm),
+			$url))))));
 		return(true);
 	}
 
@@ -1274,8 +1342,8 @@
 		if(session_id() === ''
 		&& !session_start())
 			return($this->SetPHPError('it was not possible to start the PHP session', $php_errormsg));
-		if(IsSet($_SESSION['OAUTH_ACCESS_TOKEN'][$access_token_url]))
-			Unset($_SESSION['OAUTH_ACCESS_TOKEN'][$access_token_url]);
+		Unset($_SESSION['OAUTH_ACCESS_TOKEN'][$access_token_url]);
+		UnSet($_SESSION['OAUTH_STATE']);
 		return true;
 	}
 /*
@@ -1427,18 +1495,24 @@
 			foreach($files as $name => $value)
 			{
 				if(!IsSet($parameters[$name]))
-					return($this->SetError('it was specified an file parameters named '.$name));
+					return($this->SetError('it was not specified a file parameter named '.$name));
 				$file = array();
-				switch(IsSet($value['Type']) ? $value['Type'] : 'FileName')
+				$value_type = IsSet($value['Type']) ? $value['Type'] : 'FileName';
+				switch($value_type)
 				{
 					case 'FileName':
 						$file['FileName'] = $parameters[$name];
+						if(IsSet($value['FileName']))
+							$file['Name'] = $value['FileName'];
 						break;
 					case 'Data':
 						$file['Data'] = $parameters[$name];
+						if(!IsSet($value['FileName']))
+							return($this->SetError('it was not specified the file name for data file parameter '.$name));
+						$file['Name'] = $value['FileName'];
 						break;
 					default:
-						return($this->SetError($value['Type'].' is not a valid type for file '.$name));
+						return($this->SetError($value_type.' is not a valid type for file '.$name));
 				}
 				$file['Content-Type'] = (IsSet($value['ContentType']) ? $value['ContentType'] : 'automatic/name');
 				$post_files[$name] = $file;
@@ -1471,6 +1545,7 @@
 					case 'application/x-www-form-urlencoded':
 					case 'multipart/form-data':
 					case 'application/json':
+					case 'application/javascript':
 						break;
 					default:
 						$first = (strpos($url, '?') === false);
@@ -1498,6 +1573,7 @@
 			$authorization = 'Bearer '.$this->access_token;
 		if(strlen($error = $http->GetRequestArguments($url, $arguments)))
 			return($this->SetError('it was not possible to open the '.$options['Resource'].' URL: '.$error));
+		$arguments = array_merge($this->http_arguments, $arguments);
 		if(strlen($error = $http->Open($arguments)))
 			return($this->SetError('it was not possible to open the '.$options['Resource'].' URL: '.$error));
 		if(count($post_files))
@@ -1512,6 +1588,7 @@
 				$arguments['PostValues'] = $post_values;
 				break;
 			case 'application/json':
+			case 'application/javascript':
 				$arguments['Headers']['Content-Type'] = $options['RequestContentType'];
 				$arguments['Body'] = (IsSet($options['RequestBody']) ? $options['RequestBody'] : json_encode($parameters));
 				break;
@@ -1536,6 +1613,8 @@
 				if(strlen($authorization))
 					$arguments['Headers']['Authorization'] = $authorization;
 				break;
+			case 'none':
+				break;
 			default:
 				return($this->SetError($authentication.' is not a supported authentication mechanism to retrieve an access token'));
 		}
@@ -1555,11 +1634,13 @@
 		}
 		$this->response_status = intval($http->response_status);
 		$content_type = (IsSet($options['ResponseContentType']) ? $options['ResponseContentType'] : (IsSet($headers['content-type']) ? strtolower(trim(strtok($headers['content-type'], ';'))) : 'unspecified'));
-		$content_type = preg_replace('/^(.+\\/).+\\+(.+)$/', '\\1\\2', $content_type); 
+		$content_type = preg_replace('/^(.+\\/).+\\+(.+)$/', '\\1\\2', $content_type);
+		$this->response_time = (IsSet($headers['date']) ? strtotime(GetType($headers['date']) === 'array' ? $headers['date'][0] : $headers['date']) : time());
 		switch($content_type)
 		{
 			case 'text/javascript':
 			case 'application/json':
+			case 'application/javascript':
 				if(!function_exists('json_decode'))
 					return($this->SetError('the JSON extension is not available in this PHP setup'));
 				$object = json_decode($data);



More information about the geeklog-cvs mailing list