PHP code example of phpno1 / passport

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

    

phpno1 / passport example snippets


    composer 

    # 在config/app.php中
    'providers' => [
        // Laravel\Passport\PassportServiceProvider::class,
        Phpno1\Passport\Providers\Phpno1PassportServiceProvider::class, // 代替原生的passport provider
    ];

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Phpno1\Passport\Traits\TokenAuthenticatesUsers;

class AdminLoginController extends Controller
{
    use TokenAuthenticatesUsers; // 使用扩展提供的trait

    protected $maxAttempts = 5; // 允许尝试次数

    protected $decayMinutes = 60; // 超过尝试次数后冻结多少分钟

    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function guard()
    {
        return 'api_admin'; // 配置文件中的自定义guard,如果是默认的api,则该方法无需重写
    }
    
    // 根据自己生成的数据来配置这些值。
    protected function authorization()
    {
        return [
            'grant_type'    => 'password',
            'client_id'     => 2,
            'client_secret' => 'hNrOGyPZlbqKYuuLgs1JMizaRd78iWbq7Lsk1AHc',
            'scope'         => 'client-backend',
        ];
    }

}