[英]Getting a client to use a bearer token I send it
I'm building a REST service and right and have run into a problem. 我正在建立REST服务,但遇到了问题。 Right now the functionality is this: a user can post their username and password and if it's correct I return a JWT token for them.
现在的功能是这样的:用户可以发布其用户名和密码,如果正确,我将为他们返回一个JWT令牌。
What do I need to do in order to make a client use this token when they request something from a protected endpoint? 当客户端从受保护的端点请求某些内容时,我该怎么做才能使客户端使用此令牌? I'm new to web in general and I don't know where to go from here.
我一般是网络新手,我不知道从这里去哪里。
First, you have to save the JWT somewhere. 首先,您必须将JWT保存在某个地方。 In a browser, the best options are in cookies or local storage (see where to store your jwts for an example on how).
在浏览器中,最好的选择是在cookie或本地存储中(有关如何操作的示例,请参见jwts的存储位置 )。
Second, you need to pass the JWT back to the server with your next request. 其次,您需要将下一个请求将JWT传递回服务器。 You will have to retrieve the JWT from wherever you stored it and include it in the request.
您必须从存储JWT的任何地方检索JWT,并将其包含在请求中。 How you do this depends on where the server expects your JWT to go and what framework you use for making requests.
如何执行此操作取决于服务器希望JWT到达何处以及用于发出请求的框架。 For example, if your JWT goes in one of the request headers, here is an example for setting request headers with a jquery ajax request.
例如,如果你的智威汤逊云在请求头中的一个, 这里是有一个jQuery Ajax请求设置请求头的例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.