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')) {
43 die(
'Error: Class SimpleOpenID requires curl extension to work');
57 $this->URLs[
'openid_server'] = $a;
70 $this->URLs[
'trust_root'] = $a;
83 $this->URLs[
'cancel'] = $a;
96 $this->URLs[
'approved'] = $a;
110 $this->fields[
'required'] = $a;
112 $this->fields[
'required'][] = $a;
127 $this->fields[
'optional'] = $a;
129 $this->fields[
'optional'][] = $a;
144 if ((stripos($a,
'http://') ===
false)
145 && (stripos($a,
'https://') ===
false)) {
161 $this->openid_url_identity = $a;
174 return $this->openid_url_identity;
187 return array(
'code'=>$e[0],
'description'=>$e[1]);
201 $errs[
'OPENID_NOSERVERSFOUND'] =
'Cannot find OpenID Server TAG on Identity page.';
203 $desc = $errs[$code];
205 $this->error = array($code, $desc);
217 if (count($this->error) > 0) {
233 $response = explode(
"\n", $response);
234 foreach ($response as $line) {
237 list($key, $value) = explode(
":", $line, 2);
238 $r[trim($key)] = trim($value);
254 if ($openid_identity ===
null) {
255 $openid_identity = $this->openid_url_identity;
258 $u = parse_url(strtolower(trim($openid_identity)));
260 if (!isset($u[
'path']) || ($u[
'path'] ==
'/')) {
263 if (substr($u[
'path'], -1, 1) ==
'/') {
264 $u[
'path'] = substr($u[
'path'], 0, strlen($u[
'path']) - 1);
266 if (isset($u[
'query'])) {
267 return $u[
'host'].$u[
'path'].
'?'.$u[
'query'];
269 return $u[
'host'].$u[
'path'];
282 if (!is_array($arr)) {
286 foreach ($arr as $key => $value) {
287 $query .= $key.
"=".$value.
"&";
304 $fp = fsockopen(
"ssl://www.myopenid.com", 443, $errno, $errstr, 3);
306 $this->
ErrorStore(
'OPENID_SOCKETERROR', $errstr);
309 $request = $method.
" /server HTTP/1.0\r\n";
310 $request .=
"User-Agent: Dolibarr\r\n";
311 $request .=
"Connection: close\r\n\r\n";
312 fwrite($fp, $request);
313 stream_set_timeout($fp, 4);
314 $res = fread($fp, 2000);
315 $info = stream_get_meta_data($fp);
318 if ($info[
'timed_out']) {
338 $matches1 = array(); $matches2 = array();
341 preg_match_all(
'/<link[^>]*rel=[\'"]openid.server[\'"][^>]*href=[\'"]([^\'"]+)[\'"][^>]*\/?>/i', $content, $matches1);
342 preg_match_all(
'/<link[^>]*href=\'"([^\'"]+)[\'"][^>]*rel=[\'"]openid.server[\'"][^>]*\/?>/i', $content, $matches2);
343 $servers = array_merge($matches1[1], $matches2[1]);
345 preg_match_all(
'/<link[^>]*rel=[\'"]openid.delegate[\'"][^>]*href=[\'"]([^\'"]+)[\'"][^>]*\/?>/i', $content, $matches1);
347 preg_match_all(
'/<link[^>]*href=[\'"]([^\'"]+)[\'"][^>]*rel=[\'"]openid.delegate[\'"][^>]*\/?>/i', $content, $matches2);
349 $delegates = array_merge($matches1[1], $matches2[1]);
351 $ret = array($servers, $delegates);
368 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
370 $url = $conf->global->MAIN_AUTHENTICATION_OPENID_URL;
373 $response =
getURLContent($url,
'GET',
'', 1, array(), array(
'http',
'https'));
376 if (count($servers) == 0) {
380 if (isset($delegates[0])
381 && ($delegates[0] !=
"")) {
398 $params[
'openid.return_to'] = urlencode($this->URLs[
'approved']);
399 $params[
'openid.mode'] =
'checkid_setup';
400 $params[
'openid.identity'] = urlencode($this->openid_url_identity);
401 $params[
'openid.trust_root'] = urlencode($this->URLs[
'trust_root']);
403 if (isset($this->fields[
'required'])
404 && (count($this->fields[
'required']) > 0)) {
405 $params[
'openid.sreg.required'] = implode(
',', $this->fields[
'required']);
407 if (isset($this->fields[
'optional'])
408 && (count($this->fields[
'optional']) > 0)) {
409 $params[
'openid.sreg.optional'] = implode(
',', $this->fields[
'optional']);
411 return $this->URLs[
'openid_server'].
"?".$this->
array2url($params);
424 if (headers_sent()) {
425 echo
'<script nonce="'.getNonce().
'" type="text/javascript">window.location=\'';
428 } else { // Default Header Redirect
429 header('Location:
'.$redirect_to);
433 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
439 public function ValidateWithServer()
443 'openid.assoc_handle
' => urlencode($_GET['openid_assoc_handle
']),
444 'openid.signed
' => urlencode($_GET['openid_signed
']),
445 'openid.sig
' => urlencode($_GET['openid_sig
'])
447 // Send only required parameters to confirm validity
448 $arr_signed = explode(",", str_replace('sreg.
', 'sreg_
', $_GET['openid_signed
']));
449 $num = count($arr_signed);
450 for ($i = 0; $i < $num; $i++) {
451 $s = str_replace('sreg_
', 'sreg.
', $arr_signed[$i]);
452 $c = $_GET['openid_
'.$arr_signed[$i]];
454 $params['openid.
'.$s] = urlencode($c);
457 $params['openid.mode
'] = "check_authentication";
459 $openid_server = $this->GetOpenIDServer();
460 if ($openid_server == false) {
464 if (is_array($params)) {
465 $params = $this->array2url($params);
468 $result = getURLContent($openid_server, 'POST
', $params);
470 $response = $result['content
'];
472 $data = $this->splitResponse($response);
473 if ($data['is_valid
'] == "true") {
489 public function sendDiscoveryRequestToGetXRDS($url = '
')
493 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php
';
495 $url = $conf->global->MAIN_AUTHENTICATION_OPENID_URL;
500 $addheaders = array('Accept: application/xrds+xml
');
501 $response = getURLContent($url, 'GET
', '', 1, $addheaders, array('http
', 'https
'), 0);
502 /* response should like this:
503 <?xml version="1.0" encoding="UTF-8"?>
504 <xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
506 <Service priority="0">
507 <Type>http://specs.openid.net/auth/2.0/server</Type>
508 <Type>http://openid.net/srv/ax/1.0</Type>
510 <URI>https://www.google.com/accounts/o8/ud</URI>
515 $content = $response['content
'];
518 if (preg_match('/
'.preg_quote('<URI>
', '/
').'(.*)
'.preg_quote('</URI>
', '/
').'/is
', $content, $reg)) {
522 if (empty($server)) {
523 $this->ErrorStore('OPENID_NOSERVERSFOUND
');
527 $this->SetOpenIDServer($server);
GetRedirectURL()
GetRedirectURL.
GetOpenIDServer($url='')
Get openid server.
SetApprovedURL($a)
SetApprovedURL.
__construct()
Constructor.
OpenID_Standarize($openid_identity=null)
OpenID_Standarize.
SetOptionalFields($a)
SetOptionalFields.
HTML2OpenIDServer($content)
HTML2OpenIDServer.
splitResponse($response)
splitResponse
SetCancelURL($a)
SetOpenIDServer.
GetError()
SetOpenIDServer.
SetTrustRoot($a)
SetOpenIDServer.
SetIdentity($a)
SetIdentity.
FSOCK_Request($url, $method="GET", $params="")
FSOCK_Request.
ErrorStore($code, $desc=null)
ErrorStore.
SetRequiredFields($a)
SetRequiredFields.
SetOpenIDServer($a)
SetOpenIDServer.
GetIdentity()
GetIdentity.
sendDiscoveryRequestToGetXRDS($url='')
Get XRDS response and set possible servers.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).