SessionGuard
class SessionGuard implements StatefulGuard, SupportsBasicAuth (View source)
Traits
GuardHelpers | These methods are typically the same across all guards. |
Macroable |
Properties
protected Authenticatable | $user | The currently authenticated user. | from GuardHelpers |
protected UserProvider | $provider | The user provider implementation. | from GuardHelpers |
static protected array | $macros | The registered string macros. | from Macroable |
protected string | $name | The name of the Guard. Typically "session". | |
protected Authenticatable | $lastAttempted | The user we last attempted to retrieve. | |
protected bool | $viaRemember | Indicates if the user was authenticated via a recaller cookie. | |
protected Session | $session | The session used by the guard. | |
protected QueueingFactory | $cookie | The Illuminate cookie creator service. | |
protected Request | $request | The request instance. | |
protected Dispatcher | $events | The event dispatcher instance. | |
protected bool | $loggedOut | Indicates if the logout method has been called. | |
protected bool | $recallAttempted | Indicates if a token user retrieval has been attempted. |
Methods
Authenticatable | authenticate() Determine if current user is authenticated. If not, throw an exception. | from GuardHelpers |
bool | hasUser() Determine if the guard has a user instance. | from GuardHelpers |
bool | check() Determine if the current user is authenticated. | from GuardHelpers |
bool | guest() Determine if the current user is a guest. | from GuardHelpers |
int|string|null | id() Get the ID for the currently authenticated user. | |
void | setUser(Authenticatable $user) Set the current user. | |
UserProvider | getProvider() Get the user provider used by the guard. | from GuardHelpers |
void | setProvider(UserProvider $provider) Set the user provider used by the guard. | from GuardHelpers |
static void | macro(string $name, object|callable $macro) Register a custom macro. | from Macroable |
static void | mixin(object $mixin, bool $replace = true) Mix another object into the class. | from Macroable |
static bool | hasMacro(string $name) Checks if macro is registered. | from Macroable |
static mixed | __callStatic(string $method, array $parameters) Dynamically handle calls to the class. | from Macroable |
mixed | __call(string $method, array $parameters) Dynamically handle calls to the class. | from Macroable |
void | __construct(string $name, UserProvider $provider, Session $session, Request $request = null) Create a new authentication guard. | |
Authenticatable|null | user() Get the currently authenticated user. | |
mixed | userFromRecaller(Recaller $recaller) Pull a user from the repository by its "remember me" cookie token. | |
Recaller|null | recaller() Get the decrypted recaller cookie for the request. | |
bool | once(array $credentials = []) Log a user into the application without sessions or cookies. | |
bool | onceUsingId(mixed $id) Log the given user ID into the application without sessions or cookies. | |
bool | validate(array $credentials = []) Validate a user's credentials. | |
Response|null | basic(string $field = 'email', array $extraConditions = []) Attempt to authenticate using HTTP Basic Auth. | |
Response|null | onceBasic(string $field = 'email', array $extraConditions = []) Perform a stateless HTTP Basic login attempt. | |
bool | attemptBasic(Request $request, string $field, array $extraConditions = []) Attempt to authenticate using basic authentication. | |
array | basicCredentials(Request $request, string $field) Get the credential array for a HTTP Basic request. | |
void | failedBasicResponse() Get the response for basic authentication. | |
bool | attempt(array $credentials = [], bool $remember = false) Attempt to authenticate a user using the given credentials. | |
bool | hasValidCredentials(mixed $user, array $credentials) Determine if the user matches the credentials. | |
Authenticatable | loginUsingId(mixed $id, bool $remember = false) Log the given user ID into the application. | |
void | login(Authenticatable $user, bool $remember = false) Log a user into the application. | |
void | updateSession(string $id) Update the session with the given ID. | |
void | ensureRememberTokenIsSet(Authenticatable $user) Create a new "remember me" token for the user if one doesn't already exist. | |
void | queueRecallerCookie(Authenticatable $user) Queue the recaller cookie into the cookie jar. | |
Cookie | createRecaller(string $value) Create a "remember me" cookie for a given ID. | |
void | logout() Log the user out of the application. | |
void | clearUserDataFromStorage() Remove the user data from the session and cookies. | |
void | cycleRememberToken(Authenticatable $user) Refresh the "remember me" token for the user. | |
void | logoutCurrentDevice() Log the user out of the application on their current device only. | |
bool|null | logoutOtherDevices(string $password, string $attribute = 'password') Invalidate other sessions for the current user. | |
void | attempting(mixed $callback) Register an authentication attempt event listener. | |
void | fireAttemptEvent(array $credentials, bool $remember = false) Fire the attempt event with the arguments. | |
fireValidatedEvent($user) Fires the validated event if the dispatcher is set. | ||
void | fireLoginEvent(Authenticatable $user, bool $remember = false) Fire the login event if the dispatcher is set. | |
void | fireAuthenticatedEvent(Authenticatable $user) Fire the authenticated event if the dispatcher is set. | |
void | fireOtherDeviceLogoutEvent(Authenticatable $user) Fire the other device logout event if the dispatcher is set. | |
void | fireFailedEvent(Authenticatable|null $user, array $credentials) Fire the failed authentication attempt event with the given arguments. | |
Authenticatable | getLastAttempted() Get the last user we attempted to authenticate. | |
string | getName() Get a unique identifier for the auth session value. | |
string | getRecallerName() Get the name of the cookie used to store the "recaller". | |
bool | viaRemember() Determine if the user was authenticated via "remember me" cookie. | |
QueueingFactory | getCookieJar() Get the cookie creator instance used by the guard. | |
void | setCookieJar(QueueingFactory $cookie) Set the cookie creator instance used by the guard. | |
Dispatcher | getDispatcher() Get the event dispatcher instance. | |
void | setDispatcher(Dispatcher $events) Set the event dispatcher instance. | |
Session | getSession() Get the session store used by the guard. | |
Authenticatable|null | getUser() Return the currently cached user. | |
Request | getRequest() Get the current request instance. | |
$this | setRequest(Request $request) Set the current request instance. |
Details
Authenticatable authenticate()
Determine if current user is authenticated. If not, throw an exception.
bool hasUser()
Determine if the guard has a user instance.
bool check()
Determine if the current user is authenticated.
bool guest()
Determine if the current user is a guest.
int|string|null id()
Get the ID for the currently authenticated user.
void setUser(Authenticatable $user)
Set the current user.
UserProvider getProvider()
Get the user provider used by the guard.
void setProvider(UserProvider $provider)
Set the user provider used by the guard.
static void macro(string $name, object|callable $macro)
Register a custom macro.
static void mixin(object $mixin, bool $replace = true)
Mix another object into the class.
static bool hasMacro(string $name)
Checks if macro is registered.
static mixed __callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
mixed __call(string $method, array $parameters)
Dynamically handle calls to the class.
void __construct(string $name, UserProvider $provider, Session $session, Request $request = null)
Create a new authentication guard.
Authenticatable|null user()
Get the currently authenticated user.
protected mixed userFromRecaller(Recaller $recaller)
Pull a user from the repository by its "remember me" cookie token.
protected Recaller|null recaller()
Get the decrypted recaller cookie for the request.
bool once(array $credentials = [])
Log a user into the application without sessions or cookies.
bool onceUsingId(mixed $id)
Log the given user ID into the application without sessions or cookies.
bool validate(array $credentials = [])
Validate a user's credentials.
Response|null basic(string $field = 'email', array $extraConditions = [])
Attempt to authenticate using HTTP Basic Auth.
Response|null onceBasic(string $field = 'email', array $extraConditions = [])
Perform a stateless HTTP Basic login attempt.
protected bool attemptBasic(Request $request, string $field, array $extraConditions = [])
Attempt to authenticate using basic authentication.
protected array basicCredentials(Request $request, string $field)
Get the credential array for a HTTP Basic request.
protected void failedBasicResponse()
Get the response for basic authentication.
bool attempt(array $credentials = [], bool $remember = false)
Attempt to authenticate a user using the given credentials.
protected bool hasValidCredentials(mixed $user, array $credentials)
Determine if the user matches the credentials.
Authenticatable loginUsingId(mixed $id, bool $remember = false)
Log the given user ID into the application.
void login(Authenticatable $user, bool $remember = false)
Log a user into the application.
protected void updateSession(string $id)
Update the session with the given ID.
protected void ensureRememberTokenIsSet(Authenticatable $user)
Create a new "remember me" token for the user if one doesn't already exist.
protected void queueRecallerCookie(Authenticatable $user)
Queue the recaller cookie into the cookie jar.
protected Cookie createRecaller(string $value)
Create a "remember me" cookie for a given ID.
void logout()
Log the user out of the application.
protected void clearUserDataFromStorage()
Remove the user data from the session and cookies.
protected void cycleRememberToken(Authenticatable $user)
Refresh the "remember me" token for the user.
void logoutCurrentDevice()
Log the user out of the application on their current device only.
bool|null logoutOtherDevices(string $password, string $attribute = 'password')
Invalidate other sessions for the current user.
The application must be using the AuthenticateSession middleware.
void attempting(mixed $callback)
Register an authentication attempt event listener.
protected void fireAttemptEvent(array $credentials, bool $remember = false)
Fire the attempt event with the arguments.
protected fireValidatedEvent($user)
Fires the validated event if the dispatcher is set.
protected void fireLoginEvent(Authenticatable $user, bool $remember = false)
Fire the login event if the dispatcher is set.
protected void fireAuthenticatedEvent(Authenticatable $user)
Fire the authenticated event if the dispatcher is set.
protected void fireOtherDeviceLogoutEvent(Authenticatable $user)
Fire the other device logout event if the dispatcher is set.
protected void fireFailedEvent(Authenticatable|null $user, array $credentials)
Fire the failed authentication attempt event with the given arguments.
Authenticatable getLastAttempted()
Get the last user we attempted to authenticate.
string getName()
Get a unique identifier for the auth session value.
string getRecallerName()
Get the name of the cookie used to store the "recaller".
bool viaRemember()
Determine if the user was authenticated via "remember me" cookie.
QueueingFactory getCookieJar()
Get the cookie creator instance used by the guard.
void setCookieJar(QueueingFactory $cookie)
Set the cookie creator instance used by the guard.
Dispatcher getDispatcher()
Get the event dispatcher instance.
void setDispatcher(Dispatcher $events)
Set the event dispatcher instance.
Session getSession()
Get the session store used by the guard.
Authenticatable|null getUser()
Return the currently cached user.
Request getRequest()
Get the current request instance.
$this setRequest(Request $request)
Set the current request instance.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/6.x/Illuminate/Auth/SessionGuard.html