rijosh/podio-auth

Podio身份验证,包括速率限制控制

1.3.9 2019-11-19 03:45 UTC

README

Laravel-Podio库,包括

先决条件

  • php: ^5.3.0
  • laravel/framework: ^5.2
  • podio/podio-php: ^4.3

安装

  1. 安装包

    composer require rijosh/podio-auth
    
  2. config/app.php 提供者列表中包含 PodioAuthServiceProvider

    PodioAuth\PodioAuthServiceProvider::class
    
  3. 创建配置文件 podio.php 并添加以下代码

    return [
        /**
         * Podio username and password.
         * This will be using for user authentication (Username and password flow).
         */
        'username' => '',
        'password' => '',
    
    
        /**
         * Include Podio apps details here.
         * This will be using for app authentication (App authentication flow).
         * List the type of hooks if needed.
         */
        'app_auth' => [
            'app_name' => [
                'app_id' =>,
                'app_secret' => '',
                'hook_types' => []
            ],
        ],
    
    
        /**
         * Include multiple API Keys here.
         * This is using for rate-limit handling.
         */
        'client_api' => [
            [
                'id' => '',
                'secret' => '',
            ],
        ]
    ];
    
  4. 更新 podio.php 中的配置数据。

  5. 运行以下命令

    * php artisan podio:init
    
    

    这将生成所需的表并从配置中同步API。

代码示例

使用包库进行身份验证和Podio API

 <?php
 
 namespace App\Http\Controllers;
 
 
 use PodioAuth\Controllers\PodioAuth;
 use PodioAuth\Repositories\Podio;
 
 class TestController extends Controller
 {
     public function getTest()
     {
         PodioAuth::podioUserAuth(); // username-password authentication
         PodioAuth::podioAppAuth(12344); // App authentication
         PodioAuth::podioAppAuthWithName("name"); // Authenticate app with name specified in config/podio.php
         Podio::PodioApp_get(123456); // Get Podio app details
     }
 }

使用钩子管理模块

以下URL可以用于管理Podio钩子。

  • hook/create : 将钩子添加到配置文件中列出的所有Podio应用程序。
  • hook/remove : 删除所有从应用程序添加的钩子,不受 podio_hooks 表中创建的条目的影响。
  • hook/disable : 从 podio_hooks 表中列出的Podio应用程序中删除所有钩子。
  • cron/hook : 将此URL用作cron作业。它将检查应用程序中的非活动钩子并启用它们。

添加钩子后,请确保所有钩子都已验证。钩子URL将是 handle/{app_id}/hook。所有来自Podio的钩子都将进入 podio_requests 表,并触发钩子处理URL。这将有助于异步处理钩子。按照以下步骤继续处理钩子。

  • 创建新的控制器并扩展 PodioAuth\Controllers\HookController
  • 添加处理钩子的函数。
    public function processHook($id) // table row id
    {
        $request = PodioRequest::whereId($id)->first(); 
        if ($request) {
            $appId = $request->app_id;
            $hook = $request->request;

             
            /**
            * Start processing hook.
            */
            $request->is_processing = 1;
            $request->save();


            /**
            * Your code
            */


            /**
            * Finished processing hook.
            */
            $request->is_processing = 0;
            $request->is_processed = 1;
            $request->save();
        }
    }
  • 为此函数添加路由,名称为 process_hook,方法为 get
Route::get('process/{id}/hook', 'HookController@processHook')->name('process_hook');

注意

所有功能都依赖于 podio.php 文件中的配置数据。请确保 app_authclient_api 已正确同步到数据库中的相应表。通过运行命令 php artisan config:cache 清除配置缓存。

贡献

欢迎使用对Podio Auth库的贡献。