{"action":"created","issue":{"url":"https://api.github.com/repos/progrium/ruby-jwt/issues/62","labels_url":"https://api.github.com/repos/progrium/ruby-jwt/issues/62/labels{/name}","comments_url":"https://api.github.com/repos/progrium/ruby-jwt/issues/62/comments","events_url":"https://api.github.com/repos/progrium/ruby-jwt/issues/62/events","html_url":"https://github.com/progrium/ruby-jwt/pull/62","id":60383014,"number":62,"title":"Add  'iat/ aud/ sub/ jti'  support for ruby-jwt","user":{"login":"ZhangHanDong","id":27893,"avatar_url":"https://avatars.githubusercontent.com/u/27893?v=3","gravatar_id":"","url":"https://api.github.com/users/ZhangHanDong","html_url":"https://github.com/ZhangHanDong","followers_url":"https://api.github.com/users/ZhangHanDong/followers","following_url":"https://api.github.com/users/ZhangHanDong/following{/other_user}","gists_url":"https://api.github.com/users/ZhangHanDong/gists{/gist_id}","starred_url":"https://api.github.com/users/ZhangHanDong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZhangHanDong/subscriptions","organizations_url":"https://api.github.com/users/ZhangHanDong/orgs","repos_url":"https://api.github.com/users/ZhangHanDong/repos","events_url":"https://api.github.com/users/ZhangHanDong/events{/privacy}","received_events_url":"https://api.github.com/users/ZhangHanDong/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-09T17:52:42Z","updated_at":"2015-03-09T19:02:46Z","closed_at":"2015-03-09T19:02:27Z","pull_request":{"url":"https://api.github.com/repos/progrium/ruby-jwt/pulls/62","html_url":"https://github.com/progrium/ruby-jwt/pull/62","diff_url":"https://github.com/progrium/ruby-jwt/pull/62.diff","patch_url":"https://github.com/progrium/ruby-jwt/pull/62.patch"},"body":"# for iat check support:\r\n\r\n```ruby\r\nexample_payload = {\"hello\" => \"world\", \"iat\" => 1425917209}\r\nexample_secret = 'secret'\r\nexample_jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJoZWxsbyI6IndvcmxkIiwiaWF0IjoxNDI1OTE3MjA5fQ.m4F-Ugo7aLnLunBBO3BeDidyWMx8T9eoJz6FW2rgQhU'\r\ndecoded_payload = JWT.decode(example_jwt, example_secret, true, {iat: true})\r\n\r\n```\r\n\r\nor\r\n\r\n```ruby\r\n\r\nbegin\r\n   example_payload = {\"hello\" => \"world\", \"iat\" => 1425917209}\r\nrescue JWT::InvalidIatError\r\n   # do something\r\nend\r\n```\r\n\r\n#  aud check support\r\n\r\n```ruby\r\n\r\nexample_payload = {\"hello\" => \"world\", \"aud\" => \"url:pnd\"}\r\nexample_payload2 = {\"hello\" => \"world\", \"aud\" => [\"url:pnd\", \"aud:yes\"]}\r\nexample_secret = 'secret'\r\n\r\nexample_jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJoZWxsbyI6IndvcmxkIiwiYXVkIjoidXJsOnBuZCJ9._gT5veUtNiZD7wLEC6Gd0-nkQV3cl1z8G0zXq8qcd-8'\r\nexample_jwt2 = \"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJoZWxsbyI6IndvcmxkIiwiYXVkIjpbInVybDpwbmQiLCJhdWQ6eWVzIl19.qNPNcT4X9B5uI91rIwbW2bIPTsp8wbRYW3jkZkrmqbQ\"\r\n\r\ndecoded_payload = JWT.decode(example_jwt, example_secret, true, {aud: \"url:pnd\"})\r\ndecoded_payload2 = JWT.decode(example_jwt2, example_secret, true, {aud: \"url:pnd\"})\r\n```\r\n\r\n# for sub support\r\n\r\n```ruby\r\nexample_payload = {\"hello\" => \"world\", \"sub\" => 'subject'}\r\nexample_secret = 'secret'\r\nexample_jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJoZWxsbyI6IndvcmxkIiwic3ViIjoic3ViamVjdCJ9.QUnNVZm4SPB4vP2zY9m1LoUSOx-5oGXBhj7R89D_UtA'\r\ndecoded_payload = JWT.decode(example_jwt, example_secret, true, {sub: 'subject'})\r\n```\r\n\r\n# for jti support\r\n\r\nIn order to ensure jti uniq for every jwt:\r\n\r\n1. Use the current timestamp (iat) as the nonce.\r\n2. Use the md5 hash of the jwt.\r\n\r\n\r\n```ruby\r\nexample_payload = {\"hello\" => \"world\", \"iat\" => 1425917209, \"jti\" => Digest::MD5.hexdigest(\"secret:1425917209\")}\r\nexample_secret = 'secret'\r\nexample_jwt = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJoZWxsbyI6IndvcmxkIiwiaWF0IjoxNDI1OTE3MjA5LCJqdGkiOiI1NWM3NzZlMjFmN2NiZDg3OWMwNmZhYzAxOGRhYzQwMiJ9.ET0hb-VTUOL3M22oG13ofzvGPLMAncbF8rdNDIqo8tg'\r\n\r\n decoded_payload = JWT.decode(example_jwt, example_secret, true, {jti: Digest::MD5.hexdigest(\"secret:1425917209\")})\r\n\r\n```\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/progrium/ruby-jwt/issues/comments/77919919","html_url":"https://github.com/progrium/ruby-jwt/pull/62#issuecomment-77919919","issue_url":"https://api.github.com/repos/progrium/ruby-jwt/issues/62","id":77919919,"user":{"login":"excpt","id":229786,"avatar_url":"https://avatars.githubusercontent.com/u/229786?v=3","gravatar_id":"","url":"https://api.github.com/users/excpt","html_url":"https://github.com/excpt","followers_url":"https://api.github.com/users/excpt/followers","following_url":"https://api.github.com/users/excpt/following{/other_user}","gists_url":"https://api.github.com/users/excpt/gists{/gist_id}","starred_url":"https://api.github.com/users/excpt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/excpt/subscriptions","organizations_url":"https://api.github.com/users/excpt/orgs","repos_url":"https://api.github.com/users/excpt/repos","events_url":"https://api.github.com/users/excpt/events{/privacy}","received_events_url":"https://api.github.com/users/excpt/received_events","type":"User","site_admin":false},"created_at":"2015-03-09T19:02:46Z","updated_at":"2015-03-09T19:02:46Z","body":"Awesome!\r\n\r\nThanks a lot! :tada: "}}