PHP code example of loong / oauth

1. Go to this page and download the library: Download loong/oauth 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/ */

    

loong / oauth example snippets

 php

g\oauth\exception\SingleException;
use loong\oauth\exception\TokenExpireException;
use loong\oauth\facade\Auth;
# data可被json序列化的数据
$data = [
    'id' => 1
];
# 加密
$token = Auth::setExpire(2)->encrypt($data);
var_dump($token);
try {
    # 解密
    $data = Auth::decrypt($token);
    var_dump($data);
} catch (TokenExpireException $e) {
    # token已过期
    var_dump($e->getMessage());
} catch (SingleException $e) {
    # 单点登录被踢下线
    var_dump($e->getMessage());
} catch (\Throwable $th) {
    var_dump($th->getMessage());
}