codeblog / jwt
一个简单的库,用于处理JSON Web Token和JSON Web Signature
v1.0.0
2019-03-27 14:18 UTC
Requires
- php: >=7.1
This package is auto-updated.
Last update: 2024-09-28 05:03:54 UTC
README
JWT是一个组件,简化了API中的认证处理。JWT包含描述用户实体、授权数据、令牌有效性、有效域名等信息和元数据。
JWT是一个组件,简化了API中的认证处理。JWT包含描述用户实体、授权数据、令牌有效性、有效域名等信息和元数据。
亮点
- 简单安装(简单安装)
- 为API创建认证令牌(为API创建认证令牌)
- 令牌真实性检查(令牌真实性检查)
- 令牌过期检查(令牌过期检查)
安装
JWT可以通过Composer获取
"codeblog/jwt": "^1.0"
或者运行
composer require codeblog/jwt
文档
有关使用详情,请参阅组件目录中的示例文件夹。在那里,您将为每个类找到使用示例。它的工作方式如下
有关使用详情,请参阅组件目录中的示例文件夹。在那里,您将为每个类找到使用示例。它的工作方式如下
创建JWT
<?php require __DIR__ . '/../vendor/autoload.php'; use CodeBlog\JWT\JWT; $key = 'codeblog.com.br'; // your secret key $payload = array( "iss" => "api.dominio.com", // the token emitter. You can use the domain where your api is. Ex: api.domain.com "iat" => time(), // The time the JWT was issued. Can be used to determine the age of JWT. "exp" => time() + (60 * 60), // This is likely to be the most commonly used registered claim. This will set the expiration on the NumericDate value. The expiration MUST be after the current date / time. "data" => [ "user_id" => 10, "user_email" => "fulano@gmail.com" ] ); $jwt = (new JWT)->encode($payload, $key); var_dump($jwt); //$decoded = JWT::decode($jwt, $key); //var_dump($decoded);
认证JWT
<?php require __DIR__ . '/../vendor/autoload.php'; use CodeBlog\JWT\JWT; $key = 'codeblog.com.br'; // your secret key $jwt = new JWT(); $token = $jwt->authHeader(); $decoded = $jwt->decode($token, $key); var_dump($decoded);
贡献
有关详细信息,请参阅CONTRIBUTING。
支持
安全性:如果您发现任何与安全相关的问题,请通过电子邮件whallyssonallain@gmail.com联系,而不是使用问题跟踪器。
如果您发现任何与安全相关的问题,请通过电子邮件whallyssonallain@gmail.com联系,而不是使用问题跟踪器。
谢谢
致谢
- Whallysson Avelino(开发者)
- CodBlog(团队)
- 所有贡献者(这座岩石)
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。