简体   繁体   English

如何在 Javascript/NodeJS 中存储令牌

[英]How to store a token in Javascript/NodeJS

We have a mobile single page application developed in HTML/CSS/NodeJS.我们有一个用 HTML/CSS/NodeJS 开发的移动单页应用程序。 The functionality of this application involves making lot of API calls.此应用程序的功能涉及进行大量 API 调用。 But to invoke any API we need a bearer token(for authorization purposes).This bearer token is just a string value.但是要调用任何 API,我们需要一个不记名令牌(用于授权目的)。这个不记名令牌只是一个字符串值。 We are generating the bearer token by making an API call(which is the first API call) and we want to use this bearer token for making all the subsequent API calls.我们通过进行 API 调用(这是第一个 API 调用)来生成不记名令牌,并且我们希望使用此不记名令牌进行所有后续 API 调用。

We are not sure how to store the token so that we can use it for making all the subsequent API calls.我们不确定如何存储令牌,以便我们可以使用它来进行所有后续的 API 调用。 We are not using a database to store the token in a database and the there is no login/logout functionality in the application to store the token in session.我们没有使用数据库将令牌存储在数据库中,并且应用程序中没有登录/注销功能来将令牌存储在 session 中。 So we are wondering if there is any other way to store the token.所以我们想知道是否有任何其他方式来存储令牌。 I know storing the token in a file could be an option but wondering if there is any other better way to store the token between API calls.我知道将令牌存储在文件中可能是一种选择,但想知道是否还有其他更好的方法可以在 API 调用之间存储令牌。 Any pointers or guidance will be very helpful.任何指示或指导都会非常有帮助。

Generate jwt token.生成 jwt 令牌。 No need to store that token in any database.无需将该令牌存储在任何数据库中。 Just use library function to verify it.只需使用库 function 来验证它。

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

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