RS256: Where does the $privateKey comes from?
I'm trying to use php-jwt to verify user ID tokens from Firebase with these instructions.
However, I'm not sure where can I get the $privateKey for this. The example in README says nothing about where does this value comes from. Thanks in advance.
The privatekey is used from the firebase serviceAccount.json file to generate the token and can be download from the firebase console. to verify the token use the the public key from this link.
Is this public key always constant or changes periodically. I mean we need to fetch this every time or can be stored.
@vikas-kumar-bhardwaj it changes after about 6 hours . you can store the file on your server along with the max-age header . so next time when you are reading the public keys file , first check if the max-age has been expired or not , if it is then just refresh the contents of your file .
private function getFbPublicKey(){ $result = file_get_contents('public/js/fb_public_keys.json'); $result = json_decode($result,true); if($result['max_age']>date(time())) { unset($result['max_age']); } else { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/robot/v1/metadata/x509/[email protected]'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, true); $response = curl_exec($ch); $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $header_len = curl_getinfo($ch, CURLINFO_HEADER_SIZE); curl_close($ch); $header = substr($response, 0, $header_len); $body = json_decode(substr($response, $header_len)); $headers = explode("max-age=", $header); $headers = explode("\n", $headers[1]); $max_age = explode(',',trim($headers[0])); $result = $body; $body->max_age = date(time()+$max_age[0]); $fp = fopen('public/js/fb_public_keys.json', 'w'); if(flock($fp, LOCK_EX)) { fwrite($fp, json_encode($body)); fflush($fp); flock($fp, LOCK_UN); } fclose($fp); } return (array)$result; }