\Charcoal\UserAuthenticator

The Authenticator service helps with user authentication / login.

Constructor dependencies

Constructor dependencies are passed as an array of key=>value pair. The required dependencies are:

  • logger A PSR3 logger instance
  • user_type The user object type (FQN or ident)
  • user_factory The Factory used to instanciate new users.
  • token_type The auth token object type (FQN or ident)
  • token_factory The Factory used to instanciate new auth tokens.

Summary

Methods
Properties
Constants
__construct()
authenticate()
authenticateByPassword()
No public properties found
No constants found
userType()
userFactory()
tokenType()
tokenFactory()
No protected properties found
N/A
setUserType()
setUserFactory()
setTokenType()
setTokenFactory()
authenticateBySession()
authenticateByToken()
$userType
$userFactory
$tokenType
$tokenFactory
N/A

Properties

$userType

$userType : string

The user object type.

Type

string

$userFactory

$userFactory : \Charcoal\Factory\FactoryInterface

Store the user model factory instance for the current class.

Type

\Charcoal\Factory\FactoryInterface

$tokenType

$tokenType : string

The auth-token object type.

Type

string

$tokenFactory

$tokenFactory : \Charcoal\Factory\FactoryInterface

Store the auth-token model factory instance for the current class.

Type

\Charcoal\Factory\FactoryInterface

Methods

__construct()

__construct(array  $data) 

Returns a new Authoricator object.

Parameters

array $data

Class dependencies.

authenticate()

authenticate() : \Charcoal\User\UserInterface|null

Determine if the current user is authenticated.

The user is authenticated via session ID or auth token.

Returns

\Charcoal\User\UserInterface|null —

Returns the authenticated user object or NULL if not authenticated.

authenticateByPassword()

authenticateByPassword(string  $username, string  $password) : \Charcoal\User\UserInterface|null

Attempt to authenticate a user using the given credentials.

Parameters

string $username

Username, part of necessery credentials.

string $password

Password, part of necessary credentials.

Throws

\InvalidArgumentException

If username or password are invalid or empty.

Returns

\Charcoal\User\UserInterface|null —

Returns the authenticated user object or NULL if not authenticated.

userType()

userType() : string

Retrieve the user object type.

Returns

string

userFactory()

userFactory() : \Charcoal\Factory\FactoryInterface

Retrieve the user model factory.

Throws

\RuntimeException

If the model factory was not previously set.

Returns

\Charcoal\Factory\FactoryInterface

tokenType()

tokenType() : string

Retrieve the auth-token object type.

Returns

string

tokenFactory()

tokenFactory() : \Charcoal\Factory\FactoryInterface

Retrieve the auth-token model factory.

Throws

\RuntimeException

If the token factory was not previously set.

Returns

\Charcoal\Factory\FactoryInterface

setUserType()

setUserType(string  $type) : \Charcoal\User\AdminAuthenticator

Set the user object type (model).

Parameters

string $type

The user object type.

Throws

\InvalidArgumentException

If the user object type parameter is not a string.

Returns

\Charcoal\User\AdminAuthenticator —

Chainable

setUserFactory()

setUserFactory(\Charcoal\Factory\FactoryInterface  $factory) : \Charcoal\User\AdminAuthenticator

Set a user model factory.

Parameters

\Charcoal\Factory\FactoryInterface $factory

The factory used to create new user instances.

Returns

\Charcoal\User\AdminAuthenticator —

Chainable

setTokenType()

setTokenType(string  $type) : \Charcoal\User\AdminAuthenticator

Set the authorization token type (model).

Parameters

string $type

The auth-token object type.

Throws

\InvalidArgumentException

If the token object type parameter is not a string.

Returns

\Charcoal\User\AdminAuthenticator —

Chainable

setTokenFactory()

setTokenFactory(\Charcoal\Factory\FactoryInterface  $factory) : \Charcoal\User\AdminAuthenticator

Set a model factory for token-based authentication.

Parameters

\Charcoal\Factory\FactoryInterface $factory

The factory used to create new auth-token instances.

Returns

\Charcoal\User\AdminAuthenticator —

Chainable

authenticateBySession()

authenticateBySession() : \Charcoal\User\UserInterface|null

Attempt to authenticate a user using their session ID.

Returns

\Charcoal\User\UserInterface|null —

Returns the authenticated user object or NULL if not authenticated.

authenticateByToken()

authenticateByToken() : \Charcoal\User\UserInterface|null

Attempt to authenticate a user using their auth token.

Returns

\Charcoal\User\UserInterface|null —

Returns the authenticated user object or NULL if not authenticated.