From ff4d7cf5311a01b322a95675a7d7607048f49704 Mon Sep 17 00:00:00 2001 From: "a.pivkin" Date: Mon, 8 Jul 2024 12:10:05 +0300 Subject: [PATCH] new version --- index.php | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 index.php diff --git a/index.php b/index.php new file mode 100644 index 0000000..44b7325 --- /dev/null +++ b/index.php @@ -0,0 +1,59 @@ +function apiRequest($url, $post=FALSE, $headers=array()) { + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + + if($post) + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); + + $headers = [ + 'Accept: application/vnd.github.v3+json, application/json', + 'User-Agent: http://example-app.com/' + ]; + + if(isset($_SESSION['access_token'])) + $headers[] = 'Authorization: Bearer '.$SESSION['access_token']; + + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + + $response = curl_exec($ch); + return json_decode($response, true); +} + +$githubClientID = 'Ov23li271OczQKR6ISyL' +$githubClientSecret = '9df1c6e9fa98690dbcc9ed12676dc2adcc1cf8cf'; + +$authorizeURL = 'https://github.com/login/oauth/authorize'; +$tokenURL = 'https://github.com/login/oauth/access_token'; +$apiURLBase = 'https://api.github.com/'; +$baseURL = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']; + +session_start(); + +if(!isset($_GET['action'])) { + if(!empty($_SESSION['access_token'])) { + echo '

Logged In

' + echo '

View Repos

' + echo '

Log Out

' + } else { + echo '

Not Logged In

' + echo '

Log In

' + } +die(); +} + +if(!isset($_GET['action']) && $_GET['action'] == 'login') { + unset($_SESSION['access_token']); + + $_SESSION['state'] = bin2hex(random_bytes(16)); + + $params = array( + 'response_type' => 'code', + 'client_id' => '$githubClientID', + 'redirect_uri' => '$baseURL', + 'scope' => 'user_public_repo', + 'state' => '$_SESSION['state']' + ); + + header('Location: '.$authorizeURL.'?'.http_build_query($params)); + die(); +} \ No newline at end of file