[英]How to get the bearer token from a webhook Ruby on Rails
I receive datas from webhook and I try to get the Authorization Bearer token
that is in the headers我从 webhook 接收数据,并尝试获取标头中的
Authorization Bearer token
I tried :我试过 :
data = JSON.parse(response.body)
puts "TOKEN " + data['csrf-token']['content']
Also :还 :
if headers['Authorization'].present?
puts " HEADER " + headers['Authorization'].split(' ').last
else
puts "ERROR"
end
-> I have the ERROR -> 我有错误
And :和 :
data = response.body
puts "TOKEN " + data['csrf-token']['content']
-> It returns nil -> 它返回零
Turns out that the solution was :事实证明,解决方案是:
bearer_token = request.headers["Authorization"]
Thanks all for your help !感谢你的帮助 !
data = JSON.parse(response.body)
#⇒ JSON::ParserError (767: unexpected token ...
The library you use to get the response seems to parse the response on its own, you don't need to call JSON#parse
again.您用于获取响应的库似乎会自行解析响应,您无需再次调用
JSON#parse
。 The below should work.下面应该工作。
data = response.body
puts "TOKEN " + data['csrf-token']['content']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.