function fetch_bearer_token($path) { $bearer_token_file = fopen($path, "w+") or die("Unable to open file! [" . $path . "]"); $size = filesize($path); if ($size > 0) { $bearer_token = fread($bearer_token_file, $size); } else { $bearer_token = get_bearer_token(); fwrite($bearer_token_file, $bearer_token); } fclose($bearer_token_file); return $bearer_token; }
function handle_client_operations() { try { $token = $_REQUEST['access_token']; if (!$token) { $token = get_bearer_token(); if (!$token) { throw new BearerException('invalid_request', 'No Access Code'); } } $pos = strpos($_SERVER['PATH_INFO'], '/client/'); if ($pos === false) { throw new OidcException('invailid_request', 'Invalid path'); } $uri_path = substr($_SERVER['PATH_INFO'], $pos + 8); $db_client = db_get_client_by_registration_uri_path($uri_path); if (!$db_client) { throw new OidcException('invalid_request', 'Invalid client'); } if ($db_client['registration_access_token'] != $token) { throw new OidcException('invalid _request', 'Invalid registration token'); } $params = $db_client->toArray(); unset($params['id']); unset($params['registration_access_token']); unset($params['registration_client_uri_path']); unset($params['jwk_encryption_uri']); unset($params['x509_uri']); unset($params['x509_encryption_uri']); $array_params = array('contacts', 'redirect_uris', 'request_uris', 'post_logout_redirect_uris', 'response_types', 'grant_types', 'default_acr_values'); foreach ($params as $key => $value) { if ($value) { if (in_array($key, $array_params)) { $params[$key] = explode('|', $value); } } else { unset($params[$key]); } } if (!empty($params['jwks'])) { $params['jwks'] = json_decode($params['jwks'], true); } if ($params['require_auth_time']) { $params['require_auth_time'] = $params['require_auth_time'] == 1; } header("Cache-Control: no-store"); header("Pragma: no-cache"); header('Content-Type: application/json'); echo pretty_json(json_encode($params)); } catch (BearerException $e) { send_error(NULL, $e->error_code, $e->desc, NULL, true, '403'); } catch (OidcException $e) { send_error(NULL, $e->error_code, $e->desc, NULL, true, '403'); } }
$formed_url = $formed_url . '&result_type=' . $result_type; } // result type - mixed(default), recent, popular if ($count != '15') { $formed_url = $formed_url . '&count=' . $count; } // results per page - defaulted to 15 $formed_url = $formed_url . '&include_entities=true'; // makes sure the entities are included, note @mentions are not included see documentation $headers = array("GET /1.1/search/tweets.json" . $formed_url . " HTTP/1.1", "Host: api.twitter.com", "User-Agent: jonhurlock Twitter Application-only OAuth App v.1", "Authorization: Bearer " . $bearer_token . ""); $ch = curl_init(); // setup a curl curl_setopt($ch, CURLOPT_URL, $url . $formed_url); // set url to send to curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // set custom headers curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return output $retrievedhtml = curl_exec($ch); // execute the curl curl_close($ch); // close the curl return $retrievedhtml; } // lets run a search. $bearer_token = get_bearer_token(); // get the bearer token print search_for_a_term($bearer_token, "test"); // search for the work 'test' invalidate_bearer_token($bearer_token); // invalidate the token