我使用Laravel 5.1.33與Dingo Api和JWT Auth,已經安裝了所有這些,但現在我很困惑,如果我需要做更多,例如我想要驗證一個用戶,因此用戶無法先訪問某些路由而不能先登錄。JWT Auth配置Dingo Api Laravel 5.1。*
我havethis修訂於api.php代碼:
'auth' => [
'jwt' => 'Dingo\Api\Auth\Provider\JWT',
],
我很困惑,當談到這裏,添加此代碼,它到底做什麼?
app('Dingo\Api\Auth\Auth')->extend('jwt', function ($app) {
return new Dingo\Api\Auth\Provider\JWT($app['Tymon\JWTAuth\JWTAuth']);
});
我已閱讀野狗/ API已經內置了tymondesigns/JWT-auth的支持,這是不是意味着我不需要編寫任何驗證代碼,或這是什麼意思?
誰能告訴我,如果我必須修改當前AuthController其在這一刻看起來如下:
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
如果是這樣,需要添加什麼方法? 它說Dingo支持內置的jwt auth,因此我決定使用這個包,不僅僅是這個原因,還有其他一些原因,比如變形金剛,比率限制等等......但是我仍然很困惑我是否需要額外編寫驗證用戶的代碼,因爲它已經在構建中支持...如果不是,我該如何登錄?我沒有聲明用於認證的路由,也沒有註冊用戶,我應該以某種方式將這些路由指向一些控制器,任何人都可以幫助解決這個問題?
嘗試更多的解釋增加了答案,避免提供鏈接,因爲鏈接可能是一段時間 – xhulio
GitHub的例子項目似乎是OAuth不智威湯遜中實現後不可用 – Sisir