{"action":"created","comment":{"url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/comments/43167522","id":43167522,"diff_hunk":"@@ -0,0 +1,44 @@\n+require 'doorkeeper/grant_flow/flow'\n+\n+module Doorkeeper\n+  module GrantFlow\n+    mattr_accessor(:registered_flows) { Hash.new }\n+\n+    module_function\n+\n+    def register(name_or_flow, options = {})\n+      if name_or_flow.is_a? Doorkeeper::GrantFlow::Flow\n+        registered_flows[name_or_flow.name.to_sym] = name_or_flow\n+      else\n+        registered_flows[name_or_flow.to_sym] = Flow.new(name_or_flow, options)\n+      end\n+    end\n+\n+    def get(name)\n+      registered_flows.fetch(name.to_sym)\n+    end\n+  end\n+end\n+\n+Doorkeeper::GrantFlow.register :implicit, \n+  response_type_matches: 'token',\n+  response_type_strategy: Doorkeeper::Request::Token\n+\n+Doorkeeper::GrantFlow.register :authorization_code,\n+  response_type_matches: 'code',\n+  response_type_strategy: Doorkeeper::Request::Code,\n+  grant_type_matches: 'authorization_code',\n+  grant_type_strategy: Doorkeeper::Request::AuthorizationCode\n+\n+Doorkeeper::GrantFlow.register :client_credentials,\n+  grant_type_matches: 'client_credentials',\n+  grant_type_strategy: Doorkeeper::Request::ClientCredentials\n+\n+Doorkeeper::GrantFlow.register :password,\n+  grant_type_matches: 'password',\n+  grant_type_strategy: Doorkeeper::Request::Password\n+\n+Doorkeeper::GrantFlow.register :refresh_token,\n+  grant_type_matches: 'refresh_token',","path":"lib/doorkeeper/grant_flow.rb","position":42,"original_position":42,"commit_id":"48f5e4cf5f73c9201447c972de6888181aa964e4","original_commit_id":"48f5e4cf5f73c9201447c972de6888181aa964e4","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":"Align the parameters of a method call if they span more than one line.","created_at":"2015-10-27T18:42:15Z","updated_at":"2015-10-27T18:42:15Z","html_url":"https://github.com/doorkeeper-gem/doorkeeper/pull/733#discussion_r43167522","pull_request_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/733","_links":{"self":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/comments/43167522"},"html":{"href":"https://github.com/doorkeeper-gem/doorkeeper/pull/733#discussion_r43167522"},"pull_request":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/733"}}},"pull_request":{"url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/733","id":48913062,"html_url":"https://github.com/doorkeeper-gem/doorkeeper/pull/733","diff_url":"https://github.com/doorkeeper-gem/doorkeeper/pull/733.diff","patch_url":"https://github.com/doorkeeper-gem/doorkeeper/pull/733.patch","issue_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/733","number":733,"state":"open","locked":false,"title":"Add registration for grant flows","user":{"login":"reidab","id":13192,"avatar_url":"https://avatars.githubusercontent.com/u/13192?v=3","gravatar_id":"","url":"https://api.github.com/users/reidab","html_url":"https://github.com/reidab","followers_url":"https://api.github.com/users/reidab/followers","following_url":"https://api.github.com/users/reidab/following{/other_user}","gists_url":"https://api.github.com/users/reidab/gists{/gist_id}","starred_url":"https://api.github.com/users/reidab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reidab/subscriptions","organizations_url":"https://api.github.com/users/reidab/orgs","repos_url":"https://api.github.com/users/reidab/repos","events_url":"https://api.github.com/users/reidab/events{/privacy}","received_events_url":"https://api.github.com/users/reidab/received_events","type":"User","site_admin":false},"body":"This is a proposal inspired by comments on https://github.com/doorkeeper-gem/doorkeeper-grants_assertion/issues/9, where the possibility of adding strategy registration to Doorkeeper is mentioned.\r\n\r\nThis adds a `Doorkeeper::GrantFlow` module, which handles registration, and a `Doorkeeper::GrantFlow::Flow` class to handle the actual matching of `grant_type` and `response_type` values.\r\n\r\nA new flow is registered like so:\r\n\r\n```ruby\r\nDoorkeeper::GrantFlow.register :authorization_code,\r\n  response_type_matches: 'code',\r\n  response_type_strategy: Doorkeeper::Request::Code,\r\n  grant_type_matches: 'authorization_code',\r\n  grant_type_strategy: Doorkeeper::Request::AuthorizationCode\r\n```\r\n\r\nInstead of relying on constantizing the param values, requests are now routed to their corresponding strategy by matching against the `response_type_matches` and `grant_type_matches` attributes. This uses the `===` operator, so regular expressions may be used.\r\n\r\nIs this an approach you'd be interested in? I'd be happy to iterate and improve on this idea.","created_at":"2015-10-27T18:33:54Z","updated_at":"2015-10-27T18:42:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e522748d5116adb6effcb3c376b8a5634371476e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/733/commits","review_comments_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/733/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/733/comments","statuses_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/statuses/48f5e4cf5f73c9201447c972de6888181aa964e4","head":{"label":"reidab:grant-flow-registration","ref":"grant-flow-registration","sha":"48f5e4cf5f73c9201447c972de6888181aa964e4","user":{"login":"reidab","id":13192,"avatar_url":"https://avatars.githubusercontent.com/u/13192?v=3","gravatar_id":"","url":"https://api.github.com/users/reidab","html_url":"https://github.com/reidab","followers_url":"https://api.github.com/users/reidab/followers","following_url":"https://api.github.com/users/reidab/following{/other_user}","gists_url":"https://api.github.com/users/reidab/gists{/gist_id}","starred_url":"https://api.github.com/users/reidab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reidab/subscriptions","organizations_url":"https://api.github.com/users/reidab/orgs","repos_url":"https://api.github.com/users/reidab/repos","events_url":"https://api.github.com/users/reidab/events{/privacy}","received_events_url":"https://api.github.com/users/reidab/received_events","type":"User","site_admin":false},"repo":{"id":45057257,"name":"doorkeeper","full_name":"reidab/doorkeeper","owner":{"login":"reidab","id":13192,"avatar_url":"https://avatars.githubusercontent.com/u/13192?v=3","gravatar_id":"","url":"https://api.github.com/users/reidab","html_url":"https://github.com/reidab","followers_url":"https://api.github.com/users/reidab/followers","following_url":"https://api.github.com/users/reidab/following{/other_user}","gists_url":"https://api.github.com/users/reidab/gists{/gist_id}","starred_url":"https://api.github.com/users/reidab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reidab/subscriptions","organizations_url":"https://api.github.com/users/reidab/orgs","repos_url":"https://api.github.com/users/reidab/repos","events_url":"https://api.github.com/users/reidab/events{/privacy}","received_events_url":"https://api.github.com/users/reidab/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/reidab/doorkeeper","description":"Doorkeeper is an OAuth 2 provider for Rails and Grape","fork":true,"url":"https://api.github.com/repos/reidab/doorkeeper","forks_url":"https://api.github.com/repos/reidab/doorkeeper/forks","keys_url":"https://api.github.com/repos/reidab/doorkeeper/keys{/key_id}","collaborators_url":"https://api.github.com/repos/reidab/doorkeeper/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/reidab/doorkeeper/teams","hooks_url":"https://api.github.com/repos/reidab/doorkeeper/hooks","issue_events_url":"https://api.github.com/repos/reidab/doorkeeper/issues/events{/number}","events_url":"https://api.github.com/repos/reidab/doorkeeper/events","assignees_url":"https://api.github.com/repos/reidab/doorkeeper/assignees{/user}","branches_url":"https://api.github.com/repos/reidab/doorkeeper/branches{/branch}","tags_url":"https://api.github.com/repos/reidab/doorkeeper/tags","blobs_url":"https://api.github.com/repos/reidab/doorkeeper/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/reidab/doorkeeper/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/reidab/doorkeeper/git/refs{/sha}","trees_url":"https://api.github.com/repos/reidab/doorkeeper/git/trees{/sha}","statuses_url":"https://api.github.com/repos/reidab/doorkeeper/statuses/{sha}","languages_url":"https://api.github.com/repos/reidab/doorkeeper/languages","stargazers_url":"https://api.github.com/repos/reidab/doorkeeper/stargazers","contributors_url":"https://api.github.com/repos/reidab/doorkeeper/contributors","subscribers_url":"https://api.github.com/repos/reidab/doorkeeper/subscribers","subscription_url":"https://api.github.com/repos/reidab/doorkeeper/subscription","commits_url":"https://api.github.com/repos/reidab/doorkeeper/commits{/sha}","git_commits_url":"https://api.github.com/repos/reidab/doorkeeper/git/commits{/sha}","comments_url":"https://api.github.com/repos/reidab/doorkeeper/comments{/number}","issue_comment_url":"https://api.github.com/repos/reidab/doorkeeper/issues/comments{/number}","contents_url":"https://api.github.com/repos/reidab/doorkeeper/contents/{+path}","compare_url":"https://api.github.com/repos/reidab/doorkeeper/compare/{base}...{head}","merges_url":"https://api.github.com/repos/reidab/doorkeeper/merges","archive_url":"https://api.github.com/repos/reidab/doorkeeper/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/reidab/doorkeeper/downloads","issues_url":"https://api.github.com/repos/reidab/doorkeeper/issues{/number}","pulls_url":"https://api.github.com/repos/reidab/doorkeeper/pulls{/number}","milestones_url":"https://api.github.com/repos/reidab/doorkeeper/milestones{/number}","notifications_url":"https://api.github.com/repos/reidab/doorkeeper/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/reidab/doorkeeper/labels{/name}","releases_url":"https://api.github.com/repos/reidab/doorkeeper/releases{/id}","created_at":"2015-10-27T17:16:42Z","updated_at":"2015-10-27T17:16:43Z","pushed_at":"2015-10-27T18:42:06Z","git_url":"git://github.com/reidab/doorkeeper.git","ssh_url":"git@github.com:reidab/doorkeeper.git","clone_url":"https://github.com/reidab/doorkeeper.git","svn_url":"https://github.com/reidab/doorkeeper","homepage":"","size":6424,"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":"4313541e4d806cd8e5cad20d4ca4444171c113d2","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-10-27T14:21:35Z","pushed_at":"2015-10-27T18:42:07Z","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":6424,"stargazers_count":2651,"watchers_count":2651,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":538,"mirror_url":null,"open_issues_count":23,"forks":538,"open_issues":23,"watchers":2651,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/733"},"html":{"href":"https://github.com/doorkeeper-gem/doorkeeper/pull/733"},"issue":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/733"},"comments":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/733/comments"},"review_comments":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/pulls/733/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/733/commits"},"statuses":{"href":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/statuses/48f5e4cf5f73c9201447c972de6888181aa964e4"}}}}