AuthManager
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
Create the user provider implementation for the driver.
Get the provider name declared by the current default guard.
Get the user provider configuration.
Create an instance of the database user provider.
Create an instance of the Eloquent user provider.
Attempt to get the guard from the local cache.
Resolve the given guard.
Call a custom driver creator.
Create a session based authentication guard.
Create a token based authentication guard.
Get the guard configuration.
Get the default authentication driver name.
Set the default guard driver the factory should serve.
Set the default authentication driver name.
Register a new callback based request guard.
Get the user resolver callback.
Clear the cached user for the given identifier.
Configure where guests are redirected by the "auth" middleware.
Configure where users are redirected by the "guest" middleware.
Configure where users are redirected by the authentication and guest middleware.
Determine if any guards have already been resolved.
Forget all of the resolved guard instances.
Get all of the created guard instances.
Get durable authentication Context keys for resolved guards.
Dynamically call the default driver instance.
Details
in
CreatesUserProviders at line 22
UserProvider|null
createUserProvider(string|null $provider = null)
Create the user provider implementation for the driver.
in
CreatesUserProviders at line 48
string|null
getDefaultUserProvider()
Get the provider name declared by the current default guard.
in
CreatesUserProviders at line 56
protected array|null
getProviderConfiguration(string|null $provider)
Get the user provider configuration.
in
CreatesUserProviders at line 68
protected DatabaseUserProvider
createDatabaseProvider(array $config)
Create an instance of the database user provider.
in
CreatesUserProviders at line 80
protected EloquentUserProvider
createEloquentProvider(array $config)
Create an instance of the Eloquent user provider.
in
RebindsCallbacksToSelf at line 18
protected Closure|null
bindCallbackToSelf(Closure $callback)
Bind the provided callback to the class instance.
at line 60
__construct(Container $app)
Create a new Auth manager instance.
at line 69
Guard|StatefulGuard
guard(UnitEnum|string|null $name = null)
Attempt to get the guard from the local cache.
at line 85
protected Guard|StatefulGuard
resolve(string $name)
Resolve the given guard.
at line 111
protected mixed
callCustomCreator(string $name, array $config)
Call a custom driver creator.
at line 119
SessionGuard
createSessionDriver(string $name, array $config)
Create a session based authentication guard.
at line 150
TokenGuard
createTokenDriver(string $name, array $config)
Create a token based authentication guard.
at line 168
protected array|null
getConfig(string $name)
Get the guard configuration.
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.
at line 191
void
shouldUse(UnitEnum|string|null $name)
Set the default guard driver the factory should serve.
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.
at line 221
AuthManager
viaRequest(string $driver, callable $callback)
Register a new callback based request guard.
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.
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.
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.
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.
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.
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.
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.
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.
at line 362
bool
hasResolvedGuards()
Determine if any guards have already been resolved.
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.
at line 385
array
getGuards()
Get all of the created guard instances.
at line 395
array
getAuthContextKeys()
Get durable authentication Context keys for resolved guards.
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.
at line 430
mixed
__call(string $method, array $parameters)
Dynamically call the default driver instance.