PageRenderTime 47ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/01.Source/01.CORE/includes/class/openid.class.php

http://creative-portal.googlecode.com/
PHP | 618 lines | 428 code | 60 blank | 130 comment | 82 complexity | 9c262a8c5cffedc2f76f57ad6dac7782 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2010 VINADES.,JSC. All rights reserved
  6. * @Createdate 20/7/2010, 4:53
  7. */
  8. /**
  9. * This class provides a simple interface for OpenID (1.1 and 2.0) authentication.
  10. * Supports Yadis discovery.
  11. * The authentication process is stateless/dumb.
  12. *
  13. * Usage:
  14. * Sign-on with OpenID is a two step process:
  15. * Step one is authentication with the provider:
  16. * <code>
  17. * $openid = new LightOpenID;
  18. * $openid->identity = 'ID supplied by user';
  19. * header('Location: ' . $openid->authUrl());
  20. * </code>
  21. * The provider then sends various parameters via GET, one of them is openid_mode.
  22. * Step two is verification:
  23. * <code>
  24. * if ($_GET['openid_mode']) {
  25. * $openid = new LightOpenID;
  26. * echo $openid->validate() ? 'Logged in.' : 'Failed';
  27. * }
  28. * </code>
  29. *
  30. * Optionally, you can set $returnUrl and $realm (or $trustRoot, which is an alias).
  31. * The default values for those are:
  32. * $openid->realm = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'];
  33. * $openid->returnUrl = $openid->realm . $_SERVER['REQUEST_URI'];
  34. * If you don't know their meaning, refer to any openid tutorial, or specification. Or just guess.
  35. *
  36. * AX and SREG extensions are supported.
  37. * To use them, specify $openid->required and/or $openid->optional.
  38. * These are arrays, with values being AX schema paths (the 'path' part of the URL).
  39. * For example:
  40. * $openid->required = array('namePerson/friendly', 'contact/email');
  41. * $openid->optional = array('namePerson/first');
  42. * If the server supports only SREG or OpenID 1.1, these are automaticaly
  43. * mapped to SREG names, so that user doesn't have to know anything about the server.
  44. *
  45. * To get the values, use $openid->getAttributes().
  46. *
  47. *
  48. * The library depends on curl, and requires PHP 5.
  49. * @author Mewp
  50. * @copyright Copyright (c) 2010, Mewp
  51. * @license http://www.opensource.org/licenses/mit-license.php MIT
  52. */
  53. class LightOpenID
  54. {
  55. public $returnUrl, $required = array(), $optional = array();
  56. private $identity, $claimed_id;
  57. protected $server, $version, $trustRoot, $aliases, $identifier_select = false, $ax = false, $sreg = false;
  58. protected static $ax_to_sreg = array( //
  59. 'namePerson/friendly' => 'nickname', //
  60. 'contact/email' => 'email', //
  61. 'namePerson' => 'fullname', //
  62. 'birthDate' => 'dob', //
  63. 'person/gender' => 'gender', //
  64. 'contact/postalCode/home' => 'postcode', //
  65. 'contact/country/home' => 'country', //
  66. 'pref/language' => 'language', //
  67. 'pref/timezone' => 'timezone', //
  68. 'namePerson/first' => 'firstname', //google - NV
  69. 'namePerson/last' => 'lastname' //google - NV
  70. );
  71. function __construct ( )
  72. {
  73. //$this->trustRoot = ( ! empty( $_SERVER['HTTPS'] ) ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'];
  74. $this->trustRoot = ( ( isset( $_SERVER['HTTPS'] ) and strtolower( $_SERVER['HTTPS'] ) == 'on' ) ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'];
  75. $this->returnUrl = $this->trustRoot . $_SERVER['REQUEST_URI'];
  76. if ( ! function_exists( 'curl_exec' ) )
  77. {
  78. trigger_error( 'Curl extension is required.', 256 );
  79. }
  80. }
  81. function __set ( $name, $value )
  82. {
  83. switch ( $name )
  84. {
  85. case 'identity':
  86. if ( strlen( $value = trim( $value ) ) )
  87. {
  88. if ( preg_match( '#^xri:/*#i', $value, $m ) )
  89. {
  90. $value = substr( $value, strlen( $m[0] ) );
  91. }
  92. elseif ( ! preg_match( '/^(?:[=@+\$!\(]|https?:)/i', $value ) )
  93. {
  94. $value = "http://$value";
  95. }
  96. if ( preg_match( '#^https?://[^/]+$#i', $value, $m ) )
  97. {
  98. $value .= '/';
  99. }
  100. }
  101. $this->$name = $this->claimed_id = $value;
  102. break;
  103. case 'trustRoot':
  104. case 'realm':
  105. $this->trustRoot = trim( $value );
  106. }
  107. }
  108. function __get ( $name )
  109. {
  110. switch ( $name )
  111. {
  112. case 'identity':
  113. # We return claimed_id instead of identity,
  114. # because the developer should see the claimed identifier,
  115. # i.e. what he set as identity, not the op-local identifier (which is what we verify)
  116. return $this->claimed_id;
  117. case 'trustRoot':
  118. case 'realm':
  119. return $this->trustRoot;
  120. }
  121. }
  122. protected function request ( $url, $method = 'GET', $params = array() )
  123. {
  124. $params = http_build_query( $params );
  125. $curl = curl_init( $url . ( $method == 'GET' && $params ? '?' . $params : '' ) );
  126. $safe_mode = ( ini_get( 'safe_mode' ) == '1' || strtolower( ini_get( 'safe_mode' ) ) == 'on' ) ? 1 : 0;
  127. $open_basedir = ( ini_get( 'open_basedir' ) == '1' || strtolower( ini_get( 'open_basedir' ) ) == 'on' ) ? 1 : 0;
  128. if ( ! $safe_mode and $open_basedir )
  129. {
  130. curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
  131. }
  132. curl_setopt( $curl, CURLOPT_HEADER, false );
  133. curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
  134. curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
  135. if ( $method == 'POST' )
  136. {
  137. curl_setopt( $curl, CURLOPT_POST, true );
  138. curl_setopt( $curl, CURLOPT_POSTFIELDS, $params );
  139. }
  140. elseif ( $method == 'HEAD' )
  141. {
  142. curl_setopt( $curl, CURLOPT_HEADER, true );
  143. curl_setopt( $curl, CURLOPT_NOBODY, true );
  144. }
  145. else
  146. {
  147. curl_setopt( $curl, CURLOPT_HTTPGET, true );
  148. }
  149. curl_setopt( $curl, CURLOPT_TIMEOUT, 30 );
  150. $response = curl_exec( $curl );
  151. if ( curl_errno( $curl ) )
  152. {
  153. trigger_error( 'Curl error: ' . curl_error( $curl ), 256 );
  154. }
  155. return $response;
  156. }
  157. protected function build_url ( $url, $parts )
  158. {
  159. if ( isset( $url['query'], $parts['query'] ) )
  160. {
  161. $parts['query'] = $url['query'] . '&' . $parts['query'];
  162. }
  163. $url = $parts + $url;
  164. $url = $url['scheme'] . '://' . ( empty( $url['username'] ) ? '' : ( empty( $url['password'] ) ? "{$url['username']}@" : "{$url['username']}:{$url['password']}@" ) ) . $url['host'] . ( empty( $url['port'] ) ? '' : ":{$url['port']}" ) . ( empty( $url['path'] ) ? '' : $url['path'] ) . ( empty( $url['query'] ) ? '' : "?{$url['query']}" ) . ( empty( $url['fragment'] ) ? '' : ":{$url['fragment']}" );
  165. return $url;
  166. }
  167. /**
  168. * Helper function used to scan for <meta>/<link> tags and extract information
  169. * from them
  170. */
  171. protected function htmlTag ( $content, $tag, $attrName, $attrValue, $valueName )
  172. {
  173. preg_match_all( "#<{$tag}[^>]*$attrName=['\"].*?$attrValue.*?['\"][^>]*$valueName=['\"](.+?)['\"][^>]*/?>#i", $content, $matches1 );
  174. preg_match_all( "#<{$tag}[^>]*$valueName=['\"](.+?)['\"][^>]*$attrName=['\"].*?$attrValue.*?['\"][^>]*/?>#i", $content, $matches2 );
  175. $result = array_merge( $matches1[1], $matches2[1] );
  176. return empty( $result ) ? false : $result[0];
  177. }
  178. /**
  179. * Performs Yadis and HTML discovery. Normally not used.
  180. * @param $url Identity URL.
  181. * @return String OP Endpoint (i.e. OpenID provider address).
  182. * @throws ErrorException
  183. */
  184. function discover ( $url )
  185. {
  186. if ( ! $url ) throw new ErrorException( 'No identity supplied.' );
  187. # Use xri.net proxy to resolve i-name identities
  188. if ( ! preg_match( '#^https?:#', $url ) )
  189. {
  190. $url = "https://xri.net/$url";
  191. }
  192. # We save the original url in case of Yadis discovery failure.
  193. # It can happen when we'll be lead to an XRDS document
  194. # which does not have any OpenID2 services.
  195. $originalUrl = $url;
  196. # A flag to disable yadis discovery in case of failure in headers.
  197. $yadis = true;
  198. # We'll jump a maximum of 5 times, to avoid endless redirections.
  199. for ( $i = 0; $i < 5; $i ++ )
  200. {
  201. if ( $yadis )
  202. {
  203. $headers = explode( "\n", $this->request( $url, 'HEAD' ) );
  204. $next = false;
  205. foreach ( $headers as $header )
  206. {
  207. if ( preg_match( '#X-XRDS-Location\s*:\s*(.*)#', $header, $m ) )
  208. {
  209. $url = $this->build_url( parse_url( $url ), parse_url( trim( $m[1] ) ) );
  210. $next = true;
  211. }
  212. if ( preg_match( '#Content-Type\s*:\s*application/xrds\+xml#i', $header ) )
  213. {
  214. # Found an XRDS document, now let's find the server, and optionally delegate.
  215. $content = $this->request( $url, 'GET' );
  216. # OpenID 2
  217. # We ignore it for MyOpenID, as it breaks sreg if using OpenID 2.0
  218. $ns = preg_quote( 'http://specs.openid.net/auth/2.0/' );
  219. if ( preg_match( '#<Service.*?>(.*)<Type>\s*' . $ns . '(.*?)\s*</Type>(.*)</Service>#s', $content, $m ) )
  220. {
  221. $content = ' ' . $m[1] . $m[3]; # The space is added, so that strpos doesn't return 0.
  222. if ( $m[2] == 'server' ) $this->identifier_select = true;
  223. preg_match( '#<URI.*?>(.*)</URI>#', $content, $server );
  224. preg_match( '#<(Local|Canonical)ID>(.*)</\1ID>#', $content, $delegate );
  225. if ( empty( $server ) )
  226. {
  227. return false;
  228. }
  229. # Does the server advertise support for either AX or SREG?
  230. $this->ax = ( bool )strpos( $content, '<Type>http://openid.net/srv/ax/1.0</Type>' );
  231. $this->sreg = strpos( $content, '<Type>http://openid.net/sreg/1.0</Type>' ) || strpos( $content, '<Type>http://openid.net/extensions/sreg/1.1</Type>' );
  232. $server = $server[1];
  233. if ( isset( $delegate[2] ) ) $this->identity = trim( $delegate[2] );
  234. $this->version = 2;
  235. $this->server = $server;
  236. return $server;
  237. }
  238. # OpenID 1.1
  239. $ns = preg_quote( 'http://openid.net/signon/1.1' );
  240. if ( preg_match( '#<Service.*?>(.*)<Type>\s*' . $ns . '\s*</Type>(.*)</Service>#s', $content, $m ) )
  241. {
  242. $content = ' ' . $m[1] . $m[2];
  243. preg_match( '#<URI.*?>(.*)</URI>#', $content, $server );
  244. preg_match( '#<.*?Delegate>(.*)</.*?Delegate>#', $content, $delegate );
  245. if ( empty( $server ) )
  246. {
  247. return false;
  248. }
  249. # AX can be used only with OpenID 2.0, so checking only SREG
  250. $this->sreg = strpos( $content, '<Type>http://openid.net/sreg/1.0</Type>' ) || strpos( $content, '<Type>http://openid.net/extensions/sreg/1.1</Type>' );
  251. $server = $server[1];
  252. if ( isset( $delegate[1] ) ) $this->identity = $delegate[1];
  253. $this->version = 1;
  254. $this->server = $server;
  255. return $server;
  256. }
  257. $next = true;
  258. $yadis = false;
  259. $url = $originalUrl;
  260. $content = null;
  261. break;
  262. }
  263. }
  264. if ( $next ) continue;
  265. # There are no relevant information in headers, so we search the body.
  266. $content = $this->request( $url, 'GET' );
  267. if ( $location = $this->htmlTag( $content, 'meta', 'http-equiv', 'X-XRDS-Location', 'value' ) )
  268. {
  269. $url = $this->build_url( parse_url( $url ), parse_url( $location ) );
  270. continue;
  271. }
  272. }
  273. if ( ! $content ) $content = $this->request( $url, 'GET' );
  274. # At this point, the YADIS Discovery has failed, so we'll switch
  275. # to openid2 HTML discovery, then fallback to openid 1.1 discovery.
  276. $server = $this->htmlTag( $content, 'link', 'rel', 'openid2.provider', 'href' );
  277. $delegate = $this->htmlTag( $content, 'link', 'rel', 'openid2.local_id', 'href' );
  278. $this->version = 2;
  279. if ( ! $server )
  280. {
  281. # The same with openid 1.1
  282. $server = $this->htmlTag( $content, 'link', 'rel', 'openid.server', 'href' );
  283. $delegate = $this->htmlTag( $content, 'link', 'rel', 'openid.delegate', 'href' );
  284. $this->version = 1;
  285. }
  286. if ( $server )
  287. {
  288. # We found an OpenID2 OP Endpoint
  289. if ( $delegate )
  290. {
  291. # We have also found an OP-Local ID.
  292. $this->identity = $delegate;
  293. }
  294. $this->server = $server;
  295. return $server;
  296. }
  297. trigger_error( 'No servers found!', 256 );
  298. }
  299. trigger_error( 'Endless redirection!', 256 );
  300. }
  301. protected function sregParams ( )
  302. {
  303. $params = array();
  304. # We always use SREG 1.1, even if the server is advertising only support for 1.0.
  305. # That's because it's fully backwards compatibile with 1.0, and some providers
  306. # advertise 1.0 even if they accept only 1.1. One such provider is myopenid.com
  307. $params['openid.ns.sreg'] = 'http://openid.net/extensions/sreg/1.1';
  308. if ( $this->required )
  309. {
  310. $params['openid.sreg.required'] = array();
  311. foreach ( $this->required as $required )
  312. {
  313. if ( ! isset( self::$ax_to_sreg[$required] ) ) continue;
  314. $params['openid.sreg.required'][] = self::$ax_to_sreg[$required];
  315. }
  316. $params['openid.sreg.required'] = implode( ',', $params['openid.sreg.required'] );
  317. }
  318. if ( $this->optional )
  319. {
  320. $params['openid.sreg.optional'] = array();
  321. foreach ( $this->optional as $optional )
  322. {
  323. if ( ! isset( self::$ax_to_sreg[$optional] ) ) continue;
  324. $params['openid.sreg.optional'][] = self::$ax_to_sreg[$optional];
  325. }
  326. $params['openid.sreg.optional'] = implode( ',', $params['openid.sreg.optional'] );
  327. }
  328. return $params;
  329. }
  330. protected function axParams ( )
  331. {
  332. $params = array();
  333. if ( $this->required || $this->optional )
  334. {
  335. $params['openid.ns.ax'] = 'http://openid.net/srv/ax/1.0';
  336. $params['openid.ax.mode'] = 'fetch_request';
  337. $this->aliases = array();
  338. $counts = array();
  339. $required = array();
  340. $optional = array();
  341. foreach ( array(
  342. 'required', 'optional'
  343. ) as $type )
  344. {
  345. foreach ( $this->$type as $alias => $field )
  346. {
  347. if ( is_int( $alias ) ) $alias = strtr( $field, '/', '_' );
  348. $this->aliases[$alias] = 'http://axschema.org/' . $field;
  349. if ( empty( $counts[$alias] ) ) $counts[$alias] = 0;
  350. $counts[$alias] += 1;
  351. ${$type}[] = $alias;
  352. }
  353. }
  354. foreach ( $this->aliases as $alias => $ns )
  355. {
  356. $params['openid.ax.type.' . $alias] = $ns;
  357. }
  358. foreach ( $counts as $alias => $count )
  359. {
  360. if ( $count == 1 ) continue;
  361. $params['openid.ax.count.' . $alias] = $count;
  362. }
  363. $params['openid.ax.required'] = implode( ',', $required );
  364. $params['openid.ax.if_avaiable'] = implode( ',', $optional );
  365. }
  366. return $params;
  367. }
  368. protected function authUrl_v1 ( )
  369. {
  370. $returnUrl = $this->returnUrl;
  371. # If we have an openid.delegate that is different from our claimed id,
  372. # we need to somehow preserve the claimed id between requests.
  373. # The simplest way is to just send it along with the return_to url.
  374. if ( $this->identity != $this->claimed_id )
  375. {
  376. $returnUrl .= ( strpos( $returnUrl, '?' ) ? '&' : '?' ) . 'openid.claimed_id=' . $this->claimed_id;
  377. }
  378. $params = array(
  379. 'openid.return_to' => $returnUrl, 'openid.mode' => 'checkid_setup', 'openid.identity' => $this->identity, 'openid.trust_root' => $this->trustRoot
  380. ) + $this->sregParams();
  381. return $this->build_url( parse_url( $this->server ), array(
  382. 'query' => http_build_query( $params )
  383. ) );
  384. }
  385. protected function authUrl_v2 ( $identifier_select )
  386. {
  387. $params = array(
  388. 'openid.ns' => 'http://specs.openid.net/auth/2.0', 'openid.mode' => 'checkid_setup', 'openid.return_to' => $this->returnUrl, 'openid.realm' => $this->trustRoot
  389. );
  390. if ( $this->ax )
  391. {
  392. $params += $this->axParams();
  393. }
  394. if ( $this->sreg )
  395. {
  396. $params += $this->sregParams();
  397. }
  398. if ( ! $this->ax && ! $this->sreg )
  399. {
  400. # If OP doesn't advertise either SREG, nor AX, let's send them both
  401. # in worst case we don't get anything in return.
  402. $params += $this->axParams() + $this->sregParams();
  403. }
  404. if ( $identifier_select )
  405. {
  406. $params['openid.identity'] = $params['openid.claimed_id'] = 'http://specs.openid.net/auth/2.0/identifier_select';
  407. }
  408. else
  409. {
  410. $params['openid.identity'] = $this->identity;
  411. $params['openid.claimed_id'] = $this->claimed_id;
  412. }
  413. return $this->build_url( parse_url( $this->server ), array(
  414. 'query' => http_build_query( $params )
  415. ) );
  416. }
  417. /**
  418. * Returns authentication url. Usually, you want to redirect your user to it.
  419. * @return String The authentication url.
  420. * @param String $select_identifier Whether to request OP to select identity for an user in OpenID 2. Does not affect OpenID 1.
  421. * @throws ErrorException
  422. */
  423. function authUrl ( $identifier_select = null )
  424. {
  425. if ( ! $this->server ) $this->discover( $this->identity );
  426. if ( $this->version == 2 )
  427. {
  428. if ( $identifier_select === null )
  429. {
  430. return $this->authUrl_v2( $this->identifier_select );
  431. }
  432. return $this->authUrl_v2( $identifier_select );
  433. }
  434. return $this->authUrl_v1();
  435. }
  436. /**
  437. * Performs OpenID verification with the OP.
  438. * @return Bool Whether the verification was successful.
  439. * @throws ErrorException
  440. */
  441. function validate ( )
  442. {
  443. $this->claimed_id = $_GET['openid_claimed_id'];
  444. $params = array(
  445. 'openid.assoc_handle' => $_GET['openid_assoc_handle'], 'openid.signed' => $_GET['openid_signed'], 'openid.sig' => $_GET['openid_sig']
  446. );
  447. if ( isset( $_GET['openid_op_endpoint'] ) )
  448. {
  449. # We're dealing with an OpenID 2.0 server, so let's set an ns
  450. # Even though we should know location of the endpoint,
  451. # we still need to verify it by discovery, so $server is not set here
  452. $params['openid.ns'] = 'http://specs.openid.net/auth/2.0';
  453. }
  454. $server = $this->discover( $_GET['openid_identity'] );
  455. foreach ( explode( ',', $_GET['openid_signed'] ) as $item )
  456. {
  457. # Checking whether magic_quotes_gpc is turned on, because
  458. # the function may fail if it is. For example, when fetching
  459. # AX namePerson, it might containg an apostrophe, which will be escaped.
  460. # In such case, validation would fail, since we'd send different data than OP
  461. # wants to verify. stripslashes() should solve that problem, but we can't
  462. # use it when magic_quotes is off.
  463. $value = $_GET['openid_' . str_replace( '.', '_', $item )];
  464. $params['openid.' . $item] = get_magic_quotes_gpc() ? stripslashes( $value ) : $value;
  465. }
  466. $params['openid.mode'] = 'check_authentication';
  467. $response = $this->request( $server, 'POST', $params );
  468. return preg_match( '/is_valid\s*:\s*true/i', $response );
  469. }
  470. protected function getAxAttributes ( )
  471. {
  472. $alias = null;
  473. if ( isset( $_GET['openid_ns_ax'] ) && $_GET['openid_ns_ax'] != 'http://openid.net/srv/ax/1.0' )
  474. { # It's the most likely case, so we'll check it before
  475. $alias = 'ax';
  476. }
  477. else
  478. {
  479. # 'ax' prefix is either undefined, or points to another extension,
  480. # so we search for another prefix
  481. foreach ( $_GET as $key => $val )
  482. {
  483. if ( substr( $key, 0, strlen( 'openid_ns_' ) ) == 'openid_ns_' && $val == 'http://openid.net/srv/ax/1.0' )
  484. {
  485. $alias = substr( $key, strlen( 'openid_ns_' ) );
  486. break;
  487. }
  488. }
  489. }
  490. if ( ! $alias )
  491. {
  492. # An alias for AX schema has not been found,
  493. # so there is no AX data in the OP's response
  494. return array();
  495. }
  496. foreach ( $_GET as $key => $value )
  497. {
  498. $keyMatch = 'openid_' . $alias . '_value_';
  499. if ( substr( $key, 0, strlen( $keyMatch ) ) != $keyMatch )
  500. {
  501. continue;
  502. }
  503. $key = substr( $key, strlen( $keyMatch ) );
  504. if ( ! isset( $_GET['openid_' . $alias . '_type_' . $key] ) )
  505. {
  506. # OP is breaking the spec by returning a field without
  507. # associated ns. This shouldn't happen, but it's better
  508. # to check, than cause an E_NOTICE.
  509. continue;
  510. }
  511. $key = substr( $_GET['openid_' . $alias . '_type_' . $key], strlen( 'http://axschema.org/' ) );
  512. $attributes[$key] = $value;
  513. }
  514. # Found the AX attributes, so no need to scan for SREG.
  515. return $attributes;
  516. }
  517. protected function getSregAttributes ( )
  518. {
  519. $attributes = array();
  520. $sreg_to_ax = array_flip( self::$ax_to_sreg );
  521. foreach ( $_GET as $key => $value )
  522. {
  523. $keyMatch = 'openid_sreg_';
  524. if ( substr( $key, 0, strlen( $keyMatch ) ) != $keyMatch )
  525. {
  526. continue;
  527. }
  528. $key = substr( $key, strlen( $keyMatch ) );
  529. if ( ! isset( $sreg_to_ax[$key] ) )
  530. {
  531. # The field name isn't part of the SREG spec, so we ignore it.
  532. continue;
  533. }
  534. $attributes[$sreg_to_ax[$key]] = $value;
  535. }
  536. return $attributes;
  537. }
  538. /**
  539. * Gets AX/SREG attributes provided by OP. should be used only after successful validaton.
  540. * Note that it does not guarantee that any of the required/optional parameters will be present,
  541. * or that there will be no other attributes besides those specified.
  542. * In other words. OP may provide whatever information it wants to.
  543. * * SREG names will be mapped to AX names.
  544. * * @return Array Array of attributes with keys being the AX schema names, e.g. 'contact/email'
  545. * @see http://www.axschema.org/types/
  546. */
  547. function getAttributes ( )
  548. {
  549. $attributes;
  550. if ( isset( $_GET['openid_ns'] ) && $_GET['openid_ns'] == 'http://specs.openid.net/auth/2.0' )
  551. { # OpenID 2.0
  552. # We search for both AX and SREG attributes, with AX taking precedence.
  553. return $this->getAxAttributes() + $this->getSregAttributes();
  554. }
  555. return $this->getSregAttributes();
  556. }
  557. }
  558. ?>