//BaseController namespace App\Http\Controllers; use Dingo\Api\Routing\Helpers; use Illuminate\Routing\Controller; class BaseController extends Controller { use Helpers; } //UsersController namespace App\Http\Controllers; use App\User; use App\Http\Controllers\Controller; class UsersController extends BaseController { public function index() { return User::all(); } public function show($id) { $user = User::findOrFail($id); // 数组形式 return $this->response->array($user->toArray()); } }
随后在app/Http/Controllers/Auth/下创建PasswordGrantVerifier.php内容如下
namespace App\Http\Controllers\Auth; use Illuminate\Support\Facades\Auth; class PasswordGrantVerifier { public function verify($username, $password) { $credentials = [ 'email' => $username, 'password' => $password, ]; if (Auth::once($credentials)) { return Auth::user()->id; } return false; } }
打开数据库的oauth_client表新增一条client数据
INSERT INTO 'oauth_clients' ('id', 'secret', 'name', 'created_at', 'updated_at') VALUES ('1', '2', 'Main website', '2016–03–13 23:00:00', '0000–00–00 00:00:00');
随后的就是去愉快的测试了,这里要测试的API有
新增一个用户
读取所有用户信息
只返回用户id为4的信息
获取access_token
利用token值获得时间,token值正确才能返回正确值
打开PostMan
您可能感兴趣的文章: