1. Go to this page and download the library: Download narakode/fineauth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
narakode / fineauth example snippets
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Sanctum\HasApiTokens;
use Narakode\FineAuth\HasRefreshTokens;
class User extends Authenticatable
{
use HasApiTokens, HasRefreshTokens;
}
namespace App\Auth;
use Narakode\FineAuth\Auth\AuthCredentials as AuthCredentialsContract;
class AuthCredentials implements AuthCredentialsContract
{
public function rules(): array
{
return [
'email' => ['
namespace App\Providers;
use App\Auth\AuthCredentials;
use Illuminate\Support\ServiceProvider;
use Narakode\FineAuth\Auth\AuthCredentials as AuthCredentialsContract;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton(AuthCredentialsContract::class, AuthCredentials::class);
}
}
namespace App\Auth;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Narakode\FineAuth\Auth\Authenticator as AuthenticatorContract;
class Authenticator implements AuthenticatorContract
{
public function attempt(array $credentials): User|false
{
$user = User::firstWhere('email', $credentials['email']);
if (!$user) {
return false;
}
if (!Hash::check($credentials['password'], $user->password)) {
return false;
}
return $user;
}
}
namespace App\Providers;
use App\Auth\Authenticator;
use Illuminate\Support\ServiceProvider;
use Narakode\FineAuth\Auth\Authenticator as AuthenticatorContract;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton(AuthenticatorContract::class, Authenticator::class);
}
}
namespace App\Auth;
use Narakode\FineAuth\Auth\AuthContext;
use Narakode\FineAuth\Auth\AuthMeta as AuthMetaContract;
class AuthMeta implements AuthMetaContract
{
public function toArray(AuthContext $auth): array
{
$user = $auth->getUser();
return [
'roles' => $user->roles,
'permissions' => $user->permissions,
];
}
}
namespace App\Providers;
use App\Auth\AuthMeta;
use Illuminate\Support\ServiceProvider;
use Narakode\FineAuth\Auth\AuthMeta as AuthMetaContract;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton(AuthMetaContract::class, AuthMeta::class);
}
}