简体   繁体   English

在 nodejs 中存储 api 访问令牌的位置

[英]where to store api access token in nodejs

I have a react+nodejs setup for a web application.我为 web 应用程序设置了 react+nodejs。 From the Nodejs(server-side) I connect to a third party server using the bearer token.从 Nodejs(服务器端)我使用不记名令牌连接到第三方服务器。

Step 1: Call the third party login URL with username and password.第一步:使用用户名和密码调用第三方登录URL。 I will get a Token in the response with expiry details.我将在响应中获得一个带有到期详细信息的令牌。

Step 2: Send other requests with the valid token.第 2 步:使用有效令牌发送其他请求。

Step 3: Before sending request I need to check if the token that I am having is expired or not.第 3 步:在发送请求之前,我需要检查我拥有的令牌是否已过期。 If not expired, proceed step 2. Otherwise, proceed with step 1 and then step 2.如果未过期,则继续执行步骤 2。否则,继续执行步骤 1,然后执行步骤 2。

I know, in the React application, I can store the token in local storage, and I also can check if it is expired or not.我知道,在 React 应用程序中,我可以将令牌存储在本地存储中,也可以检查它是否过期。

How can I do this in NodeJs(server-side)?我如何在 NodeJs(服务器端)中做到这一点? Do I have to store the token in the database along with expiry time?我必须将令牌与到期时间一起存储在数据库中吗? Or is there any other secure way to store the toke on server temporarily?或者有没有其他安全的方法可以暂时将令牌存储在服务器上?

You could create a properties file, also you could create environment variables (I think thist is a better option).您可以创建一个属性文件,也可以创建环境变量(我认为这是一个更好的选择)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM