doorkeeper-sequel 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +13 -0
  6. data/.travis.yml +24 -0
  7. data/CHANGELOG.md +24 -0
  8. data/Gemfile +23 -0
  9. data/Gemfile.lock +172 -0
  10. data/LICENSE +21 -0
  11. data/README.md +76 -0
  12. data/Rakefile +56 -0
  13. data/config/locales/en.yml +16 -0
  14. data/doorkeeper-sequel.gemspec +32 -0
  15. data/gemfiles/rails-4.2.gemfile +11 -0
  16. data/gemfiles/rails-5.0.gemfile +11 -0
  17. data/lib/doorkeeper/orm/sequel/access_grant.rb +9 -0
  18. data/lib/doorkeeper/orm/sequel/access_token.rb +32 -0
  19. data/lib/doorkeeper/orm/sequel/application.rb +18 -0
  20. data/lib/doorkeeper/orm/sequel/models/access_grant_mixin.rb +50 -0
  21. data/lib/doorkeeper/orm/sequel/models/access_token_mixin.rb +163 -0
  22. data/lib/doorkeeper/orm/sequel/models/application_mixin.rb +70 -0
  23. data/lib/doorkeeper/orm/sequel/models/concerns/ownership.rb +19 -0
  24. data/lib/doorkeeper/orm/sequel/models/concerns/sequel_compat.rb +40 -0
  25. data/lib/doorkeeper/orm/sequel/validators/redirect_uri_validator.rb +49 -0
  26. data/lib/doorkeeper/orm/sequel.rb +18 -0
  27. data/lib/doorkeeper-sequel/gem_version.rb +13 -0
  28. data/lib/doorkeeper-sequel/version.rb +7 -0
  29. data/lib/doorkeeper-sequel.rb +18 -0
  30. data/lib/generators/doorkeeper/sequel/application_owner_generator.rb +23 -0
  31. data/lib/generators/doorkeeper/sequel/migration_generator.rb +23 -0
  32. data/lib/generators/doorkeeper/sequel/previous_refresh_token_generator.rb +23 -0
  33. data/lib/generators/doorkeeper/sequel/templates/add_owner_to_application.rb +9 -0
  34. data/lib/generators/doorkeeper/sequel/templates/add_previous_refresh_token_to_access_tokens.rb +7 -0
  35. data/lib/generators/doorkeeper/sequel/templates/migration.rb +59 -0
  36. data/spec/controllers/application_metal_controller.rb +10 -0
  37. data/spec/controllers/applications_controller_spec.rb +58 -0
  38. data/spec/controllers/authorizations_controller_spec.rb +189 -0
  39. data/spec/controllers/protected_resources_controller_spec.rb +300 -0
  40. data/spec/controllers/token_info_controller_spec.rb +52 -0
  41. data/spec/controllers/tokens_controller_spec.rb +88 -0
  42. data/spec/dummy/Rakefile +7 -0
  43. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  44. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +7 -0
  45. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +12 -0
  46. data/spec/dummy/app/controllers/home_controller.rb +17 -0
  47. data/spec/dummy/app/controllers/metal_controller.rb +11 -0
  48. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +11 -0
  49. data/spec/dummy/app/helpers/application_helper.rb +5 -0
  50. data/spec/dummy/app/models/user.rb +11 -0
  51. data/spec/dummy/app/views/home/index.html.erb +0 -0
  52. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  53. data/spec/dummy/config/application.rb +29 -0
  54. data/spec/dummy/config/boot.rb +9 -0
  55. data/spec/dummy/config/database.yml +15 -0
  56. data/spec/dummy/config/environment.rb +5 -0
  57. data/spec/dummy/config/environments/development.rb +29 -0
  58. data/spec/dummy/config/environments/production.rb +62 -0
  59. data/spec/dummy/config/environments/test.rb +44 -0
  60. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  61. data/spec/dummy/config/initializers/db.rb +74 -0
  62. data/spec/dummy/config/initializers/doorkeeper.rb +96 -0
  63. data/spec/dummy/config/initializers/secret_token.rb +9 -0
  64. data/spec/dummy/config/initializers/session_store.rb +8 -0
  65. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  66. data/spec/dummy/config/locales/doorkeeper.en.yml +5 -0
  67. data/spec/dummy/config/routes.rb +52 -0
  68. data/spec/dummy/config.ru +4 -0
  69. data/spec/dummy/db/migrate/20111122132257_create_users.rb +9 -0
  70. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +5 -0
  71. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +60 -0
  72. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +7 -0
  73. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +11 -0
  74. data/spec/dummy/db/schema.rb +67 -0
  75. data/spec/dummy/log/test.log +19813 -0
  76. data/spec/dummy/public/404.html +26 -0
  77. data/spec/dummy/public/422.html +26 -0
  78. data/spec/dummy/public/500.html +26 -0
  79. data/spec/dummy/public/favicon.ico +0 -0
  80. data/spec/dummy/script/rails +6 -0
  81. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-T/-TZF6Ae6YipbyKuHghb9wlTx4_b9itbSHRc_2PmqjiU.cache +1 -0
  82. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/0p/0pa3wNbGHqFC6gxrMvdOJiP6gPwFv9VJ_npjEfRWxAE.cache +1 -0
  83. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/2e/2eYh115US2lIRhM2KTEaJFa6aV_cX8iv6JAdjuq0Uio.cache +1 -0
  84. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/3P/3PoguHEOEeItUjmwC74MWLLP-_Ijow7798bF5U6K2dw.cache +1 -0
  85. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6b/6b0anrSo7Fvoc05t4Ca0zZmfS_cpERy1DsG3ea6lBOg.cache +0 -0
  86. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/BA/BAC3ZaGoeZ9Od-kKg-UQYelvRgsCa0H72-52nLdcTNw.cache +1 -0
  87. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Bw/Bw6Nimjvy5Yv1AYbZb1t-v0eMNhv-bhwBzR-b5mY7FU.cache +0 -0
  88. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Fq/FqQWjMAz8yjZQlMC_dUsztaOxGruI2IXyGAAUF9SvQ0.cache +1 -0
  89. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/J_/J_D9clwKidN28hnVB1O3zEfKDwg90Usdb5ToKiPq_aw.cache +0 -0
  90. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Ji/JitNKkP1dYdu9ObSdIkkEAsiFxEmRO5oy1UIyhT_hYs.cache +0 -0
  91. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Jq/JqTLVvnY2AgGkHftWPwqt_HkbwhYRsmgHxk37VqKJAY.cache +0 -0
  92. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/QX/QXcp8DweOJ6BfMedGMfeHvVXv2hjDIleln1LSJk7vOE.cache +2 -0
  93. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Qy/Qy1ldbz6vKa_fv4E4ByxWslKFoV1qReQR5DKJ525z88.cache +1 -0
  94. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Rl/RlCJ_X5xFsE3VBDhkYrY7r_R6sMgiAc03cT8nr7Q2vY.cache +0 -0
  95. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Ta/TaYxNn81MhqC3DnMC6_y_Q7xap5Ntn4ggFo94EUaiak.cache +0 -0
  96. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Wq/WqbLVKOcTMZtttygYt_ncr1mGIDrzevSTaPGNmzV1D8.cache +1 -0
  97. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/YF/YF60qiQ28QMoYDrLmrbHWZr7X7bl5MxVPR5QrrVCFak.cache +1 -0
  98. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Yf/YfJJZvm_NONHd4eCasDibCcRapZ_WYIO5MUxSUUbYFk.cache +0 -0
  99. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Z0/Z0e47cT2a-21U-w-3gkbgqC3o5jWnEzOB8vW06aJH1E.cache +0 -0
  100. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/_u/_uy-z8SVnhffUNelRxbPDL2aAUPb_GbqREXVsfy8uGc.cache +0 -0
  101. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/dL/dL7SLUWUIeVdyA1UuH-rvif0nzesOar3LdEtqzdb4bE.cache +0 -0
  102. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/f8/f8WT8jqR1qNIdQaRDpXbyLN7E5AWkbYFBwdh9Ozk7gk.cache +1 -0
  103. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/hk/hk2YB6skvc72qL4IzzQKU8Emyfe5vARjoD1bvQTw4zE.cache +1 -0
  104. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/iO/iOpDp_7ZvBNO5WIpTmqNewUl9bB2satqXWulyNvAaX8.cache +0 -0
  105. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ii/iiJRBZIsxKiwyzU_Z7UtQeUTXMRJRPTreTKRvAWO7_8.cache +1 -0
  106. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mj/mjuMepngMLrtgilLlJ9oTTSqoGO1YUww1rXphQ1pOm4.cache +0 -0
  107. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/qo/qo6SpT75QykYB63Aqq5bgzpXyNU1Y4dGFvCCJgoWQpE.cache +1 -0
  108. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/sp/sprzBMBliJDI__s-0D3q82tn1MpBkFV0N651hTr3XE8.cache +1 -0
  109. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/tM/tM6A7CR8QluP_u4u59vN1GjSZGNqNH3TXkkNzb9EPXA.cache +0 -0
  110. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/vO/vOXN0mER62j4JiPpMTSVS7MMqs0067cZx14vD5B8qiQ.cache +0 -0
  111. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/zz/zzlQ_kom0liFOvGYDcjtVw6yAHOyA-bbzP8f0e_Tq1A.cache +1 -0
  112. data/spec/factories.rb +28 -0
  113. data/spec/generators/application_owner_generator_spec.rb +20 -0
  114. data/spec/generators/migration_generator_spec.rb +20 -0
  115. data/spec/generators/previous_refresh_token_generator_spec.rb +20 -0
  116. data/spec/generators/templates/routes.rb +3 -0
  117. data/spec/generators/tmp/dummy/db/migrate/20161012132809_create_doorkeeper_tables.rb +59 -0
  118. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +24 -0
  119. data/spec/lib/config_spec.rb +334 -0
  120. data/spec/lib/doorkeeper_spec.rb +28 -0
  121. data/spec/lib/models/expirable_spec.rb +51 -0
  122. data/spec/lib/models/revocable_spec.rb +59 -0
  123. data/spec/lib/models/scopes_spec.rb +43 -0
  124. data/spec/lib/oauth/authorization/uri_builder_spec.rb +42 -0
  125. data/spec/lib/oauth/authorization_code_request_spec.rb +80 -0
  126. data/spec/lib/oauth/client/credentials_spec.rb +47 -0
  127. data/spec/lib/oauth/client/methods_spec.rb +54 -0
  128. data/spec/lib/oauth/client_credentials/creator_spec.rb +44 -0
  129. data/spec/lib/oauth/client_credentials/issuer_spec.rb +86 -0
  130. data/spec/lib/oauth/client_credentials/validation_spec.rb +54 -0
  131. data/spec/lib/oauth/client_credentials_integration_spec.rb +27 -0
  132. data/spec/lib/oauth/client_credentials_request_spec.rb +104 -0
  133. data/spec/lib/oauth/client_spec.rb +39 -0
  134. data/spec/lib/oauth/code_request_spec.rb +45 -0
  135. data/spec/lib/oauth/code_response_spec.rb +34 -0
  136. data/spec/lib/oauth/error_response_spec.rb +61 -0
  137. data/spec/lib/oauth/error_spec.rb +23 -0
  138. data/spec/lib/oauth/forbidden_token_response_spec.rb +23 -0
  139. data/spec/lib/oauth/helpers/scope_checker_spec.rb +64 -0
  140. data/spec/lib/oauth/helpers/unique_token_spec.rb +20 -0
  141. data/spec/lib/oauth/helpers/uri_checker_spec.rb +104 -0
  142. data/spec/lib/oauth/invalid_token_response_spec.rb +28 -0
  143. data/spec/lib/oauth/password_access_token_request_spec.rb +90 -0
  144. data/spec/lib/oauth/pre_authorization_spec.rb +155 -0
  145. data/spec/lib/oauth/refresh_token_request_spec.rb +154 -0
  146. data/spec/lib/oauth/scopes_spec.rb +122 -0
  147. data/spec/lib/oauth/token_request_spec.rb +98 -0
  148. data/spec/lib/oauth/token_response_spec.rb +85 -0
  149. data/spec/lib/oauth/token_spec.rb +116 -0
  150. data/spec/lib/request/strategy_spec.rb +53 -0
  151. data/spec/lib/server_spec.rb +52 -0
  152. data/spec/models/doorkeeper/access_grant_spec.rb +36 -0
  153. data/spec/models/doorkeeper/access_token_spec.rb +394 -0
  154. data/spec/models/doorkeeper/application_spec.rb +179 -0
  155. data/spec/requests/applications/applications_request_spec.rb +94 -0
  156. data/spec/requests/applications/authorized_applications_spec.rb +30 -0
  157. data/spec/requests/endpoints/authorization_spec.rb +72 -0
  158. data/spec/requests/endpoints/token_spec.rb +64 -0
  159. data/spec/requests/flows/authorization_code_errors_spec.rb +66 -0
  160. data/spec/requests/flows/authorization_code_spec.rb +156 -0
  161. data/spec/requests/flows/client_credentials_spec.rb +58 -0
  162. data/spec/requests/flows/implicit_grant_errors_spec.rb +32 -0
  163. data/spec/requests/flows/implicit_grant_spec.rb +61 -0
  164. data/spec/requests/flows/password_spec.rb +115 -0
  165. data/spec/requests/flows/refresh_token_spec.rb +174 -0
  166. data/spec/requests/flows/revoke_token_spec.rb +157 -0
  167. data/spec/requests/flows/skip_authorization_spec.rb +59 -0
  168. data/spec/requests/protected_resources/metal_spec.rb +14 -0
  169. data/spec/requests/protected_resources/private_api_spec.rb +81 -0
  170. data/spec/routing/custom_controller_routes_spec.rb +71 -0
  171. data/spec/routing/default_routes_spec.rb +35 -0
  172. data/spec/routing/scoped_routes_spec.rb +31 -0
  173. data/spec/spec_helper.rb +2 -0
  174. data/spec/spec_helper_integration.rb +50 -0
  175. data/spec/stubs/config/application.rb +29 -0
  176. data/spec/stubs/config/initializers/db.rb +74 -0
  177. data/spec/stubs/generators/application_owner_generator_spec.rb +20 -0
  178. data/spec/stubs/generators/migration_generator_spec.rb +20 -0
  179. data/spec/stubs/generators/previous_refresh_token_generator_spec.rb +20 -0
  180. data/spec/stubs/generators/tmp/dummy/db/migrate/20161012132810_add_owner_to_application.rb +9 -0
  181. data/spec/stubs/models/user.rb +11 -0
  182. data/spec/stubs/spec_helper_integration.rb +50 -0
  183. data/spec/stubs/support/sequel.rb +0 -0
  184. data/spec/support/dependencies/factory_girl.rb +2 -0
  185. data/spec/support/helpers/access_token_request_helper.rb +11 -0
  186. data/spec/support/helpers/authorization_request_helper.rb +41 -0
  187. data/spec/support/helpers/config_helper.rb +9 -0
  188. data/spec/support/helpers/model_helper.rb +67 -0
  189. data/spec/support/helpers/request_spec_helper.rb +76 -0
  190. data/spec/support/helpers/url_helper.rb +55 -0
  191. data/spec/support/http_method_shim.rb +24 -0
  192. data/spec/support/orm/active_record.rb +3 -0
  193. data/spec/support/orm/sequel.rb +0 -0
  194. data/spec/support/shared/controllers_shared_context.rb +69 -0
  195. data/spec/support/shared/models_shared_examples.rb +52 -0
  196. data/spec/validators/redirect_uri_validator_spec.rb +78 -0
  197. metadata +570 -0
@@ -0,0 +1,11 @@
1
+ class SemiProtectedResourcesController < ApplicationController
2
+ before_action :doorkeeper_authorize!, only: :index
3
+
4
+ def index
5
+ render plain: 'protected index'
6
+ end
7
+
8
+ def show
9
+ render plain: 'non protected show'
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module ApplicationHelper
2
+ def current_user
3
+ @current_user ||= User.find_by_id(session[:user_id])
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class User < Sequel::Model
2
+ class << self
3
+ def authenticate!(name, password)
4
+ User.where(name: name, password: password).first
5
+ end
6
+
7
+ def create!(values = {}, &block)
8
+ new(values, &block).save(raise_on_failure: true)
9
+ end
10
+ end
11
+ end
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+ </head>
7
+ <body>
8
+
9
+ <%= link_to "Sign in", '/sign_in' %>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "rails"
4
+
5
+ %w(
6
+ action_controller
7
+ action_view
8
+ action_mailer
9
+ active_job
10
+ rails/test_unit
11
+ sprockets
12
+ ).each do |framework|
13
+ begin
14
+ require "#{framework}/railtie"
15
+ rescue LoadError
16
+ end
17
+ end
18
+
19
+ Bundler.require(*Rails.groups)
20
+
21
+ require 'yaml'
22
+
23
+ module Dummy
24
+ class Application < Rails::Application
25
+ # Settings in config/environments/* take precedence over those specified here.
26
+ # Application configuration should go into files in config/initializers
27
+ # -- all .rb files in that directory are automatically loaded.
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ orm = ENV['BUNDLE_GEMFILE'].match(/Gemfile\.(.+)\.rb/)
5
+ unless defined?(DOORKEEPER_ORM)
6
+ DOORKEEPER_ORM = (orm && orm[1]) || :active_record
7
+ end
8
+
9
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,15 @@
1
+ development:
2
+ adapter: sqlite3
3
+ database: db/development.sqlite3
4
+ pool: 5
5
+ timeout: 5000
6
+
7
+ test:
8
+ adapter: sqlite3
9
+ database: ":memory:"
10
+ timeout: 500
11
+
12
+ production:
13
+ adapter: sqlite3
14
+ database: ":memory:"
15
+ timeout: 500
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Rails.application.initialize!
@@ -0,0 +1,29 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Show full error reports and disable caching
10
+ config.consider_all_requests_local = true
11
+ config.action_controller.perform_caching = false
12
+
13
+ # Don't care if the mailer can't send
14
+ # config.action_mailer.raise_delivery_errors = false
15
+
16
+ # Print deprecation notices to the Rails logger
17
+ config.active_support.deprecation = :log
18
+
19
+ # Only use best-standards-support built into browsers
20
+ config.action_dispatch.best_standards_support = :builtin
21
+
22
+ # Do not compress assets
23
+ config.assets.compress = false
24
+
25
+ # Expands the lines which load the assets
26
+ config.assets.debug = true
27
+
28
+ config.eager_load = false
29
+ end
@@ -0,0 +1,62 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+ # Compress JavaScripts and CSS
15
+ config.assets.compress = true
16
+
17
+ # Don't fallback to assets pipeline if a precompiled asset is missed
18
+ config.assets.compile = false
19
+
20
+ # Generate digests for assets URLs
21
+ config.assets.digest = true
22
+
23
+ # Defaults to Rails.root.join("public/assets")
24
+ # config.assets.manifest = YOUR_PATH
25
+
26
+ # Specifies the header that your server uses for sending files
27
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
29
+
30
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31
+ # config.force_ssl = true
32
+
33
+ # See everything in the log (default is :info)
34
+ # config.log_level = :debug
35
+
36
+ # Use a different logger for distributed setups
37
+ # config.logger = SyslogLogger.new
38
+
39
+ # Use a different cache store in production
40
+ # config.cache_store = :mem_cache_store
41
+
42
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
43
+ # config.action_controller.asset_host = "http://assets.example.com"
44
+
45
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
46
+ # config.assets.precompile += %w( search.js )
47
+
48
+ # Disable delivery errors, bad email addresses will be ignored
49
+ # config.action_mailer.raise_delivery_errors = false
50
+
51
+ # Enable threaded mode
52
+ # config.threadsafe!
53
+
54
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
55
+ # the I18n.default_locale when a translation can not be found)
56
+ config.i18n.fallbacks = true
57
+
58
+ # Send deprecation notices to registered listeners
59
+ config.active_support.deprecation = :notify
60
+
61
+ config.eager_load = true
62
+ end
@@ -0,0 +1,44 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
14
+
15
+ # Show full error reports and disable caching
16
+ config.consider_all_requests_local = true
17
+ config.action_controller.perform_caching = false
18
+
19
+ # Raise exceptions instead of rendering exception templates
20
+ config.action_dispatch.show_exceptions = false
21
+
22
+ # Disable request forgery protection in test environment
23
+ config.action_controller.allow_forgery_protection = false
24
+
25
+ # Tell Action Mailer not to deliver emails to the real world.
26
+ # The :test delivery method accumulates sent emails in the
27
+ # ActionMailer::Base.deliveries array.
28
+ # config.action_mailer.delivery_method = :test
29
+
30
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
31
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
32
+ # like if you have constraints or database-specific column types
33
+ # config.active_record.schema_format = :sql
34
+
35
+ # Print deprecation notices to the stderr
36
+ config.active_support.deprecation = :stderr
37
+
38
+ config.eager_load = true
39
+
40
+ if DOORKEEPER_ORM == :active_record
41
+ config.active_record.table_name_prefix = TABLE_NAME_PREFIX.to_s
42
+ config.active_record.table_name_suffix = TABLE_NAME_SUFFIX.to_s
43
+ end
44
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,74 @@
1
+ # SQLite memory database
2
+ DB = if defined?(JRUBY_VERSION)
3
+ Sequel.connect('jdbc:sqlite::memory:')
4
+ else
5
+ Sequel.sqlite
6
+ end
7
+
8
+ DB.create_table :oauth_applications do
9
+ primary_key :id
10
+
11
+ column :name, String, size: 255, null: false
12
+ column :uid, String, size: 255, null: false, index: { unique: true }
13
+ column :secret, String, size: 255, null: false
14
+
15
+ column :scopes, String, size: 255, null: false, default: ''
16
+ column :redirect_uri, String
17
+
18
+ column :created_at, DateTime
19
+ column :updated_at, DateTime
20
+
21
+ column :owner_id, Integer
22
+ column :owner_type, String
23
+ index [:owner_id, :owner_type]
24
+ end
25
+
26
+ DB.create_table :oauth_access_grants do
27
+ primary_key :id
28
+ column :application_id, Integer
29
+
30
+ column :resource_owner_id, Integer, null: false
31
+
32
+ column :token, String, size: 255, null: false, index: { unique: true }
33
+ column :expires_in, Integer, null: false
34
+ column :redirect_uri, String, null: false
35
+ column :created_at, DateTime, null: false
36
+ column :revoked_at, DateTime
37
+ column :scopes, String, size: 255
38
+ end
39
+
40
+ DB.create_table :oauth_access_tokens do
41
+ primary_key :id
42
+ column :application_id, Integer
43
+
44
+ column :resource_owner_id, Integer, index: true
45
+
46
+ # If you use a custom token generator you may need to change this column
47
+ # from string to text, so that it accepts tokens larger than 255
48
+ # characters. More info on custom token generators in:
49
+ # https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator
50
+ #
51
+ # column :token, String, null: false
52
+ column :token, String, size: 255, null: false, index: { unique: true }
53
+
54
+ column :refresh_token, String, size: 255, index: { unique: true }
55
+ # If there is a previous_refresh_token column,
56
+ # refresh tokens will be revoked after a related access token is used.
57
+ # If there is no previous_refresh_token column,
58
+ # previous tokens are revoked as soon as a new access token is created.
59
+ # Comment out this line if you'd rather have refresh tokens
60
+ # instantly revoked.
61
+ column :previous_refresh_token, String, size: 255, null: false, default: ''
62
+ column :expires_in, Integer
63
+ column :revoked_at, DateTime
64
+ column :created_at, DateTime, null: false
65
+ column :scopes, String, size: 255
66
+ end
67
+
68
+ DB.create_table :users do
69
+ primary_key :id
70
+ column :name, String, size: 255
71
+ column :created_at, DateTime
72
+ column :updated_at, DateTime
73
+ column :password, String, size: 255
74
+ end
@@ -0,0 +1,96 @@
1
+ Doorkeeper.configure do
2
+ # Change the ORM that doorkeeper will use.
3
+ orm DOORKEEPER_ORM
4
+
5
+ # This block will be called to check whether the resource owner is authenticated or not.
6
+ resource_owner_authenticator do
7
+ # Put your resource owner authentication logic here.
8
+ User.where(id: session[:user_id]).first || redirect_to(root_url, alert: 'Needs sign in.')
9
+ end
10
+
11
+ # If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.
12
+ # admin_authenticator do
13
+ # # Put your admin authentication logic here.
14
+ # # Example implementation:
15
+ # Admin.find_by_id(session[:admin_id]) || redirect_to(new_admin_session_url)
16
+ # end
17
+
18
+ # Authorization Code expiration time (default 10 minutes).
19
+ # authorization_code_expires_in 10.minutes
20
+
21
+ # Access token expiration time (default 2 hours).
22
+ # If you want to disable expiration, set this to nil.
23
+ # access_token_expires_in 2.hours
24
+
25
+ # Reuse access token for the same resource owner within an application (disabled by default)
26
+ # Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383
27
+ # reuse_access_token
28
+
29
+ # Issue access tokens with refresh token (disabled by default)
30
+ use_refresh_token
31
+
32
+ # Provide support for an owner to be assigned to each registered application (disabled by default)
33
+ # Optional parameter confirmation: true (default false) if you want to enforce ownership of
34
+ # a registered application
35
+ # Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support
36
+ # enable_application_owner confirmation: false
37
+
38
+ # Define access token scopes for your provider
39
+ # For more information go to
40
+ # https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Scopes
41
+ default_scopes :public
42
+ optional_scopes :write, :update
43
+
44
+ # Change the way client credentials are retrieved from the request object.
45
+ # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
46
+ # falls back to the `:client_id` and `:client_secret` params from the `params` object.
47
+ # Check out the wiki for more information on customization
48
+ # client_credentials :from_basic, :from_params
49
+
50
+ # Change the way access token is authenticated from the request object.
51
+ # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
52
+ # falls back to the `:access_token` or `:bearer_token` params from the `params` object.
53
+ # Check out the wiki for more information on customization
54
+ # access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param
55
+
56
+ # Change the native redirect uri for client apps
57
+ # When clients register with the following redirect uri, they won't be redirected to any server and the authorization code will be displayed within the provider
58
+ # The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL
59
+ # (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi)
60
+ #
61
+ # native_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'
62
+
63
+ # Forces the usage of the HTTPS protocol in non-native redirect uris (enabled
64
+ # by default in non-development environments). OAuth2 delegates security in
65
+ # communication to the HTTPS protocol so it is wise to keep this enabled.
66
+ #
67
+ # force_ssl_in_redirect_uri !Rails.env.development?
68
+
69
+ # Specify what grant flows are enabled in array of Strings. The valid
70
+ # strings and the flows they enable are:
71
+ #
72
+ # "authorization_code" => Authorization Code Grant Flow
73
+ # "implicit" => Implicit Grant Flow
74
+ # "password" => Resource Owner Password Credentials Grant Flow
75
+ # "client_credentials" => Client Credentials Grant Flow
76
+ #
77
+ # If not specified, Doorkeeper enables authorization_code and
78
+ # client_credentials.
79
+ #
80
+ # implicit and password grant flows have risks that you should understand
81
+ # before enabling:
82
+ # http://tools.ietf.org/html/rfc6819#section-4.4.2
83
+ # http://tools.ietf.org/html/rfc6819#section-4.4.3
84
+ #
85
+ # grant_flows %w(authorization_code client_credentials)
86
+
87
+ # Under some circumstances you might want to have applications auto-approved,
88
+ # so that the user skips the authorization step.
89
+ # For example if dealing with a trusted application.
90
+ # skip_authorization do |resource_owner, client|
91
+ # client.superapp? or resource_owner.admin?
92
+ # end
93
+
94
+ # WWW-Authenticate Realm (default "Doorkeeper").
95
+ realm "Doorkeeper"
96
+ end
@@ -0,0 +1,9 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_key_base =
8
+ Dummy::Application.config.secret_token =
9
+ 'c00157b5a1bb6181792f0f4a8a080485de7bab9987e6cf159dc74c4f0573345c1bfa713b5d756e1491fc0b098567e8a619e2f8d268eda86a20a720d05d633780'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -0,0 +1,5 @@
1
+ en:
2
+ doorkeeper:
3
+ scopes:
4
+ public: "Access your public data"
5
+ write: "Update your data"
@@ -0,0 +1,52 @@
1
+ Rails.application.routes.draw do
2
+ use_doorkeeper
3
+ use_doorkeeper scope: 'scope'
4
+
5
+ scope 'inner_space' do
6
+ use_doorkeeper scope: 'scope' do
7
+ controllers authorizations: 'custom_authorizations',
8
+ tokens: 'custom_authorizations',
9
+ applications: 'custom_authorizations',
10
+ token_info: 'custom_authorizations'
11
+
12
+ as authorizations: 'custom_auth',
13
+ tokens: 'custom_token',
14
+ token_info: 'custom_token_info'
15
+ end
16
+ end
17
+
18
+ scope 'space' do
19
+ use_doorkeeper do
20
+ controllers authorizations: 'custom_authorizations',
21
+ tokens: 'custom_authorizations',
22
+ applications: 'custom_authorizations',
23
+ token_info: 'custom_authorizations'
24
+
25
+ as authorizations: 'custom_auth',
26
+ tokens: 'custom_token',
27
+ token_info: 'custom_token_info'
28
+ end
29
+ end
30
+
31
+ scope 'outer_space' do
32
+ use_doorkeeper do
33
+ controllers authorizations: 'custom_authorizations',
34
+ tokens: 'custom_authorizations',
35
+ token_info: 'custom_authorizations'
36
+
37
+ as authorizations: 'custom_auth',
38
+ tokens: 'custom_token',
39
+ token_info: 'custom_token_info'
40
+
41
+ skip_controllers :tokens, :applications, :token_info
42
+ end
43
+ end
44
+
45
+ get 'metal.json' => 'metal#index'
46
+
47
+ get '/callback', to: 'home#callback'
48
+ get '/sign_in', to: 'home#sign_in'
49
+ resources :semi_protected_resources
50
+ resources :full_protected_resources
51
+ root to: 'home#index'
52
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,9 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :name
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ class AddPasswordToUsers < ActiveRecord::Migration
2
+ def change
3
+ add_column :users, :password, :string
4
+ end
5
+ end
@@ -0,0 +1,60 @@
1
+ class CreateDoorkeeperTables < ActiveRecord::Migration
2
+ def change
3
+ create_table :oauth_applications do |t|
4
+ t.string :name, null: false
5
+ t.string :uid, null: false
6
+ t.string :secret, null: false
7
+ t.text :redirect_uri, null: false
8
+ t.string :scopes, null: false, default: ''
9
+ t.timestamps null: false
10
+ end
11
+
12
+ add_index :oauth_applications, :uid, unique: true
13
+
14
+ create_table :oauth_access_grants do |t|
15
+ t.integer :resource_owner_id, null: false
16
+ t.references :application, null: false
17
+ t.string :token, null: false
18
+ t.integer :expires_in, null: false
19
+ t.text :redirect_uri, null: false
20
+ t.datetime :created_at, null: false
21
+ t.datetime :revoked_at
22
+ t.string :scopes
23
+ end
24
+
25
+ add_index :oauth_access_grants, :token, unique: true
26
+ add_foreign_key(
27
+ :oauth_access_grants,
28
+ :oauth_applications,
29
+ column: :application_id,
30
+ )
31
+
32
+ create_table :oauth_access_tokens do |t|
33
+ t.integer :resource_owner_id
34
+ t.references :application
35
+
36
+ # If you use a custom token generator you may need to change this column
37
+ # from string to text, so that it accepts tokens larger than 255
38
+ # characters. More info on custom token generators in:
39
+ # https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator
40
+ #
41
+ # t.text :token, null: false
42
+ t.string :token, null: false
43
+
44
+ t.string :refresh_token
45
+ t.integer :expires_in
46
+ t.datetime :revoked_at
47
+ t.datetime :created_at, null: false
48
+ t.string :scopes
49
+ end
50
+
51
+ add_index :oauth_access_tokens, :token, unique: true
52
+ add_index :oauth_access_tokens, :resource_owner_id
53
+ add_index :oauth_access_tokens, :refresh_token, unique: true
54
+ add_foreign_key(
55
+ :oauth_access_tokens,
56
+ :oauth_applications,
57
+ column: :application_id,
58
+ )
59
+ end
60
+ end
@@ -0,0 +1,7 @@
1
+ class AddOwnerToApplication < ActiveRecord::Migration
2
+ def change
3
+ add_column :oauth_applications, :owner_id, :integer, null: true
4
+ add_column :oauth_applications, :owner_type, :string, null: true
5
+ add_index :oauth_applications, [:owner_id, :owner_type]
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ class AddPreviousRefreshTokenToAccessTokens < ActiveRecord::Migration
2
+ def change
3
+ add_column(
4
+ :oauth_access_tokens,
5
+ :previous_refresh_token,
6
+ :string,
7
+ default: "",
8
+ null: false
9
+ )
10
+ end
11
+ end