The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

154 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. 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. # Provide support for an owner to be assigned to each registered application (disabled by default)
  43. # Optional parameter :confirmation => true (default false) if you want to enforce ownership of
  44. # a registered application
  45. # Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support
  46. enable_application_owner
  47. # Define access token scopes for your provider
  48. # For more information go to
  49. # https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Scopes
  50. default_scopes :read
  51. optional_scopes :write,
  52. :'write:accounts',
  53. :'write:blocks',
  54. :'write:bookmarks',
  55. :'write:conversations',
  56. :'write:favourites',
  57. :'write:filters',
  58. :'write:follows',
  59. :'write:lists',
  60. :'write:media',
  61. :'write:mutes',
  62. :'write:notifications',
  63. :'write:reports',
  64. :'write:statuses',
  65. :read,
  66. :'read:accounts',
  67. :'read:blocks',
  68. :'read:bookmarks',
  69. :'read:favourites',
  70. :'read:filters',
  71. :'read:follows',
  72. :'read:lists',
  73. :'read:mutes',
  74. :'read:notifications',
  75. :'read:search',
  76. :'read:statuses',
  77. :follow,
  78. :push,
  79. :'admin:read',
  80. :'admin:read:accounts',
  81. :'admin:read:reports',
  82. :'admin:write',
  83. :'admin:write:accounts',
  84. :'admin:write:reports'
  85. # Change the way client credentials are retrieved from the request object.
  86. # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
  87. # falls back to the `:client_id` and `:client_secret` params from the `params` object.
  88. # Check out the wiki for more information on customization
  89. # client_credentials :from_basic, :from_params
  90. # Change the way access token is authenticated from the request object.
  91. # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
  92. # falls back to the `:access_token` or `:bearer_token` params from the `params` object.
  93. # Check out the wiki for more information on customization
  94. # access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param
  95. # Change the native redirect uri for client apps
  96. # 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
  97. # The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL
  98. # (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi)
  99. #
  100. # native_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'
  101. # Forces the usage of the HTTPS protocol in non-native redirect uris (enabled
  102. # by default in non-development environments). OAuth2 delegates security in
  103. # communication to the HTTPS protocol so it is wise to keep this enabled.
  104. #
  105. force_ssl_in_redirect_uri false
  106. # Specify what grant flows are enabled in array of Strings. The valid
  107. # strings and the flows they enable are:
  108. #
  109. # "authorization_code" => Authorization Code Grant Flow
  110. # "implicit" => Implicit Grant Flow
  111. # "password" => Resource Owner Password Credentials Grant Flow
  112. # "client_credentials" => Client Credentials Grant Flow
  113. #
  114. # If not specified, Doorkeeper enables authorization_code and
  115. # client_credentials.
  116. #
  117. # implicit and password grant flows have risks that you should understand
  118. # before enabling:
  119. # http://tools.ietf.org/html/rfc6819#section-4.4.2
  120. # http://tools.ietf.org/html/rfc6819#section-4.4.3
  121. #
  122. grant_flows %w(authorization_code password client_credentials)
  123. # Under some circumstances you might want to have applications auto-approved,
  124. # so that the user skips the authorization step.
  125. # For example if dealing with a trusted application.
  126. skip_authorization do |resource_owner, client|
  127. client.application.superapp?
  128. end
  129. # WWW-Authenticate Realm (default "Doorkeeper").
  130. # realm "Doorkeeper"
  131. end