added tokens

This commit is contained in:
olegphenomenon 2022-02-09 16:18:25 +02:00
parent c2969fa877
commit 7e0c6b3afb
13 changed files with 94 additions and 62 deletions

View file

@ -46,11 +46,6 @@ end
def base_request(url:, json_obj:)
uri = URI(url)
http = Net::HTTP.new(uri.host, uri.port)
headers = {
'Authorization' => 'Bearer foobar',
'Content-Type' => 'application/json',
'Accept' => TOKEN
}
unless Rails.env.development?
http.use_ssl = true
@ -59,3 +54,19 @@ def base_request(url:, json_obj:)
http.post(url, json_obj.to_json, headers)
end
def generate_token
JWT.encode(payload, ENV['secret_word'])
end
def payload
{ data: ENV['secret_access_word'] }
end
def headers
{
'Authorization' => "Bearer #{generate_token}",
'Content-Type' => 'application/json',
}
end