-3

I receive datas from webhook and I try to get the Authorization Bearer token that is in the headers

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 !

Dam76
  • 15
  • 4

2 Answers2

0
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. The below should work.

data = response.body
puts "TOKEN " + data['csrf-token']['content']
Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
0

enter image description here

.....

I think you can get Authorization Bearer token like :-

if headers['Authorization'].present?
  return headers['Authorization'].split(' ').last
else
  errors.add(:token, 'Missing token')
end
code_aks
  • 1,972
  • 1
  • 12
  • 28