Download the PHP package fenrir-soft/authentication without Composer
On this page you can find all versions of the php package fenrir-soft/authentication. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package authentication
Fenrir Framework - Authentication
Requirements
- php 8.2+
Installation
Run the command:
Add the following to your .env file
Create a src/container-definitions.php file, if you have'nt yet, and add the following:
On your controllers add the #Auth attribute
To authenticate you'll need to set the Authorization header with a jwt token with the following claims
To create a jwt token you can use the JwtService like this:
<?php
use Fenrir\Framework\Lib\Request;
use Fenrir\Framework\Lib\Response;
use Fenrir\Authentication\Services\JwtService;
class AuthController {
public function __construct(
private Request $request,
private Response $response,
private JwtService $jwt_service
) {}
public function login() {
$login = $this->request->get('login', '');
$password = $this->request->get('password', '');
if ($login === 'admin' && $password === '12345') {
$jwt_token = $this->jwt_service->encode([
'sub' => 'my-user-id',
'iat' => time(),
'exp' => time() + 3600, /// valid for one hour
'role' => 'admin',
'acl' => ['admin:access']
]);
$this->response->json([
'jwt' => $jwt_token,
]);
return;
}
$this->response->json([
'error' => "Invalide username or password"
]);
}
}
All versions of authentication with dependencies
PHP Build Version
Package Version
The package fenrir-soft/authentication contains the following files
Loading the files please wait ....