Authentication works fine using 'middleware' => 'auth:api'
on regular endpoints where the client sends the Authorization=Bearer <access_token>
.
But now I'd like to handle plain image download requests, without Authorization header, having the access token in the query string like this: GET /picture/my_picture.png?access_token=1234
.
I tried something like this in my middleware, but I can't seem to add headers to the Request:
if ($request->has('access_token')) {
// something like $request->header->set('Authorization', 'Bearer ' . $request->get('access_token'));
}
if ($this->auth->guard($guard)->guest()) {
// throw exception
}
Can this be done? Maybe intercept or override something/somewhere else?
I had similar issue In your App\Http\Kernal.php
register your middleware in $middleware and $routeMiddleware
Middleware