{"action":"created","comment":{"url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/comments/27167566","id":27167566,"diff_hunk":"@@ -12,6 +12,81 @@ module Doorkeeper\n       let(:factory_name) { :access_token }\n     end\n \n+    describe :token do\n+      it \"creates a JWT token\" do\n+        Doorkeeper.configure do\n+          use_jwt_token\n+        end\n+\n+        token = FactoryGirl.create :access_token, use_jwt_token: true\n+        decoded_token = JWT.decode(token.token, nil, nil)\n+        expect(decoded_token[0]).to be_a(Hash)\n+        expect(decoded_token[1][\"typ\"]).to eq \"JWT\"\n+        expect(decoded_token[1][\"alg\"]).to eq \"none\"\n+      end\n+\n+      it \"encodes the payload in to the token\" do\n+        Doorkeeper.configure do\n+          use_jwt_token\n+\n+          jwt_token_payload do\n+            { foo: \"bar\" }\n+          end\n+        end\n+\n+        token = FactoryGirl.create :access_token, use_jwt_token: true\n+        decoded_token = JWT.decode(token.token, nil, nil)\n+        expect(decoded_token[0]).to eq({ \"foo\" => \"bar\" })\n+      end\n+\n+      it \"encodes the signed payload in to the token\" do\n+        Doorkeeper.configure do\n+          use_jwt_token\n+\n+          jwt_token_payload do\n+            { foo: \"bar\" }\n+          end\n+\n+          jwt_secret_key \"secret\"\n+        end\n+\n+        token = FactoryGirl.create :access_token, use_jwt_token: true\n+        decoded_token = JWT.decode(token.token, \"secret\", nil)\n+        expect(decoded_token[0]).to eq({ \"foo\" => \"bar\" })\n+      end\n+\n+      it \"encodes the encrypted payload in to the token\" do\n+        Doorkeeper.configure do\n+          use_jwt_token\n+\n+          jwt_token_payload do\n+            { foo: \"bar\" }\n+          end\n+\n+          jwt_secret_key \"secret\"\n+          jwt_encryption_method :hs512\n+        end\n+\n+        token = FactoryGirl.create :access_token, use_jwt_token: true\n+        decoded_token = JWT.decode(token.token, \"secret\", \"HS512\")\n+        expect(decoded_token[0]).to eq({ \"foo\" => \"bar\" })\n+        expect(decoded_token[1][\"typ\"]).to eq \"JWT\"\n+        expect(decoded_token[1][\"alg\"]).to eq \"HS512\"\n+      end\n+\n+      it \"does not use JWT without use_jwt_token set\" do\n+        Doorkeeper.configure do\n+          jwt_token_payload do\n+            { foo: \"bar\" }\n+          end\n+        end\n+\n+        token = FactoryGirl.create :access_token\n+        expect{ JWT.decode(token.token, nil, nil) }","path":"spec/models/doorkeeper/access_token_spec.rb","position":74,"original_position":74,"commit_id":"734c04bb1bca0f1f5840757d17d053dcffd3ee5e","original_commit_id":"734c04bb1bca0f1f5840757d17d053dcffd3ee5e","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Space missing to the left of {.","created_at":"2015-03-25T21:23:09Z","updated_at":"2015-03-25T21:23:09Z","html_url":"https://github.com/doorkeeper-gem/doorkeeper/pull/610#discussion_r27167566","pull_request_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/610","_links":{"self":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/comments/27167566"},"html":{"href":"https://github.com/doorkeeper-gem/doorkeeper/pull/610#discussion_r27167566"},"pull_request":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/610"}}},"pull_request":{"url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/610","id":31967392,"html_url":"https://github.com/doorkeeper-gem/doorkeeper/pull/610","diff_url":"https://github.com/doorkeeper-gem/doorkeeper/pull/610.diff","patch_url":"https://github.com/doorkeeper-gem/doorkeeper/pull/610.patch","issue_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/610","number":610,"state":"open","locked":false,"title":"JWT Support","user":{"login":"chriswarren","id":3241,"avatar_url":"https://avatars.githubusercontent.com/u/3241?v=3","gravatar_id":"","url":"https://api.github.com/users/chriswarren","html_url":"https://github.com/chriswarren","followers_url":"https://api.github.com/users/chriswarren/followers","following_url":"https://api.github.com/users/chriswarren/following{/other_user}","gists_url":"https://api.github.com/users/chriswarren/gists{/gist_id}","starred_url":"https://api.github.com/users/chriswarren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chriswarren/subscriptions","organizations_url":"https://api.github.com/users/chriswarren/orgs","repos_url":"https://api.github.com/users/chriswarren/repos","events_url":"https://api.github.com/users/chriswarren/events{/privacy}","received_events_url":"https://api.github.com/users/chriswarren/received_events","type":"User","site_admin":false},"body":"We talked about making this an extension in #598 but I wanted to submit it as a PR and get your thoughts before attempting to extract it, both to check that I'm not missing anything and in case seeing it written out changes your perspective on having it in the gem directly.\r\n\r\nAdds support for JWT tokens, set up through the regular Doorkeeper config process. Supports custom payloads and secrets and multiple encryption types, all disabled by default.\r\n\r\nUse case for JWT tokens is allowing applications to identify tokens provided by the Doorkeeper app and communicate amongst themselves without having to check in with the central application. If you know the secret used to encode the token you can decode it and access identifying information for the user.","created_at":"2015-03-25T21:23:02Z","updated_at":"2015-03-25T21:23:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d5f6b36b42760d6ec8841c6c1bf5fae55d8d624b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/610/commits","review_comments_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/610/comments","review_comment_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/comments{/number}","comments_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/610/comments","statuses_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/statuses/734c04bb1bca0f1f5840757d17d053dcffd3ee5e","head":{"label":"chriswarren:jwt","ref":"jwt","sha":"734c04bb1bca0f1f5840757d17d053dcffd3ee5e","user":{"login":"chriswarren","id":3241,"avatar_url":"https://avatars.githubusercontent.com/u/3241?v=3","gravatar_id":"","url":"https://api.github.com/users/chriswarren","html_url":"https://github.com/chriswarren","followers_url":"https://api.github.com/users/chriswarren/followers","following_url":"https://api.github.com/users/chriswarren/following{/other_user}","gists_url":"https://api.github.com/users/chriswarren/gists{/gist_id}","starred_url":"https://api.github.com/users/chriswarren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chriswarren/subscriptions","organizations_url":"https://api.github.com/users/chriswarren/orgs","repos_url":"https://api.github.com/users/chriswarren/repos","events_url":"https://api.github.com/users/chriswarren/events{/privacy}","received_events_url":"https://api.github.com/users/chriswarren/received_events","type":"User","site_admin":false},"repo":{"id":32819208,"name":"doorkeeper","full_name":"chriswarren/doorkeeper","owner":{"login":"chriswarren","id":3241,"avatar_url":"https://avatars.githubusercontent.com/u/3241?v=3","gravatar_id":"","url":"https://api.github.com/users/chriswarren","html_url":"https://github.com/chriswarren","followers_url":"https://api.github.com/users/chriswarren/followers","following_url":"https://api.github.com/users/chriswarren/following{/other_user}","gists_url":"https://api.github.com/users/chriswarren/gists{/gist_id}","starred_url":"https://api.github.com/users/chriswarren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chriswarren/subscriptions","organizations_url":"https://api.github.com/users/chriswarren/orgs","repos_url":"https://api.github.com/users/chriswarren/repos","events_url":"https://api.github.com/users/chriswarren/events{/privacy}","received_events_url":"https://api.github.com/users/chriswarren/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chriswarren/doorkeeper","description":"Doorkeeper is an OAuth 2 provider for Rails (and Grape)","fork":true,"url":"https://api.github.com/repos/chriswarren/doorkeeper","forks_url":"https://api.github.com/repos/chriswarren/doorkeeper/forks","keys_url":"https://api.github.com/repos/chriswarren/doorkeeper/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chriswarren/doorkeeper/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chriswarren/doorkeeper/teams","hooks_url":"https://api.github.com/repos/chriswarren/doorkeeper/hooks","issue_events_url":"https://api.github.com/repos/chriswarren/doorkeeper/issues/events{/number}","events_url":"https://api.github.com/repos/chriswarren/doorkeeper/events","assignees_url":"https://api.github.com/repos/chriswarren/doorkeeper/assignees{/user}","branches_url":"https://api.github.com/repos/chriswarren/doorkeeper/branches{/branch}","tags_url":"https://api.github.com/repos/chriswarren/doorkeeper/tags","blobs_url":"https://api.github.com/repos/chriswarren/doorkeeper/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chriswarren/doorkeeper/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chriswarren/doorkeeper/git/refs{/sha}","trees_url":"https://api.github.com/repos/chriswarren/doorkeeper/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chriswarren/doorkeeper/statuses/{sha}","languages_url":"https://api.github.com/repos/chriswarren/doorkeeper/languages","stargazers_url":"https://api.github.com/repos/chriswarren/doorkeeper/stargazers","contributors_url":"https://api.github.com/repos/chriswarren/doorkeeper/contributors","subscribers_url":"https://api.github.com/repos/chriswarren/doorkeeper/subscribers","subscription_url":"https://api.github.com/repos/chriswarren/doorkeeper/subscription","commits_url":"https://api.github.com/repos/chriswarren/doorkeeper/commits{/sha}","git_commits_url":"https://api.github.com/repos/chriswarren/doorkeeper/git/commits{/sha}","comments_url":"https://api.github.com/repos/chriswarren/doorkeeper/comments{/number}","issue_comment_url":"https://api.github.com/repos/chriswarren/doorkeeper/issues/comments{/number}","contents_url":"https://api.github.com/repos/chriswarren/doorkeeper/contents/{+path}","compare_url":"https://api.github.com/repos/chriswarren/doorkeeper/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chriswarren/doorkeeper/merges","archive_url":"https://api.github.com/repos/chriswarren/doorkeeper/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chriswarren/doorkeeper/downloads","issues_url":"https://api.github.com/repos/chriswarren/doorkeeper/issues{/number}","pulls_url":"https://api.github.com/repos/chriswarren/doorkeeper/pulls{/number}","milestones_url":"https://api.github.com/repos/chriswarren/doorkeeper/milestones{/number}","notifications_url":"https://api.github.com/repos/chriswarren/doorkeeper/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chriswarren/doorkeeper/labels{/name}","releases_url":"https://api.github.com/repos/chriswarren/doorkeeper/releases{/id}","created_at":"2015-03-24T19:08:33Z","updated_at":"2015-03-24T19:08:34Z","pushed_at":"2015-03-25T21:11:26Z","git_url":"git://github.com/chriswarren/doorkeeper.git","ssh_url":"git@github.com:chriswarren/doorkeeper.git","clone_url":"https://github.com/chriswarren/doorkeeper.git","svn_url":"https://github.com/chriswarren/doorkeeper","homepage":"","size":1912,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"doorkeeper-gem:master","ref":"master","sha":"16e2316fdc7fdf9e395fc202097f235833cb3a84","user":{"login":"doorkeeper-gem","id":7275750,"avatar_url":"https://avatars.githubusercontent.com/u/7275750?v=3","gravatar_id":"","url":"https://api.github.com/users/doorkeeper-gem","html_url":"https://github.com/doorkeeper-gem","followers_url":"https://api.github.com/users/doorkeeper-gem/followers","following_url":"https://api.github.com/users/doorkeeper-gem/following{/other_user}","gists_url":"https://api.github.com/users/doorkeeper-gem/gists{/gist_id}","starred_url":"https://api.github.com/users/doorkeeper-gem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doorkeeper-gem/subscriptions","organizations_url":"https://api.github.com/users/doorkeeper-gem/orgs","repos_url":"https://api.github.com/users/doorkeeper-gem/repos","events_url":"https://api.github.com/users/doorkeeper-gem/events{/privacy}","received_events_url":"https://api.github.com/users/doorkeeper-gem/received_events","type":"Organization","site_admin":false},"repo":{"id":2802565,"name":"doorkeeper","full_name":"doorkeeper-gem/doorkeeper","owner":{"login":"doorkeeper-gem","id":7275750,"avatar_url":"https://avatars.githubusercontent.com/u/7275750?v=3","gravatar_id":"","url":"https://api.github.com/users/doorkeeper-gem","html_url":"https://github.com/doorkeeper-gem","followers_url":"https://api.github.com/users/doorkeeper-gem/followers","following_url":"https://api.github.com/users/doorkeeper-gem/following{/other_user}","gists_url":"https://api.github.com/users/doorkeeper-gem/gists{/gist_id}","starred_url":"https://api.github.com/users/doorkeeper-gem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doorkeeper-gem/subscriptions","organizations_url":"https://api.github.com/users/doorkeeper-gem/orgs","repos_url":"https://api.github.com/users/doorkeeper-gem/repos","events_url":"https://api.github.com/users/doorkeeper-gem/events{/privacy}","received_events_url":"https://api.github.com/users/doorkeeper-gem/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/doorkeeper-gem/doorkeeper","description":"Doorkeeper is an OAuth 2 provider for Rails (and Grape)","fork":false,"url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper","forks_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/forks","keys_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/keys{/key_id}","collaborators_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/teams","hooks_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/hooks","issue_events_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/events{/number}","events_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/events","assignees_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/assignees{/user}","branches_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/branches{/branch}","tags_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/tags","blobs_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/git/refs{/sha}","trees_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/git/trees{/sha}","statuses_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/statuses/{sha}","languages_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/languages","stargazers_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/stargazers","contributors_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/contributors","subscribers_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/subscribers","subscription_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/subscription","commits_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/commits{/sha}","git_commits_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/git/commits{/sha}","comments_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/comments{/number}","issue_comment_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/comments{/number}","contents_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/contents/{+path}","compare_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/compare/{base}...{head}","merges_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/merges","archive_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/downloads","issues_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues{/number}","pulls_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls{/number}","milestones_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/milestones{/number}","notifications_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/labels{/name}","releases_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/releases{/id}","created_at":"2011-11-18T13:02:01Z","updated_at":"2015-03-25T13:22:00Z","pushed_at":"2015-03-25T21:23:02Z","git_url":"git://github.com/doorkeeper-gem/doorkeeper.git","ssh_url":"git@github.com:doorkeeper-gem/doorkeeper.git","clone_url":"https://github.com/doorkeeper-gem/doorkeeper.git","svn_url":"https://github.com/doorkeeper-gem/doorkeeper","homepage":"","size":5546,"stargazers_count":2160,"watchers_count":2160,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":452,"mirror_url":null,"open_issues_count":11,"forks":452,"open_issues":11,"watchers":2160,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/610"},"html":{"href":"https://github.com/doorkeeper-gem/doorkeeper/pull/610"},"issue":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/610"},"comments":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/610/comments"},"review_comments":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/610/comments"},"review_comment":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/610/commits"},"statuses":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/statuses/734c04bb1bca0f1f5840757d17d053dcffd3ee5e"}}}}