2017-01-26 1 views
1

Je l'ai fait avec google inscription, je veux demander à propos de l'authentification google token_id. Google émet un token-id pour chaque utilisateur qui change à chaque connexion, je reçois ce jeton-id lorsque l'utilisateur se connecte, je veux authentifier cet identifiant de jeton de google pour vérifier si la connexion était originale ou fausse . J'utilise ce php api fourni par Google, mais il donne en permanence cette erreur:Classe 'Silex Application' introuvable

Uncaught Error: Class 'Silex\Application' not found in C:\xampp\htdocs\final\gplus-verifytoken-php-master\verify.php:23

Stack trace: #0 {main} thrown in C:\xampp\htdocs\final\gplus-verifytoken-php-master\verify.php on line 23

require_once __DIR__.'/vendor/autoload.php'; 
require_once __DIR__.'/google-api-php-client/src/Google_Client.php'; 

use Symfony\Component\HttpFoundation\Request; 
use Symfony\Component\HttpFoundation\Response; 

const CLIENT_ID = 'xyz'; 
const CLIENT_SECRET = 'xyz'; 
const APPLICATION_NAME = "xyz"; 

$client = new Google_Client(); 
$client->setApplicationName(APPLICATION_NAME); 
$client->setClientId(CLIENT_ID); 
$client->setClientSecret(CLIENT_SECRET); 

$app = new Silex\Application(); 
$app['debug'] = true; 

$app->register(new Silex\Provider\TwigServiceProvider(), array(
    'twig.path' => __DIR__, 
)); 
$app->register(new Silex\Provider\SessionServiceProvider()); 

// Initialize a session for the current user, and render index.html. 
$app->get('/', function() use ($app) { 
    return $app['twig']->render('index.html', array(
     'CLIENT_ID' => CLIENT_ID, 
     'APPLICATION_NAME' => APPLICATION_NAME 
    )); 
}); 

// Verify an ID Token or an Access Token. 
// Example URI: /verify?id_token=...&access_token=... 
$app->post('/verify', function (Request $request) use($app, $client) { 

    $id_token = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImE0MzY0YjVmYjliODYxYzNhYTRkYTg5NWExMjk5NzZjMjgyZGJmYzIifQ.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwiaWF0IjoxNDg1NDEyMjQ1LCJleHAiOjE0ODU0MTU4NDUsImF0X2hhc2giOiJMSV9DTWxzeG1lSTdvQm9lSUxoSjZRIiwiYXVkIjoiNDY4MzU1OTM0NzMzLXZqNnRkdDJtazEwZ3R0OHJvZGY2bG84MHM4czdtdTRrLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwic3ViIjoiMTEyNjE1NTE5MDY0MTc3ODI0NTgzIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImF6cCI6IjQ2ODM1NTkzNDczMy12ajZ0ZHQybWsxMGd0dDhyb2RmNmxvODBzOHM3bXU0ay5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImVtYWlsIjoibWdoYXphbmZhcmFsaWtoYW4wOUBnbWFpbC5jb20ifQ.Bpa2_zeVebQ7xtKXvuEell50bvUtKOGb5ZertUZGvzGWXnlA-c2kw4Mvko9Xd4JI_R4wbFoyBtrGCiK0jAlJMgaIH8p3wJbzNKPZ-gPFJdX8mv4v42v8-9urGM7rRUCDylz16WEcR1A2qOmEcNCpCf0_FGNpChl8sc8q8zvTnIb_zYYHp_V7ebR2RlUuO2z9G5YzBN3hZDnmen1xLStmNmYKsIiP5ypMqbWaLjnXJjre6bjTuIGymg_phDYDmwWMVTJyx88zmKAfwQTCh2u3qe_fkCDxxm0MO2wC29__q4uc0BfUNdH62GOrNTBJXmPTUZuT1vdUhzz4CLu1KUohWg"; 
    /*$id_token = $request->get("id_token");*/ 
    $access_token = $request->get("access_token"); 

    $token_status = Array(); 

    $id_status = Array(); 
    if (!empty($id_token)) { 
     // Check that the ID Token is valid. 
     try { 
     // Client library can verify the ID token. 
     $jwt = $client->verifyIdToken($id_token, CLIENT_ID)->getAttributes(); 
     $gplus_id = $jwt["payload"]["sub"]; 

     $id_status["valid"] = true; 
     $id_status["gplus_id"] = $gplus_id; 
     $id_status["message"] = "ID Token is valid."; 
     } catch (Google_AuthException $e) { 
     $id_status["valid"] = false; 
     $id_status["gplus_id"] = NULL; 
     $id_status["message"] = "Invalid ID Token."; 
     } 
     $token_status["id_token_status"] = $id_status; 
    } 

    $access_status = Array(); 
    if (!empty($access_token)) { 
     $access_status["valid"] = false; 
     $access_status["gplus_id"] = NULL; 
     // Check that the Access Token is valid. 
     $reqUrl = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' . 
       $access_token; 
     $req = new Google_HttpRequest($reqUrl); 

     $tokenInfo = json_decode(
      $client::getIo()->authenticatedRequest($req) 
       ->getResponseBody()); 

     if ($tokenInfo->error) { 
     // This is not a valid token. 
     $access_status["message"] = "Invalid Access Token."; 
     } else if ($tokenInfo->audience != CLIENT_ID) { 
     // This is not meant for this app. It is VERY important to check 
     // the client ID in order to prevent man-in-the-middle attacks. 
     $access_status["message"] = "Access Token not meant for this app."; 
     } else { 
     $access_status["valid"] = true; 
     $access_status["gplus_id"] = $tokenInfo->user_id; 
     $access_status["message"] = "Access Token is valid."; 
     } 
     $token_status["access_token_status"] = $access_status; 
    } 

    return $app->json($token_status, 200); 
}); 

$app->run(); 
+0

Avez-vous essayé 'composer installer'? – itsazzad

+0

Et avez-vous essayé avec 'composer dump-autoload'? – itsazzad

+0

En cas d'erreur, envoyez la liste d'erreurs. – itsazzad

Répondre

0

Je l'ai fait comme ça

composer install (after that run this command) 
composer dump-autoload 

il travaille pour moi