Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get user in LoginProxy #39

Open
sreinoso opened this issue Jan 26, 2018 · 6 comments
Open

Get user in LoginProxy #39

sreinoso opened this issue Jan 26, 2018 · 6 comments

Comments

@sreinoso
Copy link

sreinoso commented Jan 26, 2018

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!

@esien525
Copy link

esien525 commented Apr 2, 2018

hi @sreinoso , did you able to solve this?

@esien525
Copy link

esien525 commented Apr 2, 2018

I found the solution, just simply use $request->user('api'); in any Controller function.

@sreinoso
Copy link
Author

sreinoso commented Apr 2, 2018

No, I did not found the solution, I will try it!

@fernandocoronatomf
Copy link

@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?

@esien525
Copy link

esien525 commented Apr 21, 2019

@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

@fernandocoronatomf
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants