OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
cream
/
quiz
/
backup
/
old_backup
/
backup
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
05/19/2025 10:07:16 AM
rwxr-xr-x
📄
callback.php
1.55 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
oauth.php
2.63 KB
05/19/2025 10:07:16 AM
rw-r--r--
Editing: oauth.php
Close
<?php session_start(); // Load credentials from the JSON file $credentials = json_decode(file_get_contents('data/youtube_oauth.json'), true); $client_id = $credentials['web']['client_id']; $client_secret = $credentials['web']['client_secret']; // Step 1: If there's no authorization code, redirect to Google OAuth if (!isset($_GET['code'])) { // Build the Google OAuth URL $auth_url = $credentials['web']['auth_uri'] . '?' . http_build_query([ 'client_id' => $client_id, 'redirect_uri' => $credentials['web']['redirect_uris'][0], // First redirect URI 'response_type' => 'code', 'scope' => 'https://www.googleapis.com/auth/youtube.readonly', 'access_type' => 'offline', // This gives you the refresh token ]); // Redirect user to the Google OAuth URL header('Location: ' . $auth_url); exit(); } else { // Step 2: If there's an authorization code, exchange it for an access token $code = $_GET['code']; // Log the code for debugging (remove in production) // echo 'Authorization Code: ' . $code . "<br>"; $token_url = $credentials['web']['token_uri']; $data = [ 'code' => $code, 'client_id' => $client_id, 'client_secret' => $client_secret, 'redirect_uri' => $credentials['web']['redirect_uris'][0], // Same as before 'grant_type' => 'authorization_code' ]; // Use cURL to get the access token $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $token_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); $response = curl_exec($ch); curl_close($ch); // Decode the response to get the token $token = json_decode($response, true); // Log the token for debugging (remove in production) // echo 'Token Response: '; // print_r($token); if (isset($token['access_token'])) { // Store the access token in the session $_SESSION['access_token'] = $token['access_token']; // Optionally store the refresh token if available (useful for long-term access) if (isset($token['refresh_token'])) { $_SESSION['refresh_token'] = $token['refresh_token']; } // Redirect to the second URI in the redirect_uris array header('Location: ' . filter_var($credentials['web']['redirect_uris'][1], FILTER_SANITIZE_URL)); exit(); } else { // Handle errors in token retrieval die('Error: Could not get the access token. Please try again.'); } } ?>