Module: ApiKeys::Authentication

Extended by:
ActiveSupport::Concern
Includes:
Logging
Defined in:
lib/api_keys/authentication.rb

Overview

Controller concern for handling API key authentication. Provides authenticate_api_key! method and helper methods.

Instance Method Summary collapse

Instance Method Details

#current_api_keyApiKeys::ApiKey?

Returns the currently authenticated API key instance if authentication was successful, otherwise returns nil.

Returns:



25
26
27
# File 'lib/api_keys/authentication.rb', line 25

def current_api_key
  @current_api_key
end

#current_api_ownerObject? Also known as: current_api_key_owner

Returns the owner of the currently authenticated ApiKey, if any.

Returns:

  • (Object, nil)

    The polymorphic owner instance (e.g., User).



31
32
33
# File 'lib/api_keys/authentication.rb', line 31

def current_api_owner
  current_api_key&.owner
end

#current_api_userUser?

Convenience helper: returns the owner if it's a User instance.

Returns:

  • (User, nil)


39
40
41
42
# File 'lib/api_keys/authentication.rb', line 39

def current_api_user
  owner = current_api_owner
  owner if defined?(::User) && owner.is_a?(::User)
end