Ejemplo n.º 1
0
 /**
  * Requests an access token.
  **/
 function requestToken($code)
 {
     $this->fetchWellKnownConfig();
     $clientId = session_get('openid_connect_client');
     $secret = session_get('openid_connect_secret');
     if (!$clientId || !$secret) {
         throw new OpenIDException('Autentificare eșuată.');
     }
     if (!isset($this->wellKnownConfig['token_endpoint'])) {
         throw new OpenIDException('Nu pot cere un token.');
     }
     $url = $this->wellKnownConfig['token_endpoint'];
     $params = array('client_id' => $clientId, 'client_secret' => $secret, 'code' => $code, 'grant_type' => 'authorization_code', 'redirect_uri' => $this->getReturnTo());
     $query = http_build_query($params, null, '&');
     $jsonResult = util_makePostRequest($url, $query);
     $result = json_decode($jsonResult, true);
     if (!$result || isset($result['error'])) {
         throw new OpenIDException('Eroare la cererea unui token');
     }
     if (!isset($result['id_token'])) {
         throw new OpenIDException('Furnizorul dumneavoastră a refuzat autorizarea');
     }
     $this->claims = $this->decodeJWT($result['id_token']);
     // verify the claims
     if ($this->claims['iss'] != $this->wellKnownConfig['issuer'] || $clientId != $this->claims['aud'] && !in_array($clientId, $this->claims['aud']) || $this->claims['nonce'] != session_get('openid_connect_nonce')) {
         throw new OpenIDException('Nu pot verifica tokenul. Posibilă încercare de interceptare a sesiunii!');
     }
     return $result['access_token'];
 }
Ejemplo n.º 2
0
function parse($text)
{
    // Preprocessing
    $text = "__NOEDITSECTION__\n" . $text;
    // Otherwise the returned HTML will contain section edit links
    $text = str_replace(array('ş', 'Ş', 'ţ', 'Ţ'), array('ș', 'Ș', 'ț', 'Ț'), $text);
    // Actual parsing
    $xmlString = util_makePostRequest(PARSER_URL, array('action' => 'parse', 'text' => $text, 'format' => 'xml', 'editsection' => false));
    $xml = simplexml_load_string($xmlString);
    $html = (string) $xml->parse->text;
    if (!$html) {
        return false;
    }
    // Postprocessing
    // Convert links to other articles, even if they are not under [[Categorie:Sincronizare]]
    $html = str_replace('href="/wiki/', 'href="/articol/', $html);
    // Fully qualify links to index.php. Most likely, these are link to non-existant articles.
    $html = str_replace('href="/index.php', 'href="http://wiki.dexonline.ro/index.php', $html);
    return $html;
}