Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davilhlapak/jwt-auth
Biblioteca PHP para a manipulação de JWT
https://github.com/davilhlapak/jwt-auth
composer hacktoberfest jwt jwt-auth php
Last synced: 9 days ago
JSON representation
Biblioteca PHP para a manipulação de JWT
- Host: GitHub
- URL: https://github.com/davilhlapak/jwt-auth
- Owner: DaviLhlapak
- License: apache-2.0
- Created: 2020-04-11T17:07:24.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-18T18:28:30.000Z (about 4 years ago)
- Last Synced: 2024-11-24T17:02:10.658Z (about 1 month ago)
- Topics: composer, hacktoberfest, jwt, jwt-auth, php
- Language: PHP
- Homepage:
- Size: 54.7 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Jwt-Auth
A PHP library for JWT manipulation using native PHP.## Installation
Jwt-Auth is avaliable via Composer
```bash
"pakpak/jwt-auth": "^2.1.4"
```or via terminal:
```bash
composer require pakpak/jwt-auth
```## Documentation
- To use JwtAuth in your code
```php
use PakPak\JwtAuth\JwtAuth;
```- Creating a JWT:
```php
use PakPak\JwtAuth\JwtAuth;
use PakPak\JwtAuth\JwtPayload;$payload = new JwtPayload("localhost","user_id");
$key = "My-Secret-Key";$jwtAuth = JwtAuth::createJwt($payload, $key);
```- Creating a JWT from a token
```php
use PakPak\JwtAuth\JwtAuth;$jwtToken = "header.payload.sign";
$jwtAuth = JwtAuth::byJwt($jwtToken);
```- Recovering data:
```php
// - Validates the token created using the access key
$jwtAuth->verifyJwt("My-Secret-Key");// - Returns a String containing the JWT Token
$jwtAuth->getJwt();// - Returns an array containing the Header
$jwtAuth->getHeader();// - Returns an array containing the Payload
$jwtAuth->getPayload();
```- Creating a header using JwtFunctions:
````php
use PakPak\JwtAuth\JwtFunctions;$header = JwtFunctions::createHeader();
````- Creating a Payload:
````php
use PakPak\JwtAuth\JwtPayload;//Token’s origin
$issuer = "www.meudominio.com";
//Token’s subject
$subject = "user_id";$payload = new JwtPayload($issuer,$subject);
````
## JwtException- Error codes:
| Code | Message |
| :---- | :-------------: |
| 1 | "Header cannot be empty" |
| 2 | "Payload cannot be empty" |
| 3 | "Secret Key cannot be empty" |
| 4 | "Sign cannot be empty" |
| 5 | "Invalid Token" |