I have an API that I need to provide a URL to download files, and the API has to have some form of authentication. I was originally thinking of using a signed URL for this task but I am unable to get that to work. When I go to the URL all it does is return a 403 error. For example, my API URL is api.website.com and the frontend is hosted on a different URL. What would be the best way to serve up those files while having authentication?
@jmurphy1267 A signed URL will work perfectly fine if as stated above, you place it outside of any "auth" middleware, maybe even in your "web" routes, or, a whole different route group that is not in web or API, as you do not need sessions or authentication to be processed when handing out signed URLs.
@Tippin I do have it outside of the auth middleware. My intention was to use signed URLs as a way to keep files secure. I am still getting a 403 after my front end gets the URL from the request and goes to the URL.
@jmurphy1267 Have to ask the obvious question...your routes are not cached right? If you do a php artisan route:list can you confirm your signed route shows up lacking the "auth" middleware? Well, technically 403 sounds more like invalid signature or a policy blocking it, as auth would throw 401
@jmurphy1267 Mind showing how you generate the route? Are you just using the single signed middleware on that route/controller? If it is coming up with a bad signature, then could be you are using a temporary signed URL with invalid / too-short of an expiration, or somehow extra characters / modifications are being made to the route possibly?
@jmurphy1267 Hmm, nothing seems out of place to my eyes. I assume $this->getKey() is you using the models key as the routing identifier. Can you ensure the pdf key is not generating as null? Also, when your UI attempts to fetch the URL, can you confirm NO extra parameters are being tacked onto the URL after the fact?
I assume your generated route should look exactly similar to: