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 user provider name declared by the given guard.
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 26
UserProvider|null
createUserProvider(string|null $provider = null)
Create the user provider implementation for the driver.
in
CreatesUserProviders at line 52
string|null
getUserProviderName(UnitEnum|string|null $guard = null)
Get the user provider name declared by the given guard.
in
CreatesUserProviders at line 71
string|null
getDefaultUserProvider()
Get the provider name declared by the current default guard.
in
CreatesUserProviders at line 79
protected array|null
getProviderConfiguration(string|null $provider)
Get the user provider configuration.
in
CreatesUserProviders at line 91
protected DatabaseUserProvider
createDatabaseProvider(array $config)
Create an instance of the database user provider.
in
CreatesUserProviders at line 107
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 87
protected Guard|StatefulGuard
resolve(string $name)
Resolve the given guard.
at line 113
protected mixed
callCustomCreator(string $name, array $config)
Call a custom driver creator.
at line 121
SessionGuard
createSessionDriver(string $name, array $config)
Create a session based authentication guard.
at line 152
TokenGuard
createTokenDriver(string $name, array $config)
Create a token based authentication guard.
at line 171
protected array|null
getConfig(string $name)
Get the guard configuration.
at line 182
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 194
void
shouldUse(UnitEnum|string|null $name)
Set the default guard driver the factory should serve.
at line 214
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 226
AuthManager
viaRequest(string $driver, callable $callback)
Register a new callback based request guard.
at line 239
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 253
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 269
void
clearUserCache(mixed $identifier, UnitEnum|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 299
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 313
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 327
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 345
AuthManager
extend(string $driver, Closure $callback)
Register a custom driver creator Closure.
Anonymous closures run in this manager's class scope; non-static closures also receive the manager as $this.
Boot-only. The callback persists in the singleton's customCreators array for the worker lifetime and applies to every subsequent guard resolution.
at line 366
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 376
bool
hasResolvedGuards()
Determine if any guards have already been resolved.
at line 389
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 399
array
getGuards()
Get all of the created guard instances.
at line 409
array
getAuthContextKeys()
Get durable authentication Context keys for resolved guards.
at line 434
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 444
mixed
__call(string $method, array $parameters)
Dynamically call the default driver instance.