You are here

static function OAuthDiscovery::discover in Lingotek Translation 7.5

Same name and namespace in other branches
  1. 7.7 lib/oauth-php/library/OAuthDiscovery.php \OAuthDiscovery::discover()
  2. 7.2 lib/oauth-php/library/OAuthDiscovery.php \OAuthDiscovery::discover()
  3. 7.3 lib/oauth-php/library/OAuthDiscovery.php \OAuthDiscovery::discover()
  4. 7.4 lib/oauth-php/library/OAuthDiscovery.php \OAuthDiscovery::discover()
  5. 7.6 lib/oauth-php/library/OAuthDiscovery.php \OAuthDiscovery::discover()

* Return a description how we can do a consumer allocation. Prefers static allocation if * possible. If static allocation is possible * * See also: http://oauth.net/discovery/#consumer_identity_types * *

Parameters

string uri: * @return array provider description

File

lib/oauth-php/library/OAuthDiscovery.php, line 50

Class

OAuthDiscovery

Code

static function discover($uri) {

  // See what kind of consumer allocations are available
  $xrds_file = self::discoverXRDS($uri);
  if (!empty($xrds_file)) {
    $xrds = xrds_parse($xrds_file);
    if (empty($xrds)) {
      throw new OAuthException2('Could not discover OAuth information for ' . $uri);
    }
  }
  else {
    throw new OAuthException2('Could not discover XRDS file at ' . $uri);
  }

  // Fill an LingotekOAuthServer record for the uri found
  $ps = parse_url($uri);
  $host = isset($ps['host']) ? $ps['host'] : 'localhost';
  $server_uri = $ps['scheme'] . '://' . $host . '/';
  $p = array(
    'user_id' => null,
    'consumer_key' => '',
    'consumer_secret' => '',
    'signature_methods' => '',
    'server_uri' => $server_uri,
    'request_token_uri' => '',
    'authorize_uri' => '',
    'access_token_uri' => '',
  );

  // Consumer identity (out of bounds or static)
  if (isset($xrds['consumer_identity'])) {

    // Try to find a static consumer allocation, we like those :)
    foreach ($xrds['consumer_identity'] as $ci) {
      if ($ci['method'] == 'static' && !empty($ci['consumer_key'])) {
        $p['consumer_key'] = $ci['consumer_key'];
        $p['consumer_secret'] = '';
      }
      else {
        if ($ci['method'] == 'oob' && !empty($ci['uri'])) {

          // TODO: Keep this uri somewhere for the user?
          $p['consumer_oob_uri'] = $ci['uri'];
        }
      }
    }
  }

  // The token uris
  if (isset($xrds['request'][0]['uri'])) {
    $p['request_token_uri'] = $xrds['request'][0]['uri'];
    if (!empty($xrds['request'][0]['signature_method'])) {
      $p['signature_methods'] = $xrds['request'][0]['signature_method'];
    }
  }
  if (isset($xrds['authorize'][0]['uri'])) {
    $p['authorize_uri'] = $xrds['authorize'][0]['uri'];
    if (!empty($xrds['authorize'][0]['signature_method'])) {
      $p['signature_methods'] = $xrds['authorize'][0]['signature_method'];
    }
  }
  if (isset($xrds['access'][0]['uri'])) {
    $p['access_token_uri'] = $xrds['access'][0]['uri'];
    if (!empty($xrds['access'][0]['signature_method'])) {
      $p['signature_methods'] = $xrds['access'][0]['signature_method'];
    }
  }
  return $p;
}