PageRenderTime 23ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/config/initializers/doorkeeper.rb

https://gitlab.com/18dit020/gitlab
Ruby | 123 lines | 35 code | 21 blank | 67 comment | 1 complexity | e85a84190eb7013e02b84ff3f2e85636 MD5 | raw file
  1. # frozen_string_literal: true
  2. Doorkeeper.configure do
  3. # Change the ORM that doorkeeper will use.
  4. # Currently supported options are :active_record, :mongoid2, :mongoid3, :mongo_mapper
  5. orm :active_record
  6. # Restore to pre-5.1 generator due to breaking change.
  7. # See https://gitlab.com/gitlab-org/gitlab/-/issues/244371
  8. default_generator_method :hex
  9. # This block will be called to check whether the resource owner is authenticated or not.
  10. resource_owner_authenticator do
  11. # Put your resource owner authentication logic here.
  12. if current_user
  13. current_user
  14. else
  15. # Ensure user is redirected to redirect_uri after login
  16. session[:user_return_to] = request.fullpath
  17. redirect_to(new_user_session_url)
  18. nil
  19. end
  20. end
  21. resource_owner_from_credentials do |routes|
  22. user = Gitlab::Auth.find_with_user_password(params[:username], params[:password], increment_failed_attempts: true)
  23. user unless user.try(:two_factor_enabled?)
  24. end
  25. # If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.
  26. # admin_authenticator do
  27. # # Put your admin authentication logic here.
  28. # # Example implementation:
  29. # Admin.find_by_id(session[:admin_id]) || redirect_to(new_admin_session_url)
  30. # end
  31. # Authorization Code expiration time (default 10 minutes).
  32. # authorization_code_expires_in 10.minutes
  33. # Access token expiration time (default 2 hours).
  34. # Until 15.0, applications can opt-out of expiring tokens.
  35. # Removal issue: https://gitlab.com/gitlab-org/gitlab/-/issues/340848
  36. custom_access_token_expires_in do |context|
  37. context.client&.expire_access_tokens ? 2.hours : Float::INFINITY
  38. end
  39. # Reuse access token for the same resource owner within an application (disabled by default)
  40. # Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383
  41. reuse_access_token
  42. # Issue access tokens with refresh token (disabled by default)
  43. use_refresh_token
  44. # Forbids creating/updating applications with arbitrary scopes that are
  45. # not in configuration, i.e. `default_scopes` or `optional_scopes`.
  46. # (disabled by default)
  47. enforce_configured_scopes
  48. # Forces the usage of the HTTPS protocol in non-native redirect uris (enabled
  49. # by default in non-development environments). OAuth2 delegates security in
  50. # communication to the HTTPS protocol so it is wise to keep this enabled.
  51. #
  52. force_ssl_in_redirect_uri false
  53. # Specify what redirect URI's you want to block during Application creation.
  54. # Any redirect URI is whitelisted by default.
  55. #
  56. # You can use this option in order to forbid URI's with 'javascript' scheme
  57. # for example.
  58. forbid_redirect_uri { |uri| %w[data vbscript javascript].include?(uri.scheme.to_s.downcase) }
  59. # Provide support for an owner to be assigned to each registered application (disabled by default)
  60. # Optional parameter confirmation: true (default false) if you want to enforce ownership of
  61. # a registered application
  62. # Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support
  63. enable_application_owner confirmation: false
  64. # Define access token scopes for your provider
  65. # For more information go to
  66. # https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Scopes
  67. default_scopes(*Gitlab::Auth::DEFAULT_SCOPES)
  68. optional_scopes(*Gitlab::Auth.optional_scopes)
  69. # Change the way client credentials are retrieved from the request object.
  70. # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
  71. # falls back to the `:client_id` and `:client_secret` params from the `params` object.
  72. # Check out the wiki for more information on customization
  73. # client_credentials :from_basic, :from_params
  74. # Change the way access token is authenticated from the request object.
  75. # By default it retrieves first from the `HTTP_AUTHORIZATION` header, then
  76. # falls back to the `:access_token` or `:bearer_token` params from the `params` object.
  77. # Check out the wiki for more information on customization
  78. access_token_methods :from_access_token_param, :from_bearer_authorization, :from_bearer_param
  79. # Specify what grant flows are enabled in array of Strings. The valid
  80. # strings and the flows they enable are:
  81. #
  82. # "authorization_code" => Authorization Code Grant Flow
  83. # "implicit" => Implicit Grant Flow
  84. # "password" => Resource Owner Password Credentials Grant Flow
  85. # "client_credentials" => Client Credentials Grant Flow
  86. #
  87. grant_flows %w(authorization_code implicit password client_credentials)
  88. # Under some circumstances you might want to have applications auto-approved,
  89. # so that the user skips the authorization step.
  90. # For example if dealing with trusted a application.
  91. skip_authorization do |resource_owner, client|
  92. client.application.trusted?
  93. end
  94. # WWW-Authenticate Realm (default "Doorkeeper").
  95. # realm "Doorkeeper"
  96. base_controller '::Gitlab::BaseDoorkeeperController'
  97. # Allow Resource Owner Password Credentials Grant without client credentials,
  98. # this was disabled by default in Doorkeeper 5.5.
  99. #
  100. # We might want to disable this in the future, see https://gitlab.com/gitlab-org/gitlab/-/issues/323615
  101. skip_client_authentication_for_password_grant true
  102. end