How should I load images if I use token-based authentication

前端 未结 2 1436
栀梦
栀梦 2021-01-07 16:16

I have a client-side application on domain client-domain.com and a server-side application on domain server-domain.com. There is an API on the serv

2条回答
  •  无人及你
    2021-01-07 16:47

    My solution to basically this exact same problem, based on Jeferson Tenorio's answer below (option 1), was to sign the URL to my API call with an encryption of the image and the user's JWT token, e.g. path/to/image?token=xxxx. In laravel this is easily accomplished with encrypt($your_object) and decrypt($token) (https://laravel.com/docs/5.7/encryption), and then I used the extracted token to verify the user had access to the file in question. But there are probably many other libraries capable of handling this.

    I would be curious if there are any security concerns, but from my perspective the JWT is never exposed via plain text and the encryption relies on a secret key that malicious actors shouldn't have access to, so it seems like it should be fairly secure. My only real complaint is that the token is quite long using this method which does not make for presentable URLs.

提交回复
热议问题