I am using Laravel 5.4 with Dingo API, and I'm trying to get Laravel's OAuth 2.0 (Passport) to work with Internal Dingo requests. Previously, I was using JWT, but now I wish to use OAuth. This is my previous dispatcher code which passes along the required token to perform the authentication on an internal request.
public function getDispatcher()
{
$token = JWTAuth::fromUser(Auth::user());
return $this->api->header('Authorization','Bearer'.$token)->be(Auth::user());
}
Now that I'm using OAuth to authenticate, my JavaScript code manages to get authentication simply by passing a cookie using this method in the JavaScript, which works perfectly.
Now I need to modify the getDispatcher()
method to get the OAuth token on an "internal request" within Dingo. Does anyone have any tips on how to do this? In theory I could create a personal access token for every user but this seems like overkill just for an internal request. Any advice or approaches appreciated. How can I get the OAuth token without going through the complete OAuth flow, or alternatively, how can I turn off authentication just for internal requests.
Update based on answer below:
'api.auth' on its own on the route (just Dingo) and the internal request works. auth:api (Passport) + api.auth and I get the method not allowed on internal requests this comes back as JSON. {"message":"405 Method Not Allowed"} now when trying to call an internal POST request. (It looks like a 301 redirect to the login page occurs when trying to POST to these routes, and in turn causes the API path to turn into a GET somehow thus throwing the 405 error).
API requests via Postman work in the inverse capacity. Can't find a user when both active (['middleware' => ['auth:api','api.auth']) when (auth:api just Passport) active it works fine.