You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
6.4 KiB

  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. if Devise.ldap_authentication
  10. user = User.authenticate_with_ldap({ :email => request.params[:username], :password => request.params[:password] })
  11. end
  12. if Devise.pam_authentication
  13. user ||= User.authenticate_with_ldap({ :email => request.params[:username], :password => request.params[:password] })
  14. end
  15. if user.nil?
  16. user = User.find_by(email: request.params[:username])
  17. user = nil unless user.valid_password?(request.params[:password])
  18. end
  19. user if !user&.otp_required_for_login?
  20. end
  21. # If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.
  22. admin_authenticator do
  23. current_user&.admin? || redirect_to(new_user_session_url)
  24. end
  25. # Authorization Code expiration time (default 10 minutes).
  26. # authorization_code_expires_in 10.minutes
  27. # Access token expiration time (default 2 hours).
  28. # If you want to disable expiration, set this to nil.
  29. access_token_expires_in nil
  30. # Assign a custom TTL for implicit grants.
  31. # custom_access_token_expires_in do |oauth_client|
  32. # oauth_client.application.additional_settings.implicit_oauth_expiration
  33. # end
  34. # Use a custom class for generating the access token.
  35. # https://github.com/doorkeeper-gem/doorkeeper#custom-access-token-generator
  36. # access_token_generator "::Doorkeeper::JWT"
  37. # The controller Doorkeeper::ApplicationController inherits from.
  38. # Defaults to ActionController::Base.
  39. # https://github.com/doorkeeper-gem/doorkeeper#custom-base-controller
  40. base_controller 'ApplicationController'
  41. # Reuse access token for the same resource owner within an application (disabled by default)
  42. # Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383
  43. reuse_access_token
  44. # Issue access tokens with refresh token (disabled by default)
  45. # use_refresh_token
  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. # Change the way client credentials are retrieved from the request object.
  90. # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
  91. # falls back to the `:client_id` and `:client_secret` params from the `params` object.
  92. # Check out the wiki for more information on customization
  93. # client_credentials :from_basic, :from_params
  94. # Change the way access token is authenticated from the request object.
  95. # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
  96. # falls back to the `:access_token` or `:bearer_token` params from the `params` object.
  97. # Check out the wiki for more information on customization
  98. # access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param
  99. # Change the native redirect uri for client apps
  100. # 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
  101. # The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL
  102. # (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi)
  103. #
  104. # native_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'
  105. # Forces the usage of the HTTPS protocol in non-native redirect uris (enabled
  106. # by default in non-development environments). OAuth2 delegates security in
  107. # communication to the HTTPS protocol so it is wise to keep this enabled.
  108. #
  109. force_ssl_in_redirect_uri false
  110. # Specify what grant flows are enabled in array of Strings. The valid
  111. # strings and the flows they enable are:
  112. #
  113. # "authorization_code" => Authorization Code Grant Flow
  114. # "implicit" => Implicit Grant Flow
  115. # "password" => Resource Owner Password Credentials Grant Flow
  116. # "client_credentials" => Client Credentials Grant Flow
  117. #
  118. # If not specified, Doorkeeper enables authorization_code and
  119. # client_credentials.
  120. #
  121. # implicit and password grant flows have risks that you should understand
  122. # before enabling:
  123. # http://tools.ietf.org/html/rfc6819#section-4.4.2
  124. # http://tools.ietf.org/html/rfc6819#section-4.4.3
  125. #
  126. grant_flows %w(authorization_code password client_credentials)
  127. # Under some circumstances you might want to have applications auto-approved,
  128. # so that the user skips the authorization step.
  129. # For example if dealing with a trusted application.
  130. skip_authorization do |resource_owner, client|
  131. client.application.superapp?
  132. end
  133. # WWW-Authenticate Realm (default "Doorkeeper").
  134. # realm "Doorkeeper"
  135. end