Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel passport oauth function using curl or guzzle

I have this route in api route file

Route::post('/user/register', 'HomeController@register');

and the register function is

public function register(Request $request)
 {
    $user = User::create([
        ...
    ]);
    return $this->getAccessToken($request);
}

public function getAccessToken(Request $request)
{
    $url = url('/oauth/token');
    $headers = ['Accept' => 'application/json'];
    $http = new Client;

    $response = $http->post($url, [
        'headers' => $headers,
        'form_params' => [
            'grant_type' => 'password',
            'client_id' => 'my_client_id',
            'client_secret' => 'my_client_secret',
            'username' => 'username',
            'password' => 'password'
        ],
    ]);

    return json_decode((string)$response->getBody(), true);
}

now when I send post request to the url the user is created but the request keep loading and no response and the whole application is hanging until I close the IDE - phpstorm - I send the same parameters to the same url /oauth/token from postman and it works fine. any help or any one tell me what I am missing ?

like image 324
Moauya Meghari Avatar asked Nov 08 '22 03:11

Moauya Meghari


1 Answers

the problem was the curl do not work when the url contains port like

localhost:8000

like image 164
Moauya Meghari Avatar answered Nov 15 '22 10:11

Moauya Meghari