如果你正確設置Laravel護照,你應該有這個在您的視圖:![enter image description here](https://i.stack.imgur.com/mTvsX.png)
你需要創建一個客戶端,該客戶端具有客戶端ID和客戶端密鑰。
現在您需要打開您的客戶應用程序,其中應包含您的客戶端ID和客戶端密碼。
它看起來像這樣(你必須標記和編號更改爲特定的一個):
class OAuthController extends Controller
{
public function redirect()
{
$query = http_build_query([
'client_id' => 3,
'redirect_uri' => 'http://localhost/app/public/callback',
'response_type' => 'code',
'scope' => '',
]);
return redirect('http://localhost/app/public/oauth/authorize?' . $query);
}
public function callback(Request $request)
{
$http = new Client;
$response = $http->post('http://localhost/app/public/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 3, // from admin panel above
'client_secret' => 'BcTgzw6YiwWUaU8ShX4bMTqej9ccgoA4NU8a2U9j', // from admin panel above
'redirect_uri' => 'http://localhost/app/public/callback',
'code' => $request->code // Get code from the callback
]
]);
return json_decode((string) $response->getBody(), true);
}
}
現在你需要調用消費者應用程序,並授權您的應用程序。
![enter image description here](https://i.stack.imgur.com/97c71.png)
如果工作你會得到一個訪問令牌+刷新令牌。
它應該是這樣的:
![enter image description here](https://i.stack.imgur.com/LlFmB.png)
現在你可以使用像郵遞員程序進行測試。
基本上你打電話給你的get路線,並添加訪問令牌,它給你訪問API,就像這樣:
![enter image description here](https://i.stack.imgur.com/Y2NGh.png)
如果您有任何其它問題我建議你閱讀docs。
因此,我強烈建議您觀看Taylor Otwell的video。
當然,如果您還有其他問題,您可以給我評論。
我跟着視頻toturial,並得到了你所顯示的屏幕,但仍然出現錯誤。 –
哪個錯誤,因此你不應該只是把答案放在這裏,而不是真的回答相反的意見,否則人們會downvote你的問題,你可能不會得到幫助了 – utdev