OAuth2 INTRIDEA gem and HTTP basic authentication header

Using INTRIDEA’s OAuth2 Ruby gem, is there a recommended way to add the HTTP basic authentication header using the password strategy?

The required header I’m working with is of the following format:

Authorization: Basic <base 64 encoded "CLIENT_ID:CLIENT_SECRET">

The following doesn’t work and doesn’t seem to add the Authorization header:

client = OAuth2::Client.new('CLIENT_ID', 'CLIENT_SECRET', :site => 'https://example.com)
token  = client.password.get_token('USERNAME', 'PASSWORD')

The following works, but is verbose:

client = OAuth2::Client.new('CLIENT_ID', 'CLIENT_SECRET', :site => 'https://example.com)
token  = client.password.get_token('USERNAME', 'PASSWORD', { 
  :headers => { 'Authorization' => 'Basic ' + Base64.strict_encode64("CLIENT_ID:CLIENT_SECRET") 
})

The password strategy examples I’ve seen don’t explicitly include the header so I’m wondering how it’s done.


Source: ruby

Leave a Reply