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]);
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) {
234 $response = explode(
"\n", $response);
235 foreach ($response as $line) {
238 list($key, $value) = explode(
":", $line, 2);
239 $r[trim($key)] = trim($value);
255 if ($openid_identity ===
null) {
256 $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']) {
343 preg_match_all(
'/<link[^>]*rel=[\'"]openid.server[\'"][^>]*href=[\'"]([^\'"]+)[\'"][^>]*\/?>/i', $content, $matches1);
344 preg_match_all(
'/<link[^>]*href=\'"([^\'"]+)[\'"][^>]*rel=[\'"]openid.server[\'"][^>]*\/?>/i', $content, $matches2);
345 $servers = array_merge($matches1[1], $matches2[1]);
347 preg_match_all(
'/<link[^>]*rel=[\'"]openid.delegate[\'"][^>]*href=[\'"]([^\'"]+)[\'"][^>]*\/?>/i', $content, $matches1);
349 preg_match_all(
'/<link[^>]*href=[\'"]([^\'"]+)[\'"][^>]*rel=[\'"]openid.delegate[\'"][^>]*\/?>/i', $content, $matches2);
351 $delegates = array_merge($matches1[1], $matches2[1]);
353 $ret = array($servers, $delegates);
370 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
375 $response =
getURLContent($url,
'GET',
'', 1, array(), array(
'http',
'https'));
378 if (count($servers) == 0) {
382 if (isset($delegates[0])
383 && ($delegates[0] !=
"")) {
400 $params[
'openid.return_to'] = urlencode($this->URLs[
'approved']);
401 $params[
'openid.mode'] =
'checkid_setup';
402 $params[
'openid.identity'] = urlencode($this->openid_url_identity);
403 $params[
'openid.trust_root'] = urlencode($this->URLs[
'trust_root']);
405 if (isset($this->fields[
'required'])
406 && (count($this->fields[
'required']) > 0)) {
407 $params[
'openid.sreg.required'] = implode(
',', $this->fields[
'required']);
409 if (isset($this->fields[
'optional'])
410 && (count($this->fields[
'optional']) > 0)) {
411 $params[
'openid.sreg.optional'] = implode(
',', $this->fields[
'optional']);
413 return $this->URLs[
'openid_server'].
"?".$this->
array2url($params);
426 if (headers_sent()) {
427 echo
'<script nonce="'.getNonce().
'" type="text/javascript">window.location=\'';
430 } else { // Default Header Redirect
431 header('Location:
'.$redirect_to);
440 public function validateWithServer()
443 'openid.assoc_handle
' => urlencode(GETPOST('openid_assoc_handle
')),
444 'openid.signed
' => urlencode(GETPOST('openid_signed
')),
445 'openid.sig
' => urlencode(GETPOST('openid_sig
'))
447 // Send only required parameters to confirm validity
448 $arr_signed = explode(",", str_replace('sreg.
', 'sreg_
', GETPOST('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 = GETPOST('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 = getDolGlobalString('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.
getDolGlobalString($key, $default='')
Return 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).