Skip to content

class Athena::Security::Authenticator::Passport::Badge::User
inherits Reference #

Represents the user being authenticated, via its identifier and how to load it.

The user is loaded by the user loader of this badge, or by the user provider of the firewall if it has none, see ASEC::Listeners::UserProvider.

# Loaded by the user provider of the firewall.
ASEC::Authenticator::Passport::Badge::User.new email

# Loaded by the provided block.
ASEC::Authenticator::Passport::Badge::User.new(api_token) do |token|
  User.find_by_api_token token
end

Included modules

Athena::Security::Authenticator::Passport::Badge::Interface

Constants#

MAX_USERNAME_LENGTH = 4096#

The maximum length of a user identifier, in bytes.

Constructors#

.new(user_identifier : String, &user_loader : String -> ASEC::User::Interface | Nil) : self#

Creates a badge for the user with the provided user_identifier, which is a unique string representing the user for this authentication. The user is loaded by the block, which returns nil if the user does not exist.

Raises an ASEC::Exception::BadCredentials if the user_identifier is empty, or longer than MAX_USERNAME_LENGTH.

View source

.new(user_identifier : String, user_loader : Proc(String, ASEC::User::Interface | Nil) | Nil = nil)#

Creates a badge for the user with the provided user_identifier, which is a unique string representing the user for this authentication. The user is loaded by the provided user_loader, which returns nil if the user does not exist, if any.

Raises an ASEC::Exception::BadCredentials if the user_identifier is empty, or longer than MAX_USERNAME_LENGTH.

View source

Methods#

#resolved? : Bool#

Returns true if this badge was checked by the security system, otherwise false.

Every badge of a passport must be resolved once it was checked, otherwise the authentication fails.

View source

#user : ASEC::User::Interface#

Returns the user, loading it via the user loader the first time.

Raises an ASEC::Exception::UserNotFound if the user does not exist, or an ASEC::Exception::Logic if this badge has no user loader.

View source

#user_identifier : String#

Returns the identifier of the user, e.g. its email address.

View source

#user_loader : Proc(String, ASEC::User::Interface | ::Nil) | ::Nil#

Returns the proc loading the user from its identifier, returning nil if it does not exist, if any.

View source

#user_loader=(user_loader : Proc(String, ASEC::User::Interface | Nil))#

Sets the provided user_loader, loading the user from its identifier, returning nil if it does not exist.

View source

#user_provider : ASEC::User::Provider::Interface | ::Nil#

Returns the user provider loading the user, if it was set via #user_provider=.

View source

#user_provider=(user_provider : ASEC::User::Provider::Interface)#

Sets the provided user_provider as the user loader, loading the user via its ASEC::User::Provider::Interface#load_user_by_identifier.

If the user_provider is also an ASEC::User::PasswordUpgraderInterface, ASEC::Listeners::PasswordMigrating upgrades the password of the user through it.

View source