Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Verify a Google API JWT with Firebase\JWT (Oauth) in PHP

How can I decode a JWT generated by Google using Firebase JWT in PHP?

I am trying to decode a JWT from Google API in a PHP endpoint:

use \Firebase\JWT\JWT; 

$decoded = JWT::decode($jwt, $secret, array('RS256'));

However, I get the error: "OpenSSL error: error:0909006C:PEM routines:get_name:no start line"

I can't get the jwt to be verified at jwt.io, either: Unable to verify Google JWT

This is where I got the secret from

I am able to decode my own HS256 JWTs using this method without any problems.

like image 206
Alex Russell Avatar asked Oct 22 '25 13:10

Alex Russell


1 Answers

composer require google/apiclient

use Google\AccessToken\Verify;

$verify = new Verify();
$payload = $verify->verifyIdToken($request->google_token);
like image 174
Jorge Montejo Avatar answered Oct 25 '25 05:10

Jorge Montejo