doorkeeper.rb 6.9 KB

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