Download the PHP package mpyw/null-auth without Composer
On this page you can find all versions of the php package mpyw/null-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package null-auth
Null Auth
Null Guard for Laravel. Designed for Middleware-based authentication and testing.
Requirements
- PHP:
^8.0
- Laravel:
^9.0 || ^10.0 || ^11.0
Installing
Features
NullAuthenticatable
family
Trait | ID | Password | Remember Token |
---|---|---|---|
GenericNullAuthenticatable GenericStrictNullAuthenticatable |
❗️ | ❌ | ❌ |
NullAuthenticatable StrictNullAuthenticatable |
✅ | ❌ | ❌ |
NoRememberTokenAuthenticatable StrictNoRememberTokenAuthenticatable |
✅ | ✅ | ❌ |
- ❗️shows containing abstract methods.
Strict
traits throwBadMethodCallException
on bad method calls.
NullGuard
NullGuard::user()
always returns Authenticatable already set byNullGuard::setUser()
.NullGuard::unsetUser()
can unset user.
NullUserProvider
- All methods do nothing and always returns falsy value.
Usage
Basic Usage
Edit your config/auth.php
.
Motivation
Guard-based API Authentication
Consider authentication that sends HTTP requests to the external platform.
In such a situation, you will probably use RequestGuard
through Auth::viaRequest()
call.
However, some methods on the contracts UserProvider
and Authenticatable
are unsuitable for that.
They heavily rely on the following flow:
- Retrieve a user from database by email address
- Verify user's password hash
This library provides a helper that makes the useless contract methods to do nothing; always return nullish or falsy values.
Now we include NullAuthenticatable
trait on a user model.
Then only getAuthIdentifierName()
and getAuthIdentifier()
are provided as a valid implementation.
Middleware-based Authentication
Suppose you hate using RequestGuard
and wish implementing authentication on middleware.
Methods such as Auth::user()
cause side effects when called for the first time on each request.
This may lead to inappropriate behaviors if you concentrate authentication on middleware
and use Auth::user()
only as a container for Authenticatable
object.
Don't worry. This library provides NullGuard
,
which is exactly as a simple Authenticatable
container that you want.
Auth::user()
does nothing but returning the cached Authenticatable
.
You can just focus on calling Auth::setUser()
on your cool middleware at ease.
Testing
Needless to say, it is also useful for testing. There is no worry about causing side effects.
All versions of null-auth with dependencies
illuminate/auth Version ^9.0 || ^10.0 || ^11.0
illuminate/contracts Version ^9.0 || ^10.0 || ^11.0
illuminate/support Version ^9.0 || ^10.0 || ^11.0