Module: OAuth2

Defined in:
lib/oauth2.rb,
lib/oauth2/error.rb,
lib/oauth2/client.rb,
lib/oauth2/version.rb,
lib/oauth2/response.rb,
lib/oauth2/access_token.rb,
lib/oauth2/authenticator.rb,
lib/oauth2/strategy/base.rb,
lib/oauth2/auth_sanitizer.rb,
lib/oauth2/strategy/implicit.rb,
lib/oauth2/strategy/password.rb,
lib/oauth2/strategy/assertion.rb,
lib/oauth2/strategy/auth_code.rb,
lib/oauth2/filtered_attributes.rb,
lib/oauth2/strategy/client_credentials.rb

Overview

:nocov:

Defined Under Namespace

Modules: Strategy, Version Classes: AccessToken, Authenticator, Client, Error, Response

Constant Summary collapse

OAUTH_DEBUG =

When true, enables verbose HTTP logging via Faraday’s logger middleware. Controlled by the OAUTH_DEBUG environment variable. Any case-insensitive value equal to “true” will enable debugging.

Returns:

  • (Boolean)
ENV.fetch("OAUTH_DEBUG", "false").casecmp("true").zero?
DEFAULT_CONFIG =

Default configuration values for the oauth2 library.

Existing objects and logger wrappers snapshot filtering configuration during initialization. Changing these config values later affects only newly initialized objects and debug loggers.

Examples:

Toggle warnings

OAuth2.configure do |config|
  config[:silence_extra_tokens_warning] = false
  config[:silence_no_tokens_warning] = false
end

Customize filtered output markers and debug-log value filtering by key name

OAuth2.configure do |config|
  config[:filtered_label] = "[REDACTED]"
  config[:filtered_debug_keys] += ["client_assertion"]
end

Returns:

  • (SnakyHash::SymbolKeyed)

    A mutable Hash-like config with symbol keys

SnakyHash::SymbolKeyed.new(
  silence_extra_tokens_warning: true,
  silence_no_tokens_warning: true,
  filtered_label: "[FILTERED]",
  filtered_debug_keys: %w[
    access_token
    refresh_token
    id_token
    client_secret
    assertion
    code_verifier
    token
  ],
)
CONFIG =

The current runtime configuration for the library.

Returns:

  • (SnakyHash::SymbolKeyed)
DEFAULT_CONFIG.dup
ConnectionError =
Class.new(Faraday::ConnectionFailed)
TimeoutError =
Class.new(Faraday::TimeoutError)
VERSION =

Traditional Constant Location

Version::VERSION
AUTH_SANITIZER =
begin
  auth_sanitizer_requirement = Gem::Requirement.new("~> 0.1", ">= 0.1.3")
  auth_sanitizer_spec = Gem.loaded_specs["auth-sanitizer"]
  unless auth_sanitizer_spec && auth_sanitizer_requirement.satisfied_by?(auth_sanitizer_spec.version)
    # :nocov:
    auth_sanitizer_spec = Gem::Specification.find_by_name("auth-sanitizer", auth_sanitizer_requirement)
    # :nocov:
  end

  auth_sanitizer_loader_path = File.join(
    auth_sanitizer_spec.full_gem_path,
    "lib/auth_sanitizer/loader.rb",
  )
  unless File.file?(auth_sanitizer_loader_path)
    # :nocov:
    raise LoadError, "oauth2 requires auth-sanitizer #{auth_sanitizer_requirement}; " \
      "loader not found at #{auth_sanitizer_loader_path}"
    # :nocov:
  end

  auth_sanitizer_loader_namespace = Module.new
  auth_sanitizer_loader_namespace.module_eval(
    File.read(auth_sanitizer_loader_path),
    auth_sanitizer_loader_path,
    1,
  )

  auth_sanitizer_loader_namespace.
    const_get(:AuthSanitizer).
    const_get(:Loader).
    load_isolated
end
FilteredAttributes =

Permanent alias for OAuth2::AUTH_SANITIZER::FilteredAttributes.

This constant is intentionally kept in the ‘OAuth2` namespace because it was part of the public API before the implementation was extracted into the `auth-sanitizer` gem. It will not be deprecated or removed.

OAuth2::AUTH_SANITIZER::FilteredAttributes

Class Method Summary collapse

Class Method Details

.configObject



79
80
81
# File 'lib/oauth2.rb', line 79

def config
  CONFIG
end

.configure {|config| ... } ⇒ void

This method returns an undefined value.

Configure global library behavior.

Yields the mutable configuration object so callers can update settings.

Yield Parameters:

  • config (SnakyHash::SymbolKeyed)

    the configuration object



89
90
91
# File 'lib/oauth2.rb', line 89

def configure
  yield config
end