doorkeeper.rb 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. resource_owner_from_credentials do |_routes|
  10. user = User.authenticate_with_ldap(email: request.params[:username], password: request.params[:password]) if Devise.ldap_authentication
  11. user ||= User.authenticate_with_pam(email: request.params[:username], password: request.params[:password]) if Devise.pam_authentication
  12. if user.nil?
  13. user = User.find_by(email: request.params[:username])
  14. user = nil unless user&.valid_password?(request.params[:password])
  15. end
  16. user unless user&.otp_required_for_login?
  17. end
  18. # If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.
  19. admin_authenticator do
  20. current_user&.admin? || redirect_to(new_user_session_url)
  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 :write,
  57. :'write:accounts',
  58. :'write:blocks',
  59. :'write:bookmarks',
  60. :'write:conversations',
  61. :'write:favourites',
  62. :'write:filters',
  63. :'write:follows',
  64. :'write:lists',
  65. :'write:media',
  66. :'write:mutes',
  67. :'write:notifications',
  68. :'write:reports',
  69. :'write:statuses',
  70. :read,
  71. :'read:accounts',
  72. :'read:blocks',
  73. :'read:bookmarks',
  74. :'read:favourites',
  75. :'read:filters',
  76. :'read:follows',
  77. :'read:lists',
  78. :'read:mutes',
  79. :'read:notifications',
  80. :'read:search',
  81. :'read:statuses',
  82. :follow,
  83. :push,
  84. :'admin:read',
  85. :'admin:read:accounts',
  86. :'admin:read:reports',
  87. :'admin:read:domain_allows',
  88. :'admin:read:domain_blocks',
  89. :'admin:read:ip_blocks',
  90. :'admin:read:email_domain_blocks',
  91. :'admin:read:canonical_email_blocks',
  92. :'admin:write',
  93. :'admin:write:accounts',
  94. :'admin:write:reports',
  95. :'admin:write:domain_allows',
  96. :'admin:write:domain_blocks',
  97. :'admin:write:ip_blocks',
  98. :'admin:write:email_domain_blocks',
  99. :'admin:write:canonical_email_blocks',
  100. :crypto
  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 whitelisted 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 password 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