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.

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