承接 verzth/tcx 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

verzth/tcx

Composer 安装命令:

composer require verzth/tcx

包简介

TCX - Authentication Module for Client-Server Transaction (One Way - Two Way)

README 文档

README

TCX is authentication module to secure API Server.

It's adapt OAuth2 scheme, but it use more simplify scheme which provide authentication for client-server without need to define scopes.

Dependencies

Laravel >= 5.6

How to Install

composer require verzth/tcx

How to Use

  1. Add our ServiceProvider on your config/app.php.

    return [
        //...
        //..
        //.
        
        'providers' => [
            // ...
            Verzth\TCX\TCXServiceProvider::class,
            ...
        ]
        
        //.
        //..
        //...
    ];
  2. Add TCX Middleware in your app/Http/Kernel.php.

    • In every request.
        $middleware = [
            //...
            \Verzth\TCX\Middleware\TCXMiddleware::class,
            //...
        ];

    or

    • In your API group middleware only.
        $middlewareGroups = [
            //...
            'api' => [
                //...
                \Verzth\TCX\Middleware\TCXMiddleware::class,
                //...
            ]
            //...
        ];

    or

    • In your route middleware, and you can add manually on your route.
        $routeMiddleware = [
            //...
            'tcx' => \Verzth\TCX\Middleware\TCXMiddleware::class,
            //...
        ];
  3. Publish our vendor with artisan command.

    php artisan vendor:publish --provider=Verzth\TCX\TCXServiceProvider
  4. Migrate our TCX DB. After migrate it, you will get 3 tables (tcx_applications, tcx_accesses, tcx_mkas).

    php artisan migrate
  5. Refresh the autoload with below command.

    composer dump-autoload
  6. We provide seeder to generate sample data. Simply put below code to file database/seeds/DatabaseSeeder.php, inside run() function.

    $this->call(TCXApplicationsTableSeeder::class);

    then run below script on your shell/command prompt.

    composer db:seed
  7. Or just run below script (skip step 6) to generate the sample data.

    php artisan db:seed --class=TCXApplicationsTableSeeder

Implementation

  1. Authentication Type, TCX support three ways authentication type:

    • One Way Transaction Code (OWTC): Client only need to use app_id and app_public to access Server APIs.
    • Two Way Transaction Code (TWTC): Client has to use app_id and app_public to get access token, then it can be used to access APIs.
    • Free Transaction Code (FTC): Client use master token to access APIs, without need to request token for every requests, it's specially design to by pass TWTC authentication. You need to generate Master token manually.

    To specify authentication for each APIs assign parameter in the middleware, use or (|) sign to specify multiple authentication or use all to support all type (Supported type : all, owtc, twtc). By default, TCX will support all authentication if you didn't specifying supported type.

    Client need to specify type by sending X-TCX-TYPE header in every APIs request.

  2. How to generate credentials:

    • app_pass or X-TCX-APP-PASS, it can be generate by hashing plain of joined token (param, time, or none), application public key, and client dynamic token with SHA1. Client need to append the given dynamic token to hash result by splitting with colon (:) symbol, then encrypt it with base64.
      • Param base

        Sample Parameter:

        abc=123
        _xyz=789
        foo=bar
        def=456
        bar=ghi
        

        Expected Token:

        _xyz=789&abc=123&bar=ghi&def=456&foo=bar
        
      • Time base

        tcx_datetime=YYYYMMDDHHmmss
        

        Sample

        tcx_datetime=20181230235959 // For 23:59:59, 30 December 2018
        
      • None, just using application password and client dynamic token.

    • token or X-TCX-TOKEN, it's provided when Client authorizing to server, but you need to encrypt it with base64.
  3. Authentication Headers.

    • Type OWTC:
      • 'X-TCX-TYPE': 'OWTC'.
      • 'X-TCX-APP-ID': Client ID.
      • 'X-TCX-APP-PASS': Client Password.
    • Type TWTC:
      • 'X-TCX-TYPE': 'TWTC'.
      • 'X-TCX-APP-ID': Client ID.
      • 'X-TCX-APP-PASS': Client Password.
      • 'X-TCX-TOKEN': Access Token, obtained by doing authorization.
    • Type FTC:
      • 'X-TCX-TYPE': 'FTC'.
      • 'X-TCX-APP-ID': Client ID.
      • 'X-TCX-APP-PASS': Client Password.
      • 'X-TCX-TOKEN': Master Access Token.
  4. Authorization Routes, TCX provide some routes which is can be used to get access token in TWTC type:

    • /tcx/authorize:

      • METHOD: POST
      • Params:
        • app_id: Client application id.
        • app_pass: Client password.

      Sample Fail response

      {
          "status": 0,
          "status_number": "002",
          "status_code": "TCXAFX",
          "status_message": "Authentication Failed"
      }
      

      Sample Success response

      {
          "status": 1,
          "status_number": "701",
          "status_code": "TCXSSS",
          "status_message": "Authentication Success",
          "data": {
              "token": "tfDBOa6q3PPTJFd0A8HWftw2sXMV1b5ue6v0intK",
              "refresh": "fR0HLeL5qk0ZdtthI2ZsQLZx8BHEP2dSnVaQqkF5",
              "expired_at": "2018-10-16 13:31:43"
          }
      }
      
    • /tcx/reauthorize:

      Refresh token can be used to refresh your existing token, you can pass it to this service and your existing token will be extended. Service will reply new refresh token for your existing token to be used in next refresh.

      • METHOD: POST
      • Params:
        • app_id: Client application id.
        • token: Refresh Token.

      Sample Fail response

      {
          "status": 0,
          "status_number": "002",
          "status_code": "TCXAFX",
          "status_message": "Authentication Failed"
      }
      

      Sample Success response

      {
          "status": 1,
          "status_number": "701",
          "status_code": "TCXSSS",
          "status_message": "Token refreshed",
          "data": {
              "refresh": "04ITeVxWINOesyHH5Sxx57rN5uAW0ltCWN0cENxD",
              "expired_at": "2018-10-16 13:36:42"
          }
      }
      
  5. Response Status.

    Status Number Code Message Note
    0 70FF000 TCXREQ TCX Authentication Required Provide Authentication Header
    0 20FF001 TCXRJC TCX Authentication Rejected X-TCX-Type not supported or disabled
    0 40FF002 TCXAFX TCX Authentication Failed X-TCX-App-ID not found, invalid, or inactive
    0 50FF003 TCXPFX TCX Pass did not match X-TCX-App-Pass not passed, crosscheck point 2
    0 50FF004 TCXMKF TCX Master Key did not valid Check the master access key (Only FTC)
    0 50FF005 TCXTFX TCX Token did not valid Check the access key (Only TWTC)

    Sample Response:

    {
        "status": 0,
        "status_code": "TCXREQ",
        "status_number": "70FF000",
        "status_message": "TCX Authentication Required"
    }
    

verzth/tcx 适用场景与选型建议

verzth/tcx 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 96 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 10 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Authentication」 「laravel」 「tcx」 「owtc」 「twtc」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 verzth/tcx 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-09