doorkeeper.rb 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. # frozen_string_literal: true
  2. Doorkeeper.configure do
  3. # Change the ORM that doorkeeper will use (needs plugins)
  4. orm :active_record
  5. # This block will be called to check whether the resource owner is authenticated or not.
  6. resource_owner_authenticator do
  7. current_user || redirect_to(new_user_session_url)
  8. end
  9. # Disable Resource Owner Password Credentials Grant Flow
  10. resource_owner_from_credentials do
  11. nil
  12. end
  13. # Doorkeeper provides some administrative interfaces for managing OAuth
  14. # Applications, allowing creation, edit, and deletion of applications from the
  15. # server. At present, these administrative routes are not integrated into
  16. # Mastodon, and as such, we've disabled them by always return a 403 forbidden
  17. # response for them. This does not affect the ability for users to manage
  18. # their own OAuth Applications.
  19. admin_authenticator do
  20. head 403
  21. end
  22. # Authorization Code expiration time (default 10 minutes).
  23. # authorization_code_expires_in 10.minutes
  24. # Access token expiration time (default 2 hours).
  25. # If you want to disable expiration, set this to nil.
  26. access_token_expires_in nil
  27. # Assign a custom TTL for implicit grants.
  28. # custom_access_token_expires_in do |oauth_client|
  29. # oauth_client.application.additional_settings.implicit_oauth_expiration
  30. # end
  31. # Use a custom class for generating the access token.
  32. # https://github.com/doorkeeper-gem/doorkeeper#custom-access-token-generator
  33. # access_token_generator "::Doorkeeper::JWT"
  34. # The controller Doorkeeper::ApplicationController inherits from.
  35. # Defaults to ActionController::Base.
  36. # https://github.com/doorkeeper-gem/doorkeeper#custom-base-controller
  37. base_controller 'ApplicationController'
  38. # Reuse access token for the same resource owner within an application (disabled by default)
  39. # Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383
  40. reuse_access_token
  41. # Issue access tokens with refresh token (disabled by default)
  42. # use_refresh_token
  43. # Forbids creating/updating applications with arbitrary scopes that are
  44. # not in configuration, i.e. `default_scopes` or `optional_scopes`.
  45. # (Disabled by default)
  46. enforce_configured_scopes
  47. # Provide support for an owner to be assigned to each registered application (disabled by default)
  48. # Optional parameter :confirmation => true (default false) if you want to enforce ownership of
  49. # a registered application
  50. # Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support
  51. enable_application_owner
  52. # Define access token scopes for your provider
  53. # For more information go to
  54. # https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Scopes
  55. default_scopes :read
  56. optional_scopes :profile,
  57. :write,
  58. :'write:accounts',
  59. :'write:blocks',
  60. :'write:bookmarks',
  61. :'write:conversations',
  62. :'write:favourites',
  63. :'write:filters',
  64. :'write:follows',
  65. :'write:lists',
  66. :'write:media',
  67. :'write:mutes',
  68. :'write:notifications',
  69. :'write:reports',
  70. :'write:statuses',
  71. :read,
  72. :'read:accounts',
  73. :'read:blocks',
  74. :'read:bookmarks',
  75. :'read:favourites',
  76. :'read:filters',
  77. :'read:follows',
  78. :'read:lists',
  79. :'read:mutes',
  80. :'read:notifications',
  81. :'read:search',
  82. :'read:statuses',
  83. :follow,
  84. :push,
  85. :'admin:read',
  86. :'admin:read:accounts',
  87. :'admin:read:reports',
  88. :'admin:read:domain_allows',
  89. :'admin:read:domain_blocks',
  90. :'admin:read:ip_blocks',
  91. :'admin:read:email_domain_blocks',
  92. :'admin:read:canonical_email_blocks',
  93. :'admin:write',
  94. :'admin:write:accounts',
  95. :'admin:write:reports',
  96. :'admin:write:domain_allows',
  97. :'admin:write:domain_blocks',
  98. :'admin:write:ip_blocks',
  99. :'admin:write:email_domain_blocks',
  100. :'admin:write:canonical_email_blocks'
  101. # Change the way client credentials are retrieved from the request object.
  102. # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
  103. # falls back to the `:client_id` and `:client_secret` params from the `params` object.
  104. # Check out the wiki for more information on customization
  105. # client_credentials :from_basic, :from_params
  106. # Change the way access token is authenticated from the request object.
  107. # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
  108. # falls back to the `:access_token` or `:bearer_token` params from the `params` object.
  109. # Check out the wiki for more information on customization
  110. # access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param
  111. # Change the native redirect uri for client apps
  112. # 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
  113. # The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL
  114. # (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi)
  115. #
  116. # native_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'
  117. # Forces the usage of the HTTPS protocol in non-native redirect uris (enabled
  118. # by default in non-development environments). OAuth2 delegates security in
  119. # communication to the HTTPS protocol so it is wise to keep this enabled.
  120. #
  121. force_ssl_in_redirect_uri false
  122. # Specify what redirect URI's you want to block during Application creation.
  123. # Any redirect URI is allowed by default.
  124. #
  125. # You can use this option in order to forbid URI's with 'javascript' scheme
  126. # for example.
  127. forbid_redirect_uri { |uri| %w(data vbscript javascript).include?(uri.scheme.to_s.downcase) }
  128. # Specify what grant flows are enabled in array of Strings. The valid
  129. # strings and the flows they enable are:
  130. #
  131. # "authorization_code" => Authorization Code Grant Flow
  132. # "implicit" => Implicit Grant Flow
  133. # "password" => Resource Owner Password Credentials Grant Flow
  134. # "client_credentials" => Client Credentials Grant Flow
  135. #
  136. # If not specified, Doorkeeper enables authorization_code and
  137. # client_credentials.
  138. #
  139. # implicit and password grant flows have risks that you should understand
  140. # before enabling:
  141. # http://tools.ietf.org/html/rfc6819#section-4.4.2
  142. # http://tools.ietf.org/html/rfc6819#section-4.4.3
  143. #
  144. grant_flows %w(authorization_code client_credentials)
  145. # Under some circumstances you might want to have applications auto-approved,
  146. # so that the user skips the authorization step.
  147. # For example if dealing with a trusted application.
  148. skip_authorization do |_resource_owner, client|
  149. client.application.superapp?
  150. end
  151. # WWW-Authenticate Realm (default "Doorkeeper").
  152. # realm "Doorkeeper"
  153. end