{"action":"created","comment":{"url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/comments/45563553","id":45563553,"diff_hunk":"@@ -129,14 +129,42 @@ def generate_refresh_token\n     end\n \n     def generate_token\n+      set_timestamps\n+\n       generator = Doorkeeper.configuration.access_token_generator.constantize\n-      self.token = generator.generate(resource_owner_id: resource_owner_id,\n-                                      scopes: scopes, application: application,\n-                                      expires_in: expires_in)\n+      self.token = generator.generate(\n+        resource_owner_id: resource_owner_id,\n+        scopes: scopes,\n+        application: application,\n+        expires_in: expires_in,\n+        created_at: created_at\n+      )\n     rescue NoMethodError\n       raise Errors::UnableToGenerateToken, \"#{generator} does not respond to `.generate`.\"\n     rescue NameError\n       raise Errors::TokenGeneratorNotFound, \"#{generator} not found\"\n     end\n+\n+    def set_timestamps\n+      if created_at.nil?\n+        self.created_at = current_time\n+\n+        if respond_to? :updated_at=","path":"lib/doorkeeper/models/access_token_mixin.rb","position":27,"original_position":27,"commit_id":"4dbe9b2c1177370bdbdf25921ac029f8b9e8ed2b","original_commit_id":"4dbe9b2c1177370bdbdf25921ac029f8b9e8ed2b","user":{"login":"tute","id":54260,"avatar_url":"https://avatars.githubusercontent.com/u/54260?v=3","gravatar_id":"","url":"https://api.github.com/users/tute","html_url":"https://github.com/tute","followers_url":"https://api.github.com/users/tute/followers","following_url":"https://api.github.com/users/tute/following{/other_user}","gists_url":"https://api.github.com/users/tute/gists{/gist_id}","starred_url":"https://api.github.com/users/tute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tute/subscriptions","organizations_url":"https://api.github.com/users/tute/orgs","repos_url":"https://api.github.com/users/tute/repos","events_url":"https://api.github.com/users/tute/events{/privacy}","received_events_url":"https://api.github.com/users/tute/received_events","type":"User","site_admin":false},"body":"Why do we need this `respond_to?` condition?","created_at":"2015-11-22T19:59:18Z","updated_at":"2015-11-22T19:59:18Z","html_url":"https://github.com/doorkeeper-gem/doorkeeper/pull/745#discussion_r45563553","pull_request_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/745","_links":{"self":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/comments/45563553"},"html":{"href":"https://github.com/doorkeeper-gem/doorkeeper/pull/745#discussion_r45563553"},"pull_request":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/745"}}},"pull_request":{"url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/745","id":50990523,"html_url":"https://github.com/doorkeeper-gem/doorkeeper/pull/745","diff_url":"https://github.com/doorkeeper-gem/doorkeeper/pull/745.diff","patch_url":"https://github.com/doorkeeper-gem/doorkeeper/pull/745.patch","issue_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/745","number":745,"state":"open","locked":false,"title":"Add created_at to token generation options","user":{"login":"ryansch","id":146013,"avatar_url":"https://avatars.githubusercontent.com/u/146013?v=3","gravatar_id":"","url":"https://api.github.com/users/ryansch","html_url":"https://github.com/ryansch","followers_url":"https://api.github.com/users/ryansch/followers","following_url":"https://api.github.com/users/ryansch/following{/other_user}","gists_url":"https://api.github.com/users/ryansch/gists{/gist_id}","starred_url":"https://api.github.com/users/ryansch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryansch/subscriptions","organizations_url":"https://api.github.com/users/ryansch/orgs","repos_url":"https://api.github.com/users/ryansch/repos","events_url":"https://api.github.com/users/ryansch/events{/privacy}","received_events_url":"https://api.github.com/users/ryansch/received_events","type":"User","site_admin":false},"body":"I'm using doorkeeper-jwt to add a JWT as my access token.  I'd like to support stateless auth but I need to be able to use the `iat` (issued at) and `exp` (expires at) claims and I need them to match doorkeeper's internal state.  This PR ensures the `created_at` and `updated_at` are set on the access token before generating the token string itself.\r\n\r\nExample use:\r\n```ruby\r\nDoorkeeper::JWT.configure do\r\n  token_payload do |opts|\r\n    {\r\n      iat: opts[:created_at].to_i,\r\n      exp: opts[:created_at].to_i + opts[:expires_in],\r\n      sub: opts[:resource_owner_id]\r\n    }\r\n  end\r\nend\r\n```","created_at":"2015-11-17T19:14:44Z","updated_at":"2015-11-22T19:59:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e838480c54f0a5033f25c14d2120a77f97c0caba","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/745/commits","review_comments_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/745/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/745/comments","statuses_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/statuses/4dbe9b2c1177370bdbdf25921ac029f8b9e8ed2b","head":{"label":"outstand:token-generator-options","ref":"token-generator-options","sha":"4dbe9b2c1177370bdbdf25921ac029f8b9e8ed2b","user":{"login":"outstand","id":141810,"avatar_url":"https://avatars.githubusercontent.com/u/141810?v=3","gravatar_id":"","url":"https://api.github.com/users/outstand","html_url":"https://github.com/outstand","followers_url":"https://api.github.com/users/outstand/followers","following_url":"https://api.github.com/users/outstand/following{/other_user}","gists_url":"https://api.github.com/users/outstand/gists{/gist_id}","starred_url":"https://api.github.com/users/outstand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/outstand/subscriptions","organizations_url":"https://api.github.com/users/outstand/orgs","repos_url":"https://api.github.com/users/outstand/repos","events_url":"https://api.github.com/users/outstand/events{/privacy}","received_events_url":"https://api.github.com/users/outstand/received_events","type":"Organization","site_admin":false},"repo":{"id":8208438,"name":"doorkeeper","full_name":"outstand/doorkeeper","owner":{"login":"outstand","id":141810,"avatar_url":"https://avatars.githubusercontent.com/u/141810?v=3","gravatar_id":"","url":"https://api.github.com/users/outstand","html_url":"https://github.com/outstand","followers_url":"https://api.github.com/users/outstand/followers","following_url":"https://api.github.com/users/outstand/following{/other_user}","gists_url":"https://api.github.com/users/outstand/gists{/gist_id}","starred_url":"https://api.github.com/users/outstand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/outstand/subscriptions","organizations_url":"https://api.github.com/users/outstand/orgs","repos_url":"https://api.github.com/users/outstand/repos","events_url":"https://api.github.com/users/outstand/events{/privacy}","received_events_url":"https://api.github.com/users/outstand/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/outstand/doorkeeper","description":"Doorkeeper is an OAuth 2 provider for Rails.","fork":true,"url":"https://api.github.com/repos/outstand/doorkeeper","forks_url":"https://api.github.com/repos/outstand/doorkeeper/forks","keys_url":"https://api.github.com/repos/outstand/doorkeeper/keys{/key_id}","collaborators_url":"https://api.github.com/repos/outstand/doorkeeper/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/outstand/doorkeeper/teams","hooks_url":"https://api.github.com/repos/outstand/doorkeeper/hooks","issue_events_url":"https://api.github.com/repos/outstand/doorkeeper/issues/events{/number}","events_url":"https://api.github.com/repos/outstand/doorkeeper/events","assignees_url":"https://api.github.com/repos/outstand/doorkeeper/assignees{/user}","branches_url":"https://api.github.com/repos/outstand/doorkeeper/branches{/branch}","tags_url":"https://api.github.com/repos/outstand/doorkeeper/tags","blobs_url":"https://api.github.com/repos/outstand/doorkeeper/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/outstand/doorkeeper/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/outstand/doorkeeper/git/refs{/sha}","trees_url":"https://api.github.com/repos/outstand/doorkeeper/git/trees{/sha}","statuses_url":"https://api.github.com/repos/outstand/doorkeeper/statuses/{sha}","languages_url":"https://api.github.com/repos/outstand/doorkeeper/languages","stargazers_url":"https://api.github.com/repos/outstand/doorkeeper/stargazers","contributors_url":"https://api.github.com/repos/outstand/doorkeeper/contributors","subscribers_url":"https://api.github.com/repos/outstand/doorkeeper/subscribers","subscription_url":"https://api.github.com/repos/outstand/doorkeeper/subscription","commits_url":"https://api.github.com/repos/outstand/doorkeeper/commits{/sha}","git_commits_url":"https://api.github.com/repos/outstand/doorkeeper/git/commits{/sha}","comments_url":"https://api.github.com/repos/outstand/doorkeeper/comments{/number}","issue_comment_url":"https://api.github.com/repos/outstand/doorkeeper/issues/comments{/number}","contents_url":"https://api.github.com/repos/outstand/doorkeeper/contents/{+path}","compare_url":"https://api.github.com/repos/outstand/doorkeeper/compare/{base}...{head}","merges_url":"https://api.github.com/repos/outstand/doorkeeper/merges","archive_url":"https://api.github.com/repos/outstand/doorkeeper/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/outstand/doorkeeper/downloads","issues_url":"https://api.github.com/repos/outstand/doorkeeper/issues{/number}","pulls_url":"https://api.github.com/repos/outstand/doorkeeper/pulls{/number}","milestones_url":"https://api.github.com/repos/outstand/doorkeeper/milestones{/number}","notifications_url":"https://api.github.com/repos/outstand/doorkeeper/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/outstand/doorkeeper/labels{/name}","releases_url":"https://api.github.com/repos/outstand/doorkeeper/releases{/id}","created_at":"2013-02-14T21:52:57Z","updated_at":"2015-11-17T19:11:38Z","pushed_at":"2015-11-20T22:49:51Z","git_url":"git://github.com/outstand/doorkeeper.git","ssh_url":"git@github.com:outstand/doorkeeper.git","clone_url":"https://github.com/outstand/doorkeeper.git","svn_url":"https://github.com/outstand/doorkeeper","homepage":"https://github.com/applicake/doorkeeper","size":2086,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"bd3802bbd0c4cdd830710d3a60812c6dce936040","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-11-21T20:55:47Z","pushed_at":"2015-11-22T19:53:45Z","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":2703,"stargazers_count":2698,"watchers_count":2698,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":549,"mirror_url":null,"open_issues_count":28,"forks":549,"open_issues":28,"watchers":2698,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/745"},"html":{"href":"https://github.com/doorkeeper-gem/doorkeeper/pull/745"},"issue":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/745"},"comments":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/745/comments"},"review_comments":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/745/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/745/commits"},"statuses":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/statuses/4dbe9b2c1177370bdbdf25921ac029f8b9e8ed2b"}}}}