token为请求配置邮递员

token为请求配置邮递员

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

问题描述

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




  • 现在您已收到请求的响应,所需的参数位于请求的标题中,单击 Headers (标题)选项卡以查看它们。






  • 然后使用需要授权的GET在Postman中创建一个新请求,并在 Headers 中设置值 access-token client uid (来自上一个请求的标头)。





您可以将值设置为,以便在每个请求中调用它们,而不是将其粘贴到每个标头中。



如果在完成本指南后出现授权错误

  {
错误:[
仅授权用户。
]
}

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

  config.change_headers_on_each_request = false 


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 protected]" 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 toconfig/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为请求配置邮递员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 19:03