1

I am writing an API at the moment in Laravel, and using passport. My client will consume it's own API, so I am using personal access in Passport.

I am not wanting to show my oauth route and grant id, or secret in the POST request so I have created a route that sits the user posts too to login, and then deals with send a POST request to the oauth/token route, like below,

protected function authenticate(Request $request) {
        //return $request->input();
        //return Response::json($this->client);
        $email = $request->input('username');
            $password = $request->input('password');
            $request->request->add([
                'username' => $email,
                'password' => $password,
                'grant_type' => 'password',
                'client_id' => $this->client->id,
                'client_secret' => $this->client->secret,
                'scope' => '*'
            ]);

            $tokenRequest = Request::create(
                env('APP_URL').'/oauth/token',
                'post'
            );

            return Route::dispatch($tokenRequest)->getContent();

        }

My problem is that my authentication returns 200 irrespective of whether the oauth login was successful. Is there a way to fire a route from a controller and return that http code for that rather than the method it was called from http response?

2

1 Answer 1

2

this should fix the problem.

$data = [
        'grant_type'=> 'password',
        'client_id'=> 99,
        'client_secret'=> 'hgfhfhjnhnjnjnjnj',
        'username'=> $request->username,
        'password'=> $request->password,
        'scopes'=> '[*]'
    ];
$request = Request::create('/oauth/token', 'POST', $data);
return app()->handle($request);
Sign up to request clarification or add additional context in comments.

2 Comments

Welcome to Stack Overflow! Please don't answer just with source code. Try to provide a nice description about how your solution works. See: How do I write a good answer?. Thanks
It helped though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.