34 public $openid_url_identity;
38 public $URLs = array();
42 public $error = array();
46 public $fields = array(
47 'required' => array(),
48 'optional' => array(),
56 if (!function_exists(
'curl_exec')) {
57 die(
'Error: Class SimpleOpenID requires curl extension to work');
71 $this->URLs[
'openid_server'] = $a;
84 $this->URLs[
'trust_root'] = $a;
97 $this->URLs[
'cancel'] = $a;
110 $this->URLs[
'approved'] = $a;
124 $this->fields[
'required'] = $a;
126 $this->fields[
'required'][] = $a;
141 $this->fields[
'optional'] = $a;
143 $this->fields[
'optional'][] = $a;
158 if ((stripos($a,
'http://') ===
false)
159 && (stripos($a,
'https://') ===
false)) {
175 $this->openid_url_identity = $a;
188 return $this->openid_url_identity;
201 return array(
'code' => $e[0],
'description' => $e[1]);
216 $errs[
'OPENID_NOSERVERSFOUND'] =
'Cannot find OpenID Server TAG on Identity page.';
218 $desc = $errs[$code];
220 $this->error = array($code, $desc);
232 if (count($this->error) > 0) {
248 $response = explode(
"\n", $response);
249 foreach ($response as $line) {
252 list($key, $value) = explode(
":", $line, 2);
253 $r[trim($key)] = trim($value);
269 if ($openid_identity ===
null) {
270 $openid_identity = $this->openid_url_identity;
273 $u = parse_url(strtolower(trim($openid_identity)));
275 if (!isset($u[
'path']) || ($u[
'path'] ==
'/')) {
278 if (substr($u[
'path'], -1, 1) ==
'/') {
279 $u[
'path'] = substr($u[
'path'], 0, strlen($u[
'path']) - 1);
281 if (isset($u[
'query'])) {
282 return $u[
'host'].$u[
'path'].
'?'.$u[
'query'];
284 return $u[
'host'].$u[
'path'];
297 if (!is_array($arr)) {
301 foreach ($arr as $key => $value) {
302 $query .= $key.
"=".$value.
"&";
319 $fp = fsockopen(
"ssl://www.myopenid.com", 443, $errno, $errstr, 3);
321 $this->
ErrorStore(
'OPENID_SOCKETERROR', $errstr);
324 $request = $method.
" /server HTTP/1.0\r\n";
325 $request .=
"User-Agent: Dolibarr\r\n";
326 $request .=
"Connection: close\r\n\r\n";
327 fwrite($fp, $request);
328 stream_set_timeout($fp, 4);
329 $res = fread($fp, 2000);
330 $info = stream_get_meta_data($fp);
333 if ($info[
'timed_out']) {
357 preg_match_all(
'/<link[^>]*rel=[\'"]openid.server[\'"][^>]*href=[\'"]([^\'"]+)[\'"][^>]*\/?>/i', $content, $matches1);
358 preg_match_all(
'/<link[^>]*href=\'"([^\'"]+)[\'"][^>]*rel=[\'"]openid.server[\'"][^>]*\/?>/i', $content, $matches2);
359 $servers = array_merge($matches1[1], $matches2[1]);
361 preg_match_all(
'/<link[^>]*rel=[\'"]openid.delegate[\'"][^>]*href=[\'"]([^\'"]+)[\'"][^>]*\/?>/i', $content, $matches1);
363 preg_match_all(
'/<link[^>]*href=[\'"]([^\'"]+)[\'"][^>]*rel=[\'"]openid.delegate[\'"][^>]*\/?>/i', $content, $matches2);
365 $delegates = array_merge($matches1[1], $matches2[1]);
367 $ret = array($servers, $delegates);
384 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
389 $response =
getURLContent($url,
'GET',
'', 1, array(), array(
'http',
'https'));
392 if (count($servers) == 0) {
396 if (isset($delegates[0])
397 && ($delegates[0] !=
"")) {
414 $params[
'openid.return_to'] = urlencode($this->URLs[
'approved']);
415 $params[
'openid.mode'] =
'checkid_setup';
416 $params[
'openid.identity'] = urlencode($this->openid_url_identity);
417 $params[
'openid.trust_root'] = urlencode($this->URLs[
'trust_root']);
419 if (isset($this->fields[
'required'])
420 && (count($this->fields[
'required']) > 0)) {
421 $params[
'openid.sreg.required'] = implode(
',', $this->fields[
'required']);
423 if (isset($this->fields[
'optional'])
424 && (count($this->fields[
'optional']) > 0)) {
425 $params[
'openid.sreg.optional'] = implode(
',', $this->fields[
'optional']);
427 return $this->URLs[
'openid_server'].
"?".$this->
array2url($params);
440 if (headers_sent()) {
441 echo
'<script nonce="'.getNonce().
'" type="text/javascript">window.location=\'';
444 } else { // Default Header Redirect
445 header('Location:
'.$redirect_to);
454 public function validateWithServer()
457 'openid.assoc_handle
' => urlencode(GETPOST('openid_assoc_handle
')),
458 'openid.signed
' => urlencode(GETPOST('openid_signed
')),
459 'openid.sig
' => urlencode(GETPOST('openid_sig
'))
461 // Send only required parameters to confirm validity
462 $arr_signed = explode(",", str_replace('sreg.
', 'sreg_
', GETPOST('openid_signed
')));
463 $num = count($arr_signed);
464 for ($i = 0; $i < $num; $i++) {
465 $s = str_replace('sreg_
', 'sreg.
', $arr_signed[$i]);
466 $c = GETPOST('openid_
'.$arr_signed[$i]);
468 $params['openid.
'.$s] = urlencode($c);
471 $params['openid.mode
'] = "check_authentication";
473 $openid_server = $this->GetOpenIDServer();
474 if ($openid_server == false) {
478 if (is_array($params)) {
479 $params = $this->array2url($params);
482 $result = getURLContent($openid_server, 'POST
', $params);
484 $response = $result['content
'];
486 $data = $this->splitResponse($response);
487 if ($data['is_valid
'] == "true") {
503 public function sendDiscoveryRequestToGetXRDS($url = '
')
507 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php
';
509 $url = getDolGlobalString('MAIN_AUTHENTICATION_OPENID_URL
');
514 $addheaders = array('Accept: application/xrds+xml
');
515 $response = getURLContent($url, 'GET
', '', 1, $addheaders, array('http
', 'https
'), 0);
516 /* response should like this:
517 <?xml version="1.0" encoding="UTF-8"?>
518 <xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
520 <Service priority="0">
521 <Type>http://specs.openid.net/auth/2.0/server</Type>
522 <Type>http://openid.net/srv/ax/1.0</Type>
524 <URI>https://www.google.com/accounts/o8/ud</URI>
529 $content = $response['content
'];
532 if (preg_match('/
'.preg_quote('<URI>
', '/
').'(.*)
'.preg_quote('</URI>
', '/
').'/is
', $content, $reg)) {
536 if (empty($server)) {
537 $this->ErrorStore('OPENID_NOSERVERSFOUND
');
541 $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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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).
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...