class Doorkeeper::Config

Doorkeeper option DSL could be reused in extensions to build their own configurations. To use the Option DSL gems need to define ‘builder_class` method that returns configuration Builder class. This exception raises when they don’t define it.

Attributes

application_secret_fallback_strategy[R]
reuse_access_token[R]
token_secret_fallback_strategy[R]

Public Instance Methods

access_grant_model() click to toggle source

Doorkeeper Access Grant model class.

@return [ActiveRecord::Base, Mongoid::Document, Sequel::Model]

# File lib/doorkeeper/config.rb, line 465
def access_grant_model
  @access_grant_model ||= access_grant_class.constantize
end
access_token_methods() click to toggle source
# File lib/doorkeeper/config.rb, line 586
def access_token_methods
  @access_token_methods ||= %i[
    from_bearer_authorization
    from_access_token_param
    from_bearer_param
  ]
end
access_token_model() click to toggle source

Doorkeeper Access Token model class.

@return [ActiveRecord::Base, Mongoid::Document, Sequel::Model]

# File lib/doorkeeper/config.rb, line 457
def access_token_model
  @access_token_model ||= access_token_class.constantize
end
allow_blank_redirect_uri?(application = nil) click to toggle source
# File lib/doorkeeper/config.rb, line 672
def allow_blank_redirect_uri?(application = nil)
  if allow_blank_redirect_uri.respond_to?(:call)
    allow_blank_redirect_uri.call(grant_flows, application)
  else
    allow_blank_redirect_uri
  end
end
allow_grant_flow_for_client?(grant_flow, client) click to toggle source
# File lib/doorkeeper/config.rb, line 680
def allow_grant_flow_for_client?(grant_flow, client)
  return true unless option_defined?(:allow_grant_flow_for_client)

  allow_grant_flow_for_client.call(grant_flow, client)
end
api_only() click to toggle source
# File lib/doorkeeper/config.rb, line 477
def api_only
  @api_only ||= false
end
application_model() click to toggle source

Doorkeeper Application model class.

@return [ActiveRecord::Base, Mongoid::Document, Sequel::Model]

# File lib/doorkeeper/config.rb, line 473
def application_model
  @application_model ||= application_class.constantize
end
application_secret_hashed?() click to toggle source
# File lib/doorkeeper/config.rb, line 548
def application_secret_hashed?
  instance_variable_defined?(:"@application_secret_strategy")
end
application_secret_strategy() click to toggle source
# File lib/doorkeeper/config.rb, line 556
def application_secret_strategy
  @application_secret_strategy ||= ::Doorkeeper::SecretStoring::Plain
end
authorization_response_flows() click to toggle source
# File lib/doorkeeper/config.rb, line 598
def authorization_response_flows
  @authorization_response_flows ||= enabled_grant_flows.select(&:handles_response_type?) +
                                    deprecated_authorization_flows
end
authorization_response_types() click to toggle source
# File lib/doorkeeper/config.rb, line 607
def authorization_response_types
  authorization_response_flows.map(&:response_type_matches)
end
calculate_authorization_response_types() click to toggle source

[NOTE]: deprecated and will be removed soon

# File lib/doorkeeper/config.rb, line 643
def calculate_authorization_response_types
  []
end
calculate_grant_flows() click to toggle source

Calculates grant flows configured by the user in Doorkeeper configuration considering registered aliases that is exposed to single or multiple other flows.

# File lib/doorkeeper/config.rb, line 658
def calculate_grant_flows
  configured_flows = grant_flows.map(&:to_s)
  aliases = Doorkeeper::GrantFlow.aliases.keys.map(&:to_s)

  flows = configured_flows - aliases
  aliases.each do |flow_alias|
    next unless configured_flows.include?(flow_alias)

    flows.concat(Doorkeeper::GrantFlow.expand_alias(flow_alias))
  end

  flows.flatten.uniq
end
calculate_token_grant_types() click to toggle source

[NOTE]: deprecated and will be removed soon

# File lib/doorkeeper/config.rb, line 648
def calculate_token_grant_types
  types = grant_flows - ["implicit"]
  types << "refresh_token" if refresh_token_enabled?
  types
end
clear_cache!() click to toggle source
# File lib/doorkeeper/config.rb, line 443
def clear_cache!
  %i[
    application_model
    access_token_model
    access_grant_model
  ].each do |var|
    remove_instance_variable("@#{var}") if instance_variable_defined?("@#{var}")
  end
end
client_credentials_methods() click to toggle source
# File lib/doorkeeper/config.rb, line 582
def client_credentials_methods
  @client_credentials_methods ||= %i[from_basic from_params]
end
confirm_application_owner?() click to toggle source
# File lib/doorkeeper/config.rb, line 536
def confirm_application_owner?
  option_set? :confirm_application_owner
end
default_scopes() click to toggle source
# File lib/doorkeeper/config.rb, line 560
def default_scopes
  @default_scopes ||= OAuth::Scopes.new
end
deprecated_authorization_flows() click to toggle source

[NOTE]: deprecated and will be removed soon

# File lib/doorkeeper/config.rb, line 626
    def deprecated_authorization_flows
      response_types = calculate_authorization_response_types

      if response_types.any?
        ::Kernel.warn <<~WARNING
          Please, don't patch Doorkeeper::Config#calculate_authorization_response_types method.
          Register your custom grant flows using the public API:
          `Doorkeeper::GrantFlow.register(grant_flow_name, **options)`.
        WARNING
      end

      response_types.map do |response_type|
        Doorkeeper::GrantFlow::FallbackFlow.new(response_type, response_type_matches: response_type)
      end
    end
deprecated_token_grant_types_resolver() click to toggle source

[NOTE]: deprecated and will be removed soon

# File lib/doorkeeper/config.rb, line 616
def deprecated_token_grant_types_resolver
  @deprecated_token_grant_types ||= calculate_token_grant_types
end
dynamic_scopes_delimiter() click to toggle source
# File lib/doorkeeper/config.rb, line 528
def dynamic_scopes_delimiter
  @dynamic_scopes_delimiter
end
enable_application_owner?() click to toggle source
# File lib/doorkeeper/config.rb, line 520
def enable_application_owner?
  option_set? :enable_application_owner
end
enable_dynamic_scopes?() click to toggle source
# File lib/doorkeeper/config.rb, line 524
def enable_dynamic_scopes?
  option_set? :enable_dynamic_scopes
end
enabled_grant_flows() click to toggle source
# File lib/doorkeeper/config.rb, line 594
def enabled_grant_flows
  @enabled_grant_flows ||= calculate_grant_flows.map { |name| Doorkeeper::GrantFlow.get(name) }.compact
end
enforce_configured_scopes?() click to toggle source
# File lib/doorkeeper/config.rb, line 516
def enforce_configured_scopes?
  option_set? :enforce_configured_scopes
end
enforce_content_type() click to toggle source
# File lib/doorkeeper/config.rb, line 481
def enforce_content_type
  @enforce_content_type ||= false
end
force_pkce?() click to toggle source
# File lib/doorkeeper/config.rb, line 512
def force_pkce?
  option_set? :force_pkce
end
native_authorization_code_route() click to toggle source
# File lib/doorkeeper/config.rb, line 620
def native_authorization_code_route
  @use_url_path_for_native_authorization = false unless defined?(@use_url_path_for_native_authorization)
  @use_url_path_for_native_authorization ? '/:code' : '/native'
end
option_defined?(name) click to toggle source
# File lib/doorkeeper/config.rb, line 686
def option_defined?(name)
  instance_variable_defined?("@#{name}")
end
optional_scopes() click to toggle source
# File lib/doorkeeper/config.rb, line 564
def optional_scopes
  @optional_scopes ||= OAuth::Scopes.new
end
pkce_code_challenge_methods_supported() click to toggle source
# File lib/doorkeeper/config.rb, line 576
def pkce_code_challenge_methods_supported
  return [] unless access_grant_model.pkce_supported?
  
  pkce_code_challenge_methods
end
polymorphic_resource_owner?() click to toggle source
# File lib/doorkeeper/config.rb, line 532
def polymorphic_resource_owner?
  option_set? :polymorphic_resource_owner
end
raise_on_errors?() click to toggle source
# File lib/doorkeeper/config.rb, line 540
def raise_on_errors?
  handle_auth_errors == :raise
end
redirect_on_errors?() click to toggle source
# File lib/doorkeeper/config.rb, line 544
def redirect_on_errors?
  handle_auth_errors == :redirect
end
refresh_token_enabled?() click to toggle source
# File lib/doorkeeper/config.rb, line 485
def refresh_token_enabled?
  if defined?(@refresh_token_enabled)
    @refresh_token_enabled
  else
    false
  end
end
resolve_controller(name) click to toggle source
# File lib/doorkeeper/config.rb, line 493
def resolve_controller(name)
  config_option = public_send(:"#{name}_controller")
  controller_name = if config_option.respond_to?(:call)
                      instance_exec(&config_option)
                    else
                      config_option
                    end

  controller_name.constantize
end
revoke_previous_authorization_code_token?() click to toggle source
# File lib/doorkeeper/config.rb, line 508
def revoke_previous_authorization_code_token?
  option_set? :revoke_previous_authorization_code_token
end
revoke_previous_client_credentials_token?() click to toggle source
# File lib/doorkeeper/config.rb, line 504
def revoke_previous_client_credentials_token?
  option_set? :revoke_previous_client_credentials_token
end
scopes() click to toggle source
# File lib/doorkeeper/config.rb, line 568
def scopes
  @scopes ||= default_scopes + optional_scopes
end
scopes_by_grant_type() click to toggle source
# File lib/doorkeeper/config.rb, line 572
def scopes_by_grant_type
  @scopes_by_grant_type ||= {}
end
token_grant_flows() click to toggle source
# File lib/doorkeeper/config.rb, line 603
def token_grant_flows
  @token_grant_flows ||= calculate_token_grant_flows
end
token_grant_types() click to toggle source
# File lib/doorkeeper/config.rb, line 611
def token_grant_types
  token_grant_flows.map(&:grant_type_matches)
end
token_secret_strategy() click to toggle source
# File lib/doorkeeper/config.rb, line 552
def token_secret_strategy
  @token_secret_strategy ||= ::Doorkeeper::SecretStoring::Plain
end

Private Instance Methods

calculate_token_grant_flows() click to toggle source
# File lib/doorkeeper/config.rb, line 698
def calculate_token_grant_flows
  flows = enabled_grant_flows.select(&:handles_grant_type?)
  flows << Doorkeeper::GrantFlow.get("refresh_token") if refresh_token_enabled?
  flows
end
option_set?(instance_key) click to toggle source

Helper to read boolearized configuration option

# File lib/doorkeeper/config.rb, line 693
def option_set?(instance_key)
  var = instance_variable_get("@#{instance_key}")
  !!(defined?(var) && var)
end