如何使用 devise_auth_token 为请求配置 Postman [英] How to configure Postman for requests with devise_auth_token

查看:20
本文介绍了如何使用 devise_auth_token 为请求配置 Postman的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用 Postman 记录一个 RubyOnRails API,但我不知道如何为需要令牌的请求设置授权.我正在使用

  • 既然你已经得到了请求的响应,你需要的参数就在请求的头部,点击Headers标签来查看它们.

  • 然后在 Postman 中使用需要授权的 GET 创建一个新请求,并在 Headers 中设置值 access-tokenclientuid 来自最后一个请求的标头.

您可以将值设置为 环境 中的局部变量在每个请求中调用它们,而不是在每个标头中粘贴它们.

如果您在完成本指南后遇到授权错误

<代码>{错误":[仅限授权用户."]}

这是因为有时访问令牌配置为每次客户端查询API时都会更改,要更改此配置只需添加以下行config/initializers/devise_token_auth.rb

config.change_headers_on_each_request = false

REST API 测试- 邮递员在每次请求后表现为不同的客户

I need to document a RubyOnRails API with Postman but I don’t know how to set up the authorization for the requests that need token. I’m using devise_token_auth gem

解决方案

When you use devise_token_auth the format of the cURL is the following:

curl -XGET -v -H 'Content-Type: application/json' -H 'access-token: lW1c60hYkRwAinzUqgLfsQ' -H 'client: W_xCQuggzNOVeCnNZbjKFw' -H "uid: email@domain.com" http://domain/api/v1/auth/validate_token

So you need the next parameters to access: access-token, client, uid, url

To get them you need to follow these instructions:

  • Create a new user with a POST request to your signup request, in this case is http://localhost:3000/auth and in Body with RAW format set the params you need to create a new user (like in the example) and click send.

  • Now that you got the response of the request, the params you need are in the header of the request, click to Headers tab to see them.

  • Then create a new request in Postman with the GET that requires the authorization and in Headers set the values access-token, client, uid from the header of the last request.

You could set the values as local variables in an environment to call them in every request instead of pasting them in each header.

In case you got an Authorization error after complete this guide

{
  "errors": [
    "Authorized users only."
  ]
}

This is because sometimes the access-token is configured to change each time the client queries the API, to change this configuration only add the following line to config/initializers/devise_token_auth.rb

config.change_headers_on_each_request = false

REST API Testing - Postman behaving as different client after each request

这篇关于如何使用 devise_auth_token 为请求配置 Postman的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆