Skip to content

Commit eacfa86

Browse files
committed
version php71
0 parents  commit eacfa86

File tree

16 files changed

+4502
-0
lines changed

16 files changed

+4502
-0
lines changed

.github/workflows/php.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Validate composer.json and composer.lock
18+
run: composer validate
19+
20+
- name: Cache Composer packages
21+
id: composer-cache
22+
uses: actions/cache@v2
23+
with:
24+
path: vendor
25+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
26+
restore-keys: |
27+
${{ runner.os }}-php-
28+
29+
- name: Install dependencies
30+
if: steps.composer-cache.outputs.cache-hit != 'true'
31+
run: composer install --prefer-dist --no-progress --no-suggest
32+
33+
- name: Run validations
34+
run: composer check
35+
36+
- name: export coverage
37+
run: |
38+
export CODECOV_TOKEN="${{ secrets.CODECOV_TOKEN }}"
39+
bash <(curl -s https://codecov.io/bash)

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
coverage
2+
vendor
3+
.scannerwork
4+
.phpunit.result.cache

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# JWT Manager PHP
2+
3+
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
4+
5+
PHP library to manage JWT authentication
6+
7+
### Installation
8+
9+
[Release 1.0.0](https://github.com/not-empty/jwt-manager-php-lib/releases/tag/1.0.0) Requires [PHP](https://php.net) 7.1
10+
11+
The recommended way to install is through [Composer](https://getcomposer.org/).
12+
13+
```sh
14+
composer require not-empty/jwt-manager-php-lib
15+
```
16+
17+
### Usage
18+
19+
Generating a token
20+
21+
```php
22+
use JwtManager\JwtManager;
23+
$secret = '77682b9441bb7daa7a1fa6eb7522b689';
24+
$context = 'test';
25+
$expire = 30;
26+
$renew = 10;
27+
$jwtManager = new JwtManager(
28+
$secret,
29+
$context,
30+
$expire,
31+
$renew
32+
);
33+
$tokenGenerated = $jwtManager->generate('test');
34+
var_dump($tokenGenerated);
35+
```
36+
37+
Dedoce the token and return the data
38+
39+
```php
40+
$result = $jwtManager->decodePayload($tokenGenerated);
41+
var_dump($result);
42+
```
43+
44+
Verify if token is valid
45+
46+
```php
47+
$result = $jwtManager->isValid($tokenGenerated);
48+
var_dump($result);
49+
```
50+
51+
Check if a token is on time
52+
53+
```php
54+
$result = $jwtManager->isOnTime($tokenGenerated);
55+
var_dump($result);
56+
```
57+
58+
Get the expiration time of a token
59+
60+
```php
61+
$result = $jwtManager->getexpire($tokenGenerated);
62+
var_dump($result);
63+
```
64+
65+
Check if need to refresh a token
66+
67+
```php
68+
$result = $jwtManager->tokenNeedToRefresh($tokenGenerated);
69+
var_dump($result);
70+
```
71+
72+
if you want an environment to run or test it, you can build and install dependences like this
73+
74+
```sh
75+
docker build --build-arg PHP_VERSION=7.1.33-cli -t not-empty/jwt-manager-php-lib:php71 -f contrib/Dockerfile .
76+
```
77+
78+
Access the container
79+
```sh
80+
docker run -v ${PWD}/:/var/www/html -it not-empty/jwt-manager-php-lib:php71 bash
81+
```
82+
83+
Verify if all dependencies is installed
84+
```sh
85+
composer install --no-dev --prefer-dist
86+
```
87+
88+
and run
89+
```sh
90+
php sample/jwt-manager-sample.php
91+
```
92+
93+
### Development
94+
95+
Want to contribute? Great!
96+
97+
The project using a simple code.
98+
Make a change in your file and be careful with your updates!
99+
**Any new code will only be accepted with all validations.**
100+
101+
To ensure that the entire project is fine:
102+
103+
First you need to building a correct environment to install all dependences
104+
105+
```sh
106+
docker build --build-arg PHP_VERSION=7.1.33-cli -t not-empty/jwt-manager-php-lib:php71 -f contrib/Dockerfile .
107+
```
108+
109+
Access the container
110+
```sh
111+
docker run -v ${PWD}/:/var/www/html -it not-empty/jwt-manager-php-lib:php71 bash
112+
```
113+
114+
Install all dependences
115+
```sh
116+
composer install --dev --prefer-dist
117+
```
118+
119+
Run all validations
120+
```sh
121+
composer check
122+
```
123+
124+
**Not Empty Foundation - Free codes, full minds**

composer.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "not-empty/jwt-manager-php-lib",
3+
"description": "PHP library to manage JWT authentication",
4+
"version": "1.0.0",
5+
"type": "library",
6+
"license": "GPL-3.0-only",
7+
"require": {
8+
"php": "^7.1"
9+
},
10+
"require-dev": {
11+
"phpunit/phpunit": "^7.5",
12+
"mockery/mockery": "^1.3",
13+
"squizlabs/php_codesniffer": "^3.7",
14+
"phpmd/phpmd": "^2.14"
15+
},
16+
"authors": [
17+
{
18+
"name": "Not Empty Foundation",
19+
"email": "dev@not-empty.com"
20+
}
21+
],
22+
"autoload": {
23+
"psr-4": {
24+
"JwtManager\\": "src/"
25+
}
26+
},
27+
"scripts": {
28+
"post-install-cmd": [
29+
"bash contrib/setup.sh"
30+
],
31+
"check": [
32+
"@lint",
33+
"@cs",
34+
"@mess",
35+
"@test",
36+
"@ccu"
37+
],
38+
"mess" : [
39+
"vendor/bin/phpmd ./src text phpmd.xml",
40+
"vendor/bin/phpmd ./sample text phpmd.xml"
41+
],
42+
"lint": [
43+
"find ./src -name '*.php' -print0 | xargs -0 -n1 -P8 php -l -d display_errors=0",
44+
"find ./tests -name '*.php' -print0 | xargs -0 -n1 -P8 php -l -d display_errors=0",
45+
"find ./sample -name '*.php' -print0 | xargs -0 -n1 -P8 php -l -d display_errors=0"
46+
],
47+
"cs": "vendor/bin/phpcs",
48+
"test": "phpdbg -qrr vendor/bin/phpunit --configuration phpunit.xml -d memory_limit=1024M",
49+
"ccu" : "php contrib/coverage-checker.php coverage/coverage.xml 100"
50+
}
51+
}

0 commit comments

Comments
 (0)