vendredi 20 avril 2018

Is it possible to call Laravel Passport functions instead of using GuzzleHttp or Proxy in general?

I just started learning Laravel and am having a tough time handling authentication. I am building a web app with Vue as front-end. Somehow I managed to solve the basic authentication issues. But now I want to send User details and OAuth2 tokens when the user login. So my login controller class has this method to send out response

protected function authenticated(Request $request, $user)
{
    $http = new Client([
        'base_uri' => config('app.url'),
        'timeout' => 10,
    ]);

    $response = $http->post('/oauth/token', [
        'form_params' => [
            'grant_type' => 'password',
            'client_id' => '11111',
            'client_secret' => 'P*********************E',
            'username' => $request->input('email'),
            'password' => $request->input('password'),
            'scope' => '',
        ],
    ]);

    //TODO return array_merge of $user values and $response->getBody()

   // Now I am just sending out true to avoid page redirects as all my forms
   // are submitted through AJAX

   return true;
}

How can I merge the two responses together and send out response as JSON? The $user param is of type \Illuminate\Contracts\Auth\Authenticatable.

Moreover GuzzleHttp client seems to be very slow, so I'd like to remove this and directly access the '/oauth/token' controller method. For example, '/oauth/token' routes to \Laravel\Passport\Http\Controllers\AccessTokenController@issueToken. Is there any solution to call this method without routes? Is this possible? Or is there any other better ways to handle this situation.

Thanks



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2HBujLq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire