且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

仅通过身份验证中间件和基于令牌的身份验证访问存储文件夹中的文件

更新时间:2023-02-24 19:09:56

您不需要在routes.php中使用任何其他配置,如果您遵循此指南,一切都将正常工作:

You don't need to use any other config in routes.php, everything will work just fine if You follow this guide:

最简单的解决方案是创建名为api_token的列是users表.然后,当尝试从android设备访问资源时,只需将?api_token=<token>添加到您的URL中,其中<token>users表中的api_token列.

The easiest solution would be to create column named api_token is users table. Then when trying to access resource from android device, just add ?api_token=<token> to Your URL, where <token> is a api_token column in Your users table.

例如: domain.com/storage/Asset/Media/1/2?api_token=123hello4secret

系统将尝试使用api_token == 123hello4secret搜索用户记录,因此只需将123hello4secret放入您的用户api_token字段中即可.

System will try to search for user record with api_token == 123hello4secret, so just put that 123hello4secret into Your user api_token field.

如果您想知道为什么要api_token作为列名,答案在这里:

If You wonder why You should api_token as column name, the answer is here: https://github.com/laravel/framework/blob/2a38acf7ee2882d831a3b9a1361a710e70ffa31e/src/Illuminate/Auth/TokenGuard.php#L45 Laravel will try to authorize You using api_token if it is found in request fields.

您还可以使用HTTP标头通过令牌进行授权:
标头示例:

Also You can use HTTP headers to authorize with token:
Header example:

Authorization: Bearer 123hello4secret