PHP code example of php-woox / webman-jwt

1. Go to this page and download the library: Download php-woox/webman-jwt 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/ */

    

php-woox / webman-jwt example snippets


use Woox\WebmanJwt\JwtToken;

$user = [
    'id'  => 2024,
    'name'  => 'codeloving',
    'email' => '[email protected]'
];
$token = JwtToken::generateToken($user);
var_dump(json_encode($token));

$id = Woox\WebmanJwt\JwtToken::getCurrentId();

$email = Woox\WebmanJwt\JwtToken::getExtend();

$email = Woox\WebmanJwt\JwtToken::getExtendVal('email');

$refreshToken = Woox\WebmanJwt\JwtToken::refreshToken();

$exp = Woox\WebmanJwt\JwtToken::getTokenExp();

'is_single_device' => true,

$user = [
    'id'  => 2024,
    'name'  => 'codeloving',
    'client' => 'MOBILE',
];
$token = Woox\WebmanJwt\JwtToken::generateToken($user);
var_dump(json_encode($token));

$user = Woox\WebmanJwt\JwtToken::getUser();

'user_model' => function($uid) {
// 返回一个对象
return \support\Db::table('resty_user')
	->where('id', $uid)
	->select('id','email','mobile','create_time')
	->first();
}

$res = Woox\WebmanJwt\JwtToken::clear();

// 生成WEB令牌
$user = [
    'id'  => 2024,
    'name'  => 'codeloving',
    'client' => JwtToken::TOKEN_CLIENT_WEB
];
$token = JwtToken::generateToken($user);

// 生成移动端令牌
$user = [
    'id'  => 2024,
    'name'  => 'codeloving',
    'client' => JwtToken::TOKEN_CLIENT_MOBILE
];
$token = JwtToken::generateToken($user);

$extend = [
    'id'  => 2024,
    'access_exp'  => 7200,  // 2 小时
];
$token = Woox\WebmanJwt\JwtToken::generateToken($extend);

+--------------+-------------------------------+--------------------+
| "alg" Param  | Digital Signature or MAC      | Implementation     |
| Value        | Algorithm                     | Requirements       |
+--------------+-------------------------------+--------------------+
| HS256        | HMAC using SHA-256            | Required           |
| HS384        | HMAC using SHA-384            | Optional           |
| HS512        | HMAC using SHA-512            | Optional           |
| RS256        | RSASSA-PKCS1-v1_5 using       | Recommended        |
|              | SHA-256                       |                    |
| RS384        | RSASSA-PKCS1-v1_5 using       | Optional           |
|              | SHA-384                       |                    |
| RS512        | RSASSA-PKCS1-v1_5 using       | Optional           |
|              | SHA-512                       |                    |
| ES256        | ECDSA using P-256 and SHA-256 | Recommended+       |
| ES384        | ECDSA using P-384 and SHA-384 | Optional           |
| ES512        | ECDSA using P-521 and SHA-512 | Optional           |
| PS256        | RSASSA-PSS using SHA-256 and  | Optional           |
|              | MGF1 with SHA-256             |                    |
| PS384        | RSASSA-PSS using SHA-384 and  | Optional           |
|              | MGF1 with SHA-384             |                    |
| PS512        | RSASSA-PSS using SHA-512 and  | Optional           |
|              | MGF1 with SHA-512             |                    |
| none         | No digital signature or MAC   | Optional           |
|              | performed                     |                    |
+--------------+-------------------------------+--------------------+

The use of "+" in the Implementation Requirements column indicates
that the 

ssh-keygen -t rsa -b 4096 -E SHA512 -m PEM -P "" -f RS512.key
openssl rsa -in RS512.key -pubout -outform PEM -out RS512.key.pub

ssh-keygen -t rsa -b 4096 -E SHA354 -m PEM -P "" -f RS384.key
openssl rsa -in RS384.key -pubout -outform PEM -out RS384.key.pub

ssh-keygen -t rsa -b 4096 -E SHA256 -m PEM -P "" -f RS256.key
openssl rsa -in RS256.key -pubout -outform PEM -out RS256.key.pub
shell
composer