class AuthManager implements Factory mixin Guard mixin StatefulGuard

Traits

Constants

DEFAULT_GUARD_CONTEXT_KEY

Context key for the default guard override.

protected RESOLVER_CONTEXT_KEY

Context key for the user resolver callback override.

Properties

protected array $customProviderCreators

The registered custom provider creators.

from  CreatesUserProviders
protected array $customCreators

The registered custom driver creators.

protected array $guards

The array of created "drivers".

protected Closure $userResolver

The user resolver shared by various services.

Methods

createUserProvider(string|null $provider = null)

Create the user provider implementation for the driver.

string|null
getDefaultUserProvider()

Get the provider name declared by the current default guard.

array|null
getProviderConfiguration(string|null $provider)

Get the user provider configuration.

createDatabaseProvider(array $config)

Create an instance of the database user provider.

createEloquentProvider(array $config)

Create an instance of the Eloquent user provider.

Closure|null
bindCallbackToSelf(Closure $callback)

Bind the provided callback to the class instance.

__construct(Container $app)

Create a new Auth manager instance.

guard(UnitEnum|string|null $name = null)

Attempt to get the guard from the local cache.

resolve(string $name)

Resolve the given guard.

mixed
callCustomCreator(string $name, array $config)

Call a custom driver creator.

createSessionDriver(string $name, array $config)

Create a session based authentication guard.

createTokenDriver(string $name, array $config)

Create a token based authentication guard.

array|null
getConfig(string $name)

Get the guard configuration.

string
getDefaultDriver()

Get the default authentication driver name.

void
shouldUse(UnitEnum|string|null $name)

Set the default guard driver the factory should serve.

void
setDefaultDriver(UnitEnum|string $name)

Set the default authentication driver name.

viaRequest(string $driver, callable $callback)

Register a new callback based request guard.

userResolver()

Get the user resolver callback.

resolveUsersUsing(Closure $userResolver)

Set the callback to be used to resolve users.

void
clearUserCache(mixed $identifier, string|null $guard = null)

Clear the cached user for the given identifier.

redirectGuestsTo(callable|string|null $redirect)

Configure where guests are redirected by the "auth" middleware.

redirectUsersTo(callable|string $redirect)

Configure where users are redirected by the "guest" middleware.

redirectTo(callable|string|null $guests = null, callable|string|null $users = null)

Configure where users are redirected by the authentication and guest middleware.

extend(string $driver, Closure $callback)

Register a custom driver creator Closure.

provider(string $name, Closure $callback)

Register a custom provider creator Closure.

bool
hasResolvedGuards()

Determine if any guards have already been resolved.

forgetGuards()

Forget all of the resolved guard instances.

array
getGuards()

Get all of the created guard instances.

array
getAuthContextKeys()

Get durable authentication Context keys for resolved guards.

setApplication(Container $app)

Set the application instance used by the manager.

mixed
__call(string $method, array $parameters)

Dynamically call the default driver instance.

Details

UserProvider|null createUserProvider(string|null $provider = null)

Create the user provider implementation for the driver.

Parameters

string|null $provider

Return Value

UserProvider|null

Exceptions

InvalidArgumentException

string|null getDefaultUserProvider()

Get the provider name declared by the current default guard.

Return Value

string|null

protected array|null getProviderConfiguration(string|null $provider)

Get the user provider configuration.

Parameters

string|null $provider

Return Value

array|null

protected DatabaseUserProvider createDatabaseProvider(array $config)

Create an instance of the database user provider.

Parameters

array $config

Return Value

DatabaseUserProvider

protected EloquentUserProvider createEloquentProvider(array $config)

Create an instance of the Eloquent user provider.

Parameters

array $config

Return Value

EloquentUserProvider

protected Closure|null bindCallbackToSelf(Closure $callback)

Bind the provided callback to the class instance.

Parameters

Closure $callback

Return Value

Closure|null

Exceptions

ReflectionException

at line 60
__construct(Container $app)

Create a new Auth manager instance.

Parameters

Container $app

at line 69
Guard|StatefulGuard guard(UnitEnum|string|null $name = null)

Attempt to get the guard from the local cache.

Parameters

UnitEnum|string|null $name

Return Value

Guard|StatefulGuard

at line 85
protected Guard|StatefulGuard resolve(string $name)

Resolve the given guard.

Parameters

string $name

Return Value

Guard|StatefulGuard

Exceptions

InvalidArgumentException

at line 111
protected mixed callCustomCreator(string $name, array $config)

Call a custom driver creator.

Parameters

string $name
array $config

Return Value

mixed

at line 119
SessionGuard createSessionDriver(string $name, array $config)

Create a session based authentication guard.

Parameters

string $name
array $config

Return Value

SessionGuard

at line 150
TokenGuard createTokenDriver(string $name, array $config)

Create a token based authentication guard.

Parameters

string $name
array $config

Return Value

TokenGuard

at line 168
protected array|null getConfig(string $name)

Get the guard configuration.

Parameters

string $name

Return Value

array|null

at line 179
string getDefaultDriver()

Get the default authentication driver name.

In Swoole, the default guard can be overridden per-request via Context (e.g. when middleware calls shouldUse()), falling back to config.

Return Value

string

at line 191
void shouldUse(UnitEnum|string|null $name)

Set the default guard driver the factory should serve.

Parameters

UnitEnum|string|null $name

Return Value

void

at line 209
void setDefaultDriver(UnitEnum|string $name)

Set the default authentication driver name.

Uses coroutine Context so one request's override doesn't affect others.

Parameters

UnitEnum|string $name

Return Value

void

at line 221
AuthManager viaRequest(string $driver, callable $callback)

Register a new callback based request guard.

Parameters

string $driver
callable $callback

Return Value

AuthManager

at line 234
Closure userResolver()

Get the user resolver callback.

Checks coroutine Context first for per-request overrides, then falls back to the process-global default resolver.

Return Value

Closure

at line 248
AuthManager resolveUsersUsing(Closure $userResolver)

Set the callback to be used to resolve users.

Uses coroutine Context so one request's override doesn't affect others.

Parameters

Closure $userResolver

Return Value

AuthManager

at line 264
void clearUserCache(mixed $identifier, string|null $guard = null)

Clear the cached user for the given identifier.

Uses the specified guard's existing provider instance to avoid creating throwaway provider objects. If the guard doesn't expose getProvider() (custom guards that don't use GuardHelpers), or the provider is not an EloquentUserProvider, or caching is disabled, this is a no-op.

Parameters

mixed $identifier
string|null $guard

Return Value

void

at line 290
AuthManager redirectGuestsTo(callable|string|null $redirect)

Configure where guests are redirected by the "auth" middleware.

Boot-only. The callback persists in authentication middleware and exception static properties for the worker lifetime and affects every subsequent unauthenticated or session-mismatch request.

Parameters

callable|string|null $redirect

Return Value

AuthManager

at line 304
AuthManager redirectUsersTo(callable|string $redirect)

Configure where users are redirected by the "guest" middleware.

Boot-only. The callback persists in the guest middleware static property for the worker lifetime and affects every subsequent already-authenticated guest-route request.

Parameters

callable|string $redirect

Return Value

AuthManager

at line 318
AuthManager redirectTo(callable|string|null $guests = null, callable|string|null $users = null)

Configure where users are redirected by the authentication and guest middleware.

Boot-only. The callbacks persist in authentication middleware and exception static properties for the worker lifetime and affect every subsequent matching request.

Parameters

callable|string|null $guests
callable|string|null $users

Return Value

AuthManager

at line 331
AuthManager extend(string $driver, Closure $callback)

Register a custom driver creator Closure.

Boot-only. The callback persists in the singleton's customCreators array for the worker lifetime and applies to every subsequent guard resolution.

Parameters

string $driver
Closure $callback

Return Value

AuthManager

at line 352
AuthManager provider(string $name, Closure $callback)

Register a custom provider creator Closure.

Boot-only. The callback persists in the singleton's customProviderCreators array for the worker lifetime and applies to every subsequent user provider resolution.

Parameters

string $name
Closure $callback

Return Value

AuthManager

at line 362
bool hasResolvedGuards()

Determine if any guards have already been resolved.

Return Value

bool

at line 375
AuthManager forgetGuards()

Forget all of the resolved guard instances.

Boot or tests only. Clears the singleton's guard cache; concurrent coroutines may already hold references to the prior guard instances (each holding its own coroutine-scoped state) that next resolution will not share.

Return Value

AuthManager

at line 385
array getGuards()

Get all of the created guard instances.

Return Value

array

at line 395
array getAuthContextKeys()

Get durable authentication Context keys for resolved guards.

Return Value

array

at line 420
AuthManager setApplication(Container $app)

Set the application instance used by the manager.

Tests only. Swaps the singleton's container reference; per-request use races across coroutines and breaks every concurrent request's auth resolution.

Parameters

Container $app

Return Value

AuthManager

at line 430
mixed __call(string $method, array $parameters)

Dynamically call the default driver instance.

Parameters

string $method
array $parameters

Return Value

mixed