Get user in LoginProxy
Hi, I'm interested on get the user to return to angular2 in LoginProxy@proxy, but I did not find which class or object returns this.
I need something like this:
[...]
public function proxy($grantType, array $data = [])
{
$data = array_merge($data, [
'client_id' => env('PASSWORD_CLIENT_ID'),
'client_secret' => env('PASSWORD_CLIENT_SECRET'),
'grant_type' => $grantType
]);
$response = $this->apiConsumer->post('/oauth/token', $data);
// dd($response, $data, self::REFRESH_TOKEN);
if (!$response->isSuccessful()) {
throw new InvalidCredentialsException();
}
$data = json_decode($response->getContent());
// Create a refresh token cookie
$this->cookie->queue(
self::REFRESH_TOKEN,
$data->refresh_token,
864000, // 10 days
null,
null,
false,
true // HttpOnly
);
return [
'user' => /* User with this token or refresh token */,
'access_token' => $data->access_token,
'expires_in' => $data->expires_in
];
}
[...]
I thought something like $this->auth->user() but it seems it's not defined.
What am I doing wrong?
Thanks!
hi @sreinoso , did you able to solve this?
I found the solution, just simply use $request->user('api'); in any Controller function.
No, I did not found the solution, I will try it!
@esien525 Is it possible to use multiple tables against laravel passport? I have 2 models that can be logged in, and none of them are users... is it possible or do you recommend me another approach?
@fernandocoronatomf, I forget how i do it already. Haha
But i think it is possible as it works like laravel guard.
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
'exampleapi' => [
'driver' => 'passport',
'provider' => 'someusers',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => Api\Users\Models\User::class,
],
'someusers' => [
'driver' => 'eloquent',
'model' => Api\Users\Models\SomeUser::class,
],
],
the code is not tested, but i hope it helps
Thanks for answering but perhaps I did not make myself clear. To use another Model is fine, the problem is when the models aren't linked to a user table.
i had to extend some passport classes to make it work and then switch the guard in a middleware + overwrite some other methods from passport classes.