This package enables support for authentication with one-time secret url.
Run the following command from your project directory to add the dependency:
composer require mkaverin/laravel-url-login
Then, run database migrations:
php artisan migrate
If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
:
'providers' => [
...
UrlLogin\Providers\UrlLoginServiceProvider::class,
],
You can copy the package config with the publish command:
php artisan vendor:publish --provider="UrlLogin\Providers\UrlLoginServiceProvider"
You can find published config in config/url-login.php
.
The model you want to use for authentication should use the AuthenticatesViaUrl
trait.
It provides the createUrlLoginToken
method and urlAuthTokens()
relation.
UrlAuthController
shipped with this package is an abstract controller that provides
authenticate() and logout() methods. You can use it as a base for your own controller:
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Http\Request;
use UrlLogin\Http\Controllers\UrlAuthController;
class AdminAuthController extends UrlAuthController
{
protected function getAuthGuardName(): string
{
return 'admin';
}
protected function isNeededToRemember(Request $request, Authenticatable $user): bool
{
return $request->has('remember') && $request->input('remember') === 'true';
}
}
This package uses default authentication guard, but you can use any guard you like by
overriding the getAuthGuardName()
or getAuthGuard()
method in your UrlAuthController
.
If you would like to provide "remember me" functionality in your application, you may use the
isNeededToRemember()
method. This method accepts authentication request and retrieved
user model, so you can determine if the user should be remembered.
composer test