ok

Mini Shell

Direktori : /home2/selectio/www/thecomponents.in/admin/api-firebase/
Upload File :
Current File : /home2/selectio/www/thecomponents.in/admin/api-firebase/verify-token.php

<?php
include_once('../includes/crud.php');
include_once('../library/jwt.php');
function generate_token()
{
    $jwt = new JWT();
    $payload = [
        'iat' => time(), /* issued at time */
        'iss' => 'eKart',
        'exp' => time() + (30 * 60), /* expires after 1 minute */
        'sub' => 'eKart Authentication'
    ];
    $token = $jwt::encode($payload, JWT_SECRET_KEY);
    return $token;
}
// generate_token();
// $token = generate_token();
// print_r($token);

function verify_token()
{
    $jwt = new JWT();
    try {
        $token = $jwt->getBearerToken();
    } catch (Exception $e) {
        $response['error'] = true;
        $response['message'] = $e->getMessage();
        print_r(json_encode($response));
        return false;
    }
    if (!empty($token)) {
        try {
            $payload = $jwt->decode($token, JWT_SECRET_KEY, ['HS256']);
            if (!isset($payload->iss) || $payload->iss != 'eKart') {
                $response['error'] = true;
                $response['message'] = 'Invalid Hash';
                print_r(json_encode($response));
                return false;
            } else {
                return true;
            }
        } catch (Exception $e) {
            $response['error'] = true;
            $response['message'] = $e->getMessage();
            print_r(json_encode($response));
            return false;
        }
    } else {
        $response['error'] = true;
        $response['message'] = "Unauthorized access not allowed";
        print_r(json_encode($response));
        return false;
    }
}

Zerion Mini Shell 1.0