{"action":"created","issue":{"url":"https://api.github.com/repos/firebase/php-jwt/issues/189","repository_url":"https://api.github.com/repos/firebase/php-jwt","labels_url":"https://api.github.com/repos/firebase/php-jwt/issues/189/labels{/name}","comments_url":"https://api.github.com/repos/firebase/php-jwt/issues/189/comments","events_url":"https://api.github.com/repos/firebase/php-jwt/issues/189/events","html_url":"https://github.com/firebase/php-jwt/issues/189","id":288080483,"number":189,"title":"Encrypting/Decrypting problem with JWT Firebase RS256","user":{"login":"gsdiama","id":22974565,"avatar_url":"https://avatars1.githubusercontent.com/u/22974565?v=4","gravatar_id":"","url":"https://api.github.com/users/gsdiama","html_url":"https://github.com/gsdiama","followers_url":"https://api.github.com/users/gsdiama/followers","following_url":"https://api.github.com/users/gsdiama/following{/other_user}","gists_url":"https://api.github.com/users/gsdiama/gists{/gist_id}","starred_url":"https://api.github.com/users/gsdiama/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gsdiama/subscriptions","organizations_url":"https://api.github.com/users/gsdiama/orgs","repos_url":"https://api.github.com/users/gsdiama/repos","events_url":"https://api.github.com/users/gsdiama/events{/privacy}","received_events_url":"https://api.github.com/users/gsdiama/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-01-12T10:52:39Z","updated_at":"2018-02-27T14:36:54Z","closed_at":null,"author_association":"NONE","body":"Hi everybody,\r\n\r\nI don't know what I'm not doing right but Firebase custom token created with this JWT library can't be decoded properly.\r\n\r\n**Encoding process (PHP 5.4):**\r\n\r\n```\r\nfunction create_custom_token($uid, $is_premium_account){\r\n\t$service_account_email = \"firebase-adminsdk-XXXXX@XXXXXXXXXXXXXXX.iam.gserviceaccount.com\";\r\n\t$private_key = \"-----BEGIN PRIVATE KEY-----\\nMI...\"; //It includes \\n but I have tried without \\n or <<<EOD... \r\n\r\n\t$now_seconds = time();\r\n\t$payload = array(\r\n\t\t\"iss\" => $service_account_email,\r\n\t\t\"sub\" => $service_account_email,\r\n\t\t\"aud\" => \"https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit\",\r\n\t\t\"iat\" => $now_seconds,\r\n\t\t\"exp\" => $now_seconds + (60 * 60),\r\n\t\t\"uid\" => $uid,\r\n\t\t\"claims\" => array(\r\n\t\t\t\"premium_account\" => $is_premium_account\r\n\t\t)\r\n\t);\r\n\r\n\treturn JWT::encode($payload, $private_key, \"RS256\");\r\n}\r\n\r\n$uid = \"YYY\";\r\n$jwt = create_custom_token($uid, false);\r\n\r\n```\r\nIt returns a JWT that I store in the app in order to check the validity of the comming events. If I go to jwt.io I get an invalid signature message.\r\n\r\n**Decoding process (PHP 5.4):**\r\n\r\n$jwt is the JWT returned by the server.\r\n\r\n```\r\n$publicKeyURL = 'https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com';\r\n$key = json_decode(file_get_contents($publicKeyURL), true);\r\n$key = array_shift($key); //I check that the key is the proper one and seems right.\r\n$decoded = JWT::decode($jwt, $key, array(\"RS256\"));\r\n```\r\n\r\nI get Fatal error: Class 'SignatureInvalidException' not found in /var/www/vhosts/XXXXX.local/jwt.php on line 92\r\n\r\nIf I go deeper, I see that when it does:\r\nopenssl_verify($msg, $signature, $key, $algorithm);\r\n\r\nThe error message returned by openssl_error_string() is:\r\nerror:0407006A:rsa routines:RSA_padding_check_PKCS1_type_1:block type is not 01\r\n\r\nI have read in the net that it seems to be a key issue, but I have checked everything and seems OK.\r\n\r\nI will much appreciate if you could help me because I have been with this issue for 3 days.\r\n\r\nThank you very much in advance,\r\n\r\nGSDiama"},"comment":{"url":"https://api.github.com/repos/firebase/php-jwt/issues/comments/368898331","html_url":"https://github.com/firebase/php-jwt/issues/189#issuecomment-368898331","issue_url":"https://api.github.com/repos/firebase/php-jwt/issues/189","id":368898331,"user":{"login":"mwakaambrose","id":8328295,"avatar_url":"https://avatars3.githubusercontent.com/u/8328295?v=4","gravatar_id":"","url":"https://api.github.com/users/mwakaambrose","html_url":"https://github.com/mwakaambrose","followers_url":"https://api.github.com/users/mwakaambrose/followers","following_url":"https://api.github.com/users/mwakaambrose/following{/other_user}","gists_url":"https://api.github.com/users/mwakaambrose/gists{/gist_id}","starred_url":"https://api.github.com/users/mwakaambrose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwakaambrose/subscriptions","organizations_url":"https://api.github.com/users/mwakaambrose/orgs","repos_url":"https://api.github.com/users/mwakaambrose/repos","events_url":"https://api.github.com/users/mwakaambrose/events{/privacy}","received_events_url":"https://api.github.com/users/mwakaambrose/received_events","type":"User","site_admin":false},"created_at":"2018-02-27T14:36:54Z","updated_at":"2018-02-27T14:36:54Z","author_association":"NONE","body":"Same problem here. 'RS256' encoded tokens don't seem to be encoded properly."}}
{"actor":{"display_login":"mwakaambrose"}}