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']) {
342 preg_match_all(
'/<link[^>]*rel=[\'"]openid.server[\'"][^>]*href=[\'"]([^\'"]+)[\'"][^>]*\/?>/i', $content, $matches1);
343 preg_match_all(
'/<link[^>]*href=\'"([^\'"]+)[\'"][^>]*rel=[\'"]openid.server[\'"][^>]*\/?>/i', $content, $matches2);
344 $servers = array_merge($matches1[1], $matches2[1]);
346 preg_match_all(
'/<link[^>]*rel=[\'"]openid.delegate[\'"][^>]*href=[\'"]([^\'"]+)[\'"][^>]*\/?>/i', $content, $matches1);
348 preg_match_all(
'/<link[^>]*href=[\'"]([^\'"]+)[\'"][^>]*rel=[\'"]openid.delegate[\'"][^>]*\/?>/i', $content, $matches2);
350 $delegates = array_merge($matches1[1], $matches2[1]);
352 $ret = array($servers, $delegates);
369 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
371 $url = $conf->global->MAIN_AUTHENTICATION_OPENID_URL;
374 $response =
getURLContent($url,
'GET',
'', 1, array(), array(
'http',
'https'));
377 if (count($servers) == 0) {
381 if (isset($delegates[0])
382 && ($delegates[0] !=
"")) {
399 $params[
'openid.return_to'] = urlencode($this->URLs[
'approved']);
400 $params[
'openid.mode'] =
'checkid_setup';
401 $params[
'openid.identity'] = urlencode($this->openid_url_identity);
402 $params[
'openid.trust_root'] = urlencode($this->URLs[
'trust_root']);
404 if (isset($this->fields[
'required'])
405 && (count($this->fields[
'required']) > 0)) {
406 $params[
'openid.sreg.required'] = implode(
',', $this->fields[
'required']);
408 if (isset($this->fields[
'optional'])
409 && (count($this->fields[
'optional']) > 0)) {
410 $params[
'openid.sreg.optional'] = implode(
',', $this->fields[
'optional']);
412 return $this->URLs[
'openid_server'].
"?".$this->
array2url($params);
425 if (headers_sent()) {
426 echo
'<script nonce="'.getNonce().
'" type="text/javascript">window.location=\'';
429 } else { // Default Header Redirect
430 header('Location:
'.$redirect_to);
434 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
440 public function ValidateWithServer()
444 'openid.assoc_handle
' => urlencode($_GET['openid_assoc_handle
']),
445 'openid.signed
' => urlencode($_GET['openid_signed
']),
446 'openid.sig
' => urlencode($_GET['openid_sig
'])
448 // Send only required parameters to confirm validity
449 $arr_signed = explode(",", str_replace('sreg.
', 'sreg_
', $_GET['openid_signed
']));
450 $num = count($arr_signed);
451 for ($i = 0; $i < $num; $i++) {
452 $s = str_replace('sreg_
', 'sreg.
', $arr_signed[$i]);
453 $c = $_GET['openid_
'.$arr_signed[$i]];
455 $params['openid.
'.$s] = urlencode($c);
458 $params['openid.mode
'] = "check_authentication";
460 $openid_server = $this->GetOpenIDServer();
461 if ($openid_server == false) {
465 if (is_array($params)) {
466 $params = $this->array2url($params);
469 $result = getURLContent($openid_server, 'POST
', $params);
471 $response = $result['content
'];
473 $data = $this->splitResponse($response);
474 if ($data['is_valid
'] == "true") {
490 public function sendDiscoveryRequestToGetXRDS($url = '
')
494 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php
';
496 $url = $conf->global->MAIN_AUTHENTICATION_OPENID_URL;
501 $addheaders = array('Accept: application/xrds+xml
');
502 $response = getURLContent($url, 'GET
', '', 1, $addheaders, array('http
', 'https
'), 0);
503 /* response should like this:
504 <?xml version="1.0" encoding="UTF-8"?>
505 <xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
507 <Service priority="0">
508 <Type>http://specs.openid.net/auth/2.0/server</Type>
509 <Type>http://openid.net/srv/ax/1.0</Type>
511 <URI>https://www.google.com/accounts/o8/ud</URI>
516 $content = $response['content
'];
519 if (preg_match('/
'.preg_quote('<URI>
', '/
').'(.*)
'.preg_quote('</URI>
', '/
').'/is
', $content, $reg)) {
523 if (empty($server)) {
524 $this->ErrorStore('OPENID_NOSERVERSFOUND
');
528 $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).