Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

ssl support added to the rest library #12

Closed
wants to merge 2 commits into from

3 participants

@paulyasi

This fork adds ssl support to the rest library by adding the variable ssl_verify_peer to indicate whether one wants certificate verification and the ssl_cainfo variable that will hold the path to the certificate file.

@philsturgeon

"TRUE" is a string?

@chriskacerguis chriskacerguis closed this pull request from a commit
Chris Kacerguis Fixes #12 74be10d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 1 deletion.
  1. +12 −1 README.md
  2. +15 −0 libraries/Rest.php
View
13 README.md
@@ -12,10 +12,21 @@ CodeIgniter-REST Client is a CodeIgniter library which makes it easy to do use R
## Usage
// Load the rest client spark
- $this->load->spark('restclient');
+ $this->load->spark('restclient/2.0.0');
+
+ // load the rest library
+ $this->load->library('rest');
// Run some setup
$this->rest->initialize(array('server' => 'http://twitter.com/'));
+
+ // for ssl and http basic authentication initialize with:
+ $this->rest->initialize(array('server' => 'https://example.com/',
+ 'http_user' => 'username',
+ 'http_pass' => 'password',
+ 'http_auth' => 'basic',
+ 'ssl_verify_peer' => TRUE,
+ 'ssl_cainfo' => '/certs/cert.pem'));
// Pull in an array of tweets
$tweets = $this->rest->get('statuses/user_timeline/'.$username.'.xml');
View
15 libraries/Rest.php
@@ -42,6 +42,8 @@ class REST
private $http_auth = null;
private $http_user = null;
private $http_pass = null;
+ private $ssl_verify_peer = null;
+ private $ssl_cainfo = null;
private $response_string;
@@ -81,6 +83,8 @@ public function initialize($config)
isset($config['http_auth']) && $this->http_auth = $config['http_auth'];
isset($config['http_user']) && $this->http_user = $config['http_user'];
isset($config['http_pass']) && $this->http_pass = $config['http_pass'];
+ isset($config['ssl_verify_peer']) && $this->ssl_verify_peer = $config['ssl_verify_peer'];
+ isset($config['ssl_cainfo']) && $this->ssl_cainfo = $config['ssl_cainfo'];
}
@@ -139,6 +143,17 @@ private function _call($method, $uri, $params = array(), $format = NULL)
// Initialize cURL session
$this->_ci->curl->create($this->rest_server.$uri);
+ // If using ssl set the ssl verification value and cainfo
+ if ($this->ssl_verify_peer == FALSE)
+ {
+ $this->_ci->curl->ssl(FALSE);
+ }
+ elseif ($this->ssl_verify_peer == TRUE)
+ {
+ $this->ssl_cainfo = getcwd() . $this->ssl_cainfo;
+ $this->_ci->curl->ssl(TRUE, 2, $this->ssl_cainfo);
+ }
+
// If authentication is enabled use it
if ($this->http_auth != '' && $this->http_user != '')
{
Something went wrong with that request. Please try again.