<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                github地址 ``` https://github.com/tymondesigns/jwt-auth ``` 安裝教程 ``` https://jwt-auth.readthedocs.io/en/develop/laravel-installation/ ``` 首先安裝擴展 ``` composer require tymon/jwt-auth ``` 如果是laravel 5.4及其以下的需要如下設置 反之忽略 ``` 將服務提供者添加到 config/app.php 配置文件中的 providers 數組中,如下所示 'providers' => [ ... Tymon\\JWTAuth\\Providers\\LaravelServiceProvider::class ] ``` 加下來添加配置文件了 ``` php artisan vendor:publish --provider="Tymon\\JWTAuth\\Providers\\LaravelServiceProvider" ``` 如下所示 ![](https://img.kancloud.cn/bf/d3/bfd3a822ac8797ed83251570a638d83e_958x86.png) 發布自動秘鑰(會在.env下面生成 JWT_SECRET 這個鍵) ``` php artisan jwt:secret ``` 如下所示 ![](https://img.kancloud.cn/e5/98/e59891392683a03447ce011fb880aa80_817x49.png) 這樣安裝工作就完畢了 開始使用的設置 需要設置一下models中的User模型 *首先,您需要在您的用戶模型上實現 Tymon\\JWTAuth\\Contracts\\JWTSubject 合約,這需要您實現兩個方法 getJWTIdentifier() 和 getJWTCustomClaims()。* ___ ``` <?php namespace App\Models; use Tymon\JWTAuth\Contracts\JWTSubject; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable implements JWTSubject { use Notifiable; /** * Get the identifier that will be stored in the subject claim of the JWT. * @return mixed */ public function getJWTIdentifier() { return $this->getKey(); } /** * Return a key value array, containing any custom claims to be added to the JWT. * @return array */ public function getJWTCustomClaims() { return []; } } ``` ___ 其中 `public function getJWTCustomClaims()`方法是為了擴展 `payload`中的值 如果返回空數組那么就是顯示在`config/jwt.php`中配置的默認值 ~~~ 'required_claims' => [ 'iss', 'iat', 'exp', 'nbf', 'sub', // 用戶的id 'jti', ], ~~~ 如果需要加上用戶的ip 那么可以這樣 ~~~ public function getJWTCustomClaims() { return [ 'ip' => $this->ip // 用戶模型中的字段 ]; } ~~~ 加上后返回ip在其中 ___ 然后需要配置config/auth.php的目錄 ``` 原來的樣子 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], ], 補充一下 如下所示 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'jwt', 'provider' => 'users', ], ], ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看