定制 laxo/authecticate-system 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laxo/authecticate-system

Composer 安装命令:

composer require laxo/authecticate-system

包简介

The PHP JWT Authorization Class provides a straightforward way to manage user authentication and authorization using JSON Web Tokens (JWT). This class is designed to handle token generation, validation, and user session management seamlessly, ensuring secure and efficient authentication for your app

README 文档

README

PHP JWT Authorization Class

Secure | Easy to Use | Session Management | Token Validation | IP Verification

Perfect for Managing Authentication and Authorization

PHP Version PHP Version GitHub License Packagist Downloads GitHub Repo stars

GitHub commit activity GitHub code size in bytes GitHub Discussions Languages



Introduction

The PHP JWT Authorization Class provides a straightforward way to manage user authentication and authorization using JSON Web Tokens (JWT). This class is designed to handle token generation, validation, and user session management seamlessly, ensuring secure and efficient authentication for your application.

Features

  • JWT Encoding and Decoding: Securely encode and decode JWTs.
  • User Authentication: Authenticate users and manage user sessions.
  • Token Validation: Validate JWTs to ensure they haven't been tampered with.
  • IP Verification: Ensure the IP address remains consistent during a session.
  • Session Management: Manage user sessions with automatic logout and token renewal.

Installation

  1. Clone the repository:
git clone https://github.com/samirkl/PHP-Authenticate-System.git
  1. Install dependencies:
composer require firebase/php-jwt

Usage

Include the Authorize class in your project and use its methods to manage authentication.

Generate Token

  • To generate a JWT for a user:
<?php
require 'Authorize.php';

// User information to protect
$userData = [
    'username' => 'bond',
    'password' => 'hashed_password',
    'name'     => 'James Bond',
    'phone'    => '123-456-7890',
    ...
];

// Authenticate user and set session
Authorize::auth($userData);

Verify Token

  • To verify the user's identity using a token:
<?php
require 'Authorize.php';

try {
    $isApi = true; // Set to true if this is an API call
    $isAuthenticated = Authorize::verifyIdentity($isApi);

    if ($isAuthenticated) {
        // User is authenticated
        echo 'User is authenticated';
    } else {
        // Authentication failed
        echo 'Authentication failed';
    }
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

Log Out

  • To log out the user:
<?php
require 'Authorize.php';

$isLoggedOut = Authorize::logOut();

if ($isLoggedOut) {
    echo 'User logged out successfully';
} else {
    echo 'User was not logged in';
}

Methods

Authorize::hash($value)

Encodes the given value into a JWT.

  • Parameters: string|array $value - The data to encode.
  • Returns: string - The encoded JWT

Authorize::unHash($value)

Decodes the given JWT.

  • Parameters: string $value - The encoded JWT.
  • Returns: string|false - The decoded data as a JSON string or false on failure.
  • Throws: JsonException

Authorize::auth(array|bool $protectedData = false)

Authenticates the user and sets the session data.

  • Parameters: array|bool $protectedData - User data to protect (e.g., username, password).

Authorize::verifyIdentity(bool $isApi = false)

Verifies the user's identity using the stored token.

  • Parameters: bool $isApi - If true, updates the token after authentication.
  • Returns: bool - True if authentication is successful, false otherwise.
  • Throws: Exception

Authorize::getIPAddress()

Gets the user's IP address.

  • Returns: string - The user's IP address.

Authorize::logOut()

Logs out the user by clearing the session and cookie.

  • Returns: bool - True if the user was logged out, false if the user was not logged in.

Authorize::validateToken($token)

Validates the given token.

  • Parameters: string $token - The JWT to validate.
  • Returns: array|null - The decoded token data as an array or null on failure.
  • Throws: JsonException

Authorize::isValidToken($tokenData)

Checks if the token data is valid.

  • Parameters: array $tokenData - The decoded token data.
  • Returns: bool - True if the token is valid, false otherwise.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgements

laxo/authecticate-system 适用场景与选型建议

laxo/authecticate-system 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 laxo/authecticate-system 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 laxo/authecticate-system 我们能提供哪些服务?
定制开发 / 二次开发

基于 laxo/authecticate-system 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-30