29 public $openid_url_identity;
30 public $URLs = array();
31 public $error = array();
32 public $fields = array(
33 'required' => array(),
34 'optional' => array(),
42 if (!function_exists(
'curl_exec'))
44 die(
'Error: Class SimpleOpenID requires curl extension to work');
58 $this->URLs[
'openid_server'] = $a;
71 $this->URLs[
'trust_root'] = $a;
84 $this->URLs[
'cancel'] = $a;
97 $this->URLs[
'approved'] = $a;
111 $this->
fields[
'required'] = $a;
113 $this->
fields[
'required'][] = $a;
128 $this->
fields[
'optional'] = $a;
130 $this->
fields[
'optional'][] = $a;
145 if ((stripos($a,
'http://') ===
false)
146 && (stripos($a,
'https://') ===
false)) {
162 $this->openid_url_identity = $a;
175 return $this->openid_url_identity;
188 return array(
'code'=>$e[0],
'description'=>$e[1]);
202 $errs[
'OPENID_NOSERVERSFOUND'] =
'Cannot find OpenID Server TAG on Identity page.';
204 $desc = $errs[$code];
206 $this->error = array($code, $desc);
218 if (count($this->error) > 0)
235 $response = explode(
"\n", $response);
236 foreach ($response as $line) {
239 list($key, $value) = explode(
":", $line, 2);
240 $r[trim($key)] = trim($value);
256 if ($openid_identity === null)
257 $openid_identity = $this->openid_url_identity;
259 $u = parse_url(strtolower(trim($openid_identity)));
261 if (!isset($u[
'path']) || ($u[
'path'] ==
'/')) {
264 if (substr($u[
'path'], -1, 1) ==
'/') {
265 $u[
'path'] = substr($u[
'path'], 0, strlen($u[
'path']) - 1);
267 if (isset($u[
'query'])) {
268 return $u[
'host'].$u[
'path'].
'?'.$u[
'query'];
270 return $u[
'host'].$u[
'path'];
283 if (!is_array($arr)) {
287 foreach ($arr as $key => $value) {
288 $query .= $key.
"=".$value.
"&";
305 $fp = fsockopen(
"ssl://www.myopenid.com", 443, $errno, $errstr, 3);
307 $this->
ErrorStore(
'OPENID_SOCKETERROR', $errstr);
310 $request = $method.
" /server HTTP/1.0\r\n";
311 $request .=
"User-Agent: Dolibarr\r\n";
312 $request .=
"Connection: close\r\n\r\n";
313 fwrite($fp, $request);
314 stream_set_timeout($fp, 4);
315 $res = fread($fp, 2000);
316 $info = stream_get_meta_data($fp);
319 if ($info[
'timed_out']) {
340 if (is_array($params)) $params = $this->
array2url($params);
342 $curl = curl_init($url.($method ==
"GET" && $params !=
"" ?
"?".$params :
""));
343 @curl_setopt($curl, CURLOPT_FOLLOWLOCATION,
true);
344 curl_setopt($curl, CURLOPT_HEADER,
false);
345 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,
false);
346 curl_setopt($curl, CURLOPT_HTTPGET, ($method ==
"GET"));
347 curl_setopt($curl, CURLOPT_POST, ($method ==
"POST"));
348 if ($method ==
"POST") curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
349 curl_setopt($curl, CURLOPT_RETURNTRANSFER,
true);
350 $response = curl_exec($curl);
352 if (curl_errno($curl) == 0) {
355 $this->
ErrorStore(
'OPENID_CURL', curl_error($curl));
373 preg_match_all(
'/<link[^>]*rel=[\'"]openid.server[\'"][^>]*href=[\'"]([^\'"]+)[\'"][^>]*\/?>/i', $content, $matches1);
374 preg_match_all(
'/<link[^>]*href=\'"([^\'"]+)[\'"][^>]*rel=[\'"]openid.server[\'"][^>]*\/?>/i', $content, $matches2);
375 $servers = array_merge($matches1[1], $matches2[1]);
377 preg_match_all(
'/<link[^>]*rel=[\'"]openid.delegate[\'"][^>]*href=[\'"]([^\'"]+)[\'"][^>]*\/?>/i', $content, $matches1);
379 preg_match_all(
'/<link[^>]*href=[\'"]([^\'"]+)[\'"][^>]*rel=[\'"]openid.delegate[\'"][^>]*\/?>/i', $content, $matches2);
381 $delegates = array_merge($matches1[1], $matches2[1]);
383 $ret = array($servers, $delegates);
400 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
401 if (empty($url)) $url = $conf->global->MAIN_AUTHENTICATION_OPENID_URL;
406 if (count($servers) == 0) {
410 if (isset($delegates[0])
411 && ($delegates[0] !=
"")) {
428 $params[
'openid.return_to'] = urlencode($this->URLs[
'approved']);
429 $params[
'openid.mode'] =
'checkid_setup';
430 $params[
'openid.identity'] = urlencode($this->openid_url_identity);
431 $params[
'openid.trust_root'] = urlencode($this->URLs[
'trust_root']);
433 if (isset($this->
fields[
'required'])
434 && (count($this->
fields[
'required']) > 0)) {
435 $params[
'openid.sreg.required'] = implode(
',', $this->
fields[
'required']);
437 if (isset($this->
fields[
'optional'])
438 && (count($this->
fields[
'optional']) > 0)) {
439 $params[
'openid.sreg.optional'] = implode(
',', $this->
fields[
'optional']);
441 return $this->URLs[
'openid_server'].
"?".$this->
array2url($params);
456 echo
'<script language="JavaScript" type="text/javascript">window.location=\'';
459 } else { // Default Header Redirect
460 header('Location:
'.$redirect_to);
464 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
470 public function ValidateWithServer()
474 'openid.assoc_handle
' => urlencode($_GET['openid_assoc_handle
']),
475 'openid.signed
' => urlencode($_GET['openid_signed
']),
476 'openid.sig
' => urlencode($_GET['openid_sig
'])
478 // Send only required parameters to confirm validity
479 $arr_signed = explode(",", str_replace('sreg.
', 'sreg_
', $_GET['openid_signed
']));
480 $num = count($arr_signed);
481 for ($i = 0; $i < $num; $i++)
483 $s = str_replace('sreg_
', 'sreg.
', $arr_signed[$i]);
484 $c = $_GET['openid_
'.$arr_signed[$i]];
486 $params['openid.
'.$s] = urlencode($c);
489 $params['openid.mode
'] = "check_authentication";
491 $openid_server = $this->GetOpenIDServer();
492 if ($openid_server == false)
496 $response = $this->CURL_Request($openid_server, 'POST
', $params);
497 $data = $this->splitResponse($response);
498 if ($data['is_valid
'] == "true")
515 public function sendDiscoveryRequestToGetXRDS($url = '')
519 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php
';
520 if (empty($url)) $url = $conf->global->MAIN_AUTHENTICATION_OPENID_URL;
524 $addheaders = array('Accept: application/xrds+xml
');
525 $response = getURLContent($url, 'GET
', '', 1, $addheaders);
526 /* response should like this:
527 <?xml version="1.0" encoding="UTF-8"?>
528 <xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
530 <Service priority="0">
531 <Type>http://specs.openid.net/auth/2.0/server</Type>
532 <Type>http://openid.net/srv/ax/1.0</Type>
534 <URI>https://www.google.com/accounts/o8/ud</URI>
539 $content = $response['content
'];
542 if (preg_match('/
'.preg_quote('<URI>
', '/
').'(.*)
'.preg_quote('</URI>
', '/
').'/is
', $content, $reg))
549 $this->ErrorStore('OPENID_NOSERVERSFOUND
');
553 $this->SetOpenIDServer($server);
SetOptionalFields($a)
SetOptionalFields.
sendDiscoveryRequestToGetXRDS($url= '')
Get XRDS response and set possible servers.
GetOpenIDServer($url= '')
Get openid server.
SetApprovedURL($a)
SetApprovedURL.
SetOpenIDServer($a)
SetOpenIDServer.
GetIdentity()
GetIdentity.
HTML2OpenIDServer($content)
HTML2OpenIDServer.
foreach($object->fields as $key=> $val) if(is_array($extrafields->attributes[$object->table_element]['label'])&&count($extrafields->attributes[$object->table_element]['label']) > 0) $object fields
SetIdentity($a)
SetIdentity.
getURLContent($url, $postorget= 'GET', $param= '', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0)
Function to get a content from an URL (use proxy if proxy defined).
GetRedirectURL()
GetRedirectURL.
ErrorStore($code, $desc=null)
ErrorStore.
SetRequiredFields($a)
SetRequiredFields.
SetCancelURL($a)
SetOpenIDServer.
SetTrustRoot($a)
SetOpenIDServer.
CURL_Request($url, $method="GET", $params="")
CURL_Request.
OpenID_Standarize($openid_identity=null)
OpenID_Standarize.
FSOCK_Request($url, $method="GET", $params="")
FSOCK_Request.
splitResponse($response)
splitResponse
GetError()
SetOpenIDServer.
__construct()
Constructor.