Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a oauth2 token to create a connection with HTTParty

I am trying to connect to the Basecamp API using HTTParty, I am however getting an issue with authentication.

I am getting an error "HTTP Basic: Access denied", which doesn't make sense when I am trying to do OAuth.

The class looks a bit like this (The XXXX comes from other places, but is just hardcoded for the example here).

 class Basecamp
    include HTTParty

    def initialize(oauth_token)
        self.class.base_uri "https://basecamp.com/XXXXX/api/v1/"
        @options = {
            headers: {
                "Authorization" => oauth_token,
                "User-Agent" => 'XXXX (XXXXXX)'
            }
        }
    end

    def projects
        self.class.get('/projects.json', @options)
    end

    def users
        self.class.get('/people.json', @options)
    end
end
like image 609
Dofs Avatar asked Dec 30 '25 21:12

Dofs


1 Answers

According to the documentation, the header should be

Authorization: Bearer YOUR_OAUTH_TOKEN

in your case, assuming oauth_token is the token, you are passing

Authorization: YOUR_OAUTH_TOKEN

Change the header to

"Authorization" => "Bearer #{oauth_token}",
like image 199
Simone Carletti Avatar answered Jan 01 '26 13:01

Simone Carletti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!