Trying Passport Token System First Time. By URL: http://localhost:8000/oauth/token, Access token and Refresh token can be available. But, unable to use oauth/token Post method in laravel Controller file
Some links: Laravel 5.6 pass oauth/token hanging
Guzzle Cannot make GET request to the localhost (port: 80, 8000, 8080, etc )
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use App\User;
use GuzzleHttp\Client;
class AuthController extends Controller
{
public function login(Request $request)
{
$credentials = request(['email', 'password']);
$credentialsforToken = request(['email', 'password', 'grant_type', 'client_id', 'client_secret']);
if(!Auth::attempt($credentials))
return response()->json([
'message' => 'Unauthorized'
], 401);
//$user = $request->user();
//return $user;
$http = new Client();
$response = $http->post(url('oauth/token'), [
'form_params' => [
'grant_type' => $credentialsforToken['grant_type'],
'client_id' => $credentialsforToken['client_id'],
'client_secret' => $credentialsforToken['client_secret'],
'username' => $credentialsforToken['email'],
'password' => $credentialsforToken['password'],
'scope' => '',
],
]);
return json_decode((string) $response->getBody(), true);
}}```
Access token and Refresh token must be generated