简体   繁体   English

让客户端使用承载令牌我将其发送

[英]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.

相关问题 如何通过请求发送不记名令牌 - How to send Bearer token with request 我可以使用 selenium 登录应用程序,他们可以获取生成的不记名令牌并在 api 调用中使用它吗?有什么方法可以获取不记名令牌吗? - Can I log in into application with selenium and them get the bearer token generated and use it in api call?Is there any way to get bearer token? 无法使用 Springfox 发送授权承载令牌 - Cannot send Authorization Bearer Token using Springfox 我如何使用 Quarkus Microprofile Rest 客户端动态传递承载令牌? - How do i pass a Bearer Token dynamically with Quarkus Microprofile Rest Client? 使用 java 6 获取不记名令牌(OAUTH 2.0) - getting bearer token(OAUTH 2.0 ) using java 6 仅使用客户端ID和密钥获取Bearer令牌。 可能吗 - Obtain Bearer token, using only Client ID and Secret. Is it possible 如何在 websocket javascript 客户端中传递授权承载访问令牌 - how to pass Authorization Bearer access token in websocket javascript client 如何获取我请求的当前不记名令牌? - how can I get the current Bearer token of my request? 我如何从 HttpClient 获取承载令牌? - How i can get the Bearer Token from HttpClient? 我想在我的 retrofit 发布请求中添加一个不记名令牌 - I want to add a bearer token to my retrofit post request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM