首页 > 解决方案 > Most secure way to pass Laravel passport access_token from Laravel blade to React component

问题描述

I'm building chat application with ReactJS and Laravel, we are using Laravel Echo. API needs an access_token to be authenticated so we need to pass the access_token in the component.

How can do it securely?

标签: reactjslaravelsecuritylaravel-echo

解决方案


access_token 可以由 Laravel Passport (LP) 生成。由于 LP 只是集成到 PHP 联盟的 OAuth 2 中,因此默认发布 JSON Web 令牌 (JWT)。这些令牌存储在客户端非常安全。

如果您查看文档,您将能够为用户生成令牌,而无需通过正常的 OAuth 2 流程。

使用浏览器的LocalStorage,您可以存储此令牌以供将来使用。


推荐阅读