{"action":"created","issue":{"url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/763","repository_url":"https://api.github.com/repos/tymondesigns/jwt-auth","labels_url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/763/labels{/name}","comments_url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/763/comments","events_url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/763/events","html_url":"https://github.com/tymondesigns/jwt-auth/issues/763","id":160822077,"number":763,"title":"JWTException when trying to use RS256 algorithm","user":{"login":"righter","id":1621194,"avatar_url":"https://avatars.githubusercontent.com/u/1621194?v=3","gravatar_id":"","url":"https://api.github.com/users/righter","html_url":"https://github.com/righter","followers_url":"https://api.github.com/users/righter/followers","following_url":"https://api.github.com/users/righter/following{/other_user}","gists_url":"https://api.github.com/users/righter/gists{/gist_id}","starred_url":"https://api.github.com/users/righter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/righter/subscriptions","organizations_url":"https://api.github.com/users/righter/orgs","repos_url":"https://api.github.com/users/righter/repos","events_url":"https://api.github.com/users/righter/events{/privacy}","received_events_url":"https://api.github.com/users/righter/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-06-17T06:41:41Z","updated_at":"2016-07-07T20:13:37Z","closed_at":null,"body":"In order to successfully sign and verify tokens using RS256, I had to override a few methods in `Tymon\\JWTAuth\\Providers\\JWT\\Namshi`.\r\nHere's what I have set up:\r\n\r\n- I'm working from a fresh Laravel 5.2 installation\r\n- I installed tymon/jwt-auth, 1.0.0-alpha.2\r\n- JWT_PUBLIC_KEY=/tmp/jwt_auth/pubkey.pem\r\n- JWT_PRIVATE_KEY=/tmp/jwt_auth/privkey.pem\r\n- JWT_ALGO=RS256\r\n\r\nI'm authenticating a user like this:\r\n```php\r\n    public function authUser(JWTAuth $jwt)\r\n    {\r\n        return $jwt->attempt(['email' => 'foo', 'password' => 'password']);\r\n    }\r\n```\r\n\r\nwhich results in the following error:\r\n```\r\nJWTException in Namshi.php line 61:\r\nCould not create token: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given\r\n```\r\n\r\nLooking at the tests on the develop branch, the NamshiTest is using `file_get_contents` to get the file contents into a resource.\r\n\r\nTo keep changes out of the vendor directory, I created a new provider which extends `Tymon\\JWTAuth\\Providers\\JWT\\Namshi`. This allowed me to override the methods I needed and I was able to successfully authenticate users and receive/verify signed tokens.\r\n"},"comment":{"url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/comments/231193491","html_url":"https://github.com/tymondesigns/jwt-auth/issues/763#issuecomment-231193491","issue_url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/763","id":231193491,"user":{"login":"tdhsmith","id":1791252,"avatar_url":"https://avatars.githubusercontent.com/u/1791252?v=3","gravatar_id":"","url":"https://api.github.com/users/tdhsmith","html_url":"https://github.com/tdhsmith","followers_url":"https://api.github.com/users/tdhsmith/followers","following_url":"https://api.github.com/users/tdhsmith/following{/other_user}","gists_url":"https://api.github.com/users/tdhsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/tdhsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tdhsmith/subscriptions","organizations_url":"https://api.github.com/users/tdhsmith/orgs","repos_url":"https://api.github.com/users/tdhsmith/repos","events_url":"https://api.github.com/users/tdhsmith/events{/privacy}","received_events_url":"https://api.github.com/users/tdhsmith/received_events","type":"User","site_admin":false},"created_at":"2016-07-07T20:13:37Z","updated_at":"2016-07-07T20:13:37Z","body":"Ok I dug into this in a little bit, and I have successfully managed to get file path strings to work, with the following config:\r\n```php\r\n'keys' => [\r\n    'public'     => 'file://../public.pem',\r\n    'private'    => 'file://../private.pem',\r\n    'passphrase' => 'password'\r\n],\r\n```\r\n\r\nI think the issues are a lot of little quirks about the process:\r\n\r\n- [`file://`](http://php.net/manual/en/wrappers.file.php) can lend itself to easy mistakes. If you want absolute paths, you need to start it with a hard-to-see third slash `file:///`. And you have to keep PHP's working directory in mind for relative paths -- for the average Laravel project, that's gonna be `<project>/public`, so you'll need to move up a level. (@righter maybe one of these was your issue?)\r\n- OpenSSL is very strict about the PEM format. You can't pass in plain pub key files like those `ssh-keygen` creates that start with \"ssh-rsa\". In fact, I couldn't even get _PEM files_ created by `ssh-keygen` to be recognized. I think it's something with the ANS1 encoding (which is sort of proprietary I guess) because OpenSSL always complains about the tags or the heading structure or somesuch. So it may be that you can only use keys generated by `openssl`. (@djordn since your file has the extension .key, this might be your problem?)\r\n- Like many PHP built-ins, the openssl functions have to be polled for their error messages, using `openssl_error_string()`. This combined with the fact that namshi/jose isn't coded very defensively, means it's a little hard to get any info about what's wrong. I'm planning to submit a PR to namshi in the next day or so to update the messaging there.\r\n\r\nThat all said, I think the solutions you two used are both perfectly acceptable, and considering how finicky it all is, I wouldn't fret too much about it. 😛 "}}
{"actor":{"display_login":"tdhsmith"}}