Basic Auth with Ruby on Rails(Faraday gem)
Code Salley

Code Salley @codesalley

About: Software developer. Hacking with ruby

Location:
Nalerigu Ghana
Joined:
Jan 24, 2021

Basic Auth with Ruby on Rails(Faraday gem)

Publish Date: Nov 28 '21
5 0

Faraday gem comes in handy with several plugins(middleware) that make HTTP request easier and more customisable, Basic authentication in ruby turn to be tricky. let's digest it;

require "faraday"

request_helper = Faraday.new(url: 'example.com') do |builder|
                builder.use Faraday::Request::BasicAuthentication, client_key, secret_key
             end

# you make HTTP requests using `request_helper` since basic auth is configured

response = request_helper.get('/myendpoit')
Enter fullscreen mode Exit fullscreen mode

Using an API like PAYPAL API, you need to get tokens by proving client and secret keys. With Faraday::Request::BasicAuthentication middleware we can pass client and secret keys as arguments to achieve basic authentication using the same method above.

twitter: code salley

Comments 0 total

    Add comment