How do I use the token to authenticate with Heroku in Ruby using their gem?

64 views Asked by At

I can successfully list pipelines using the heroku-cli (actual names hidden for security):

$ heroku pipelines
=== My Pipelines
...-qa-pipeline
...-qa-pipeline
...-qa-pipeline

When I try to do the same in Ruby, I get a 401 Unauthorized:

require "platform-api"
heroku = PlatformAPI.connect_token(`heroku auth:token`.strip)
heroku.pipeline.list

This results in:

/home/pupeno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/excon-0.99.0/lib/excon/middlewares/expects.rb:13:in `response_call': Expected([200, 201, 202, 204, 206, 304, 429]) <=> Actual(401 Unauthorized) (Excon::Error::Unauthorized)
        from /home/pupeno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/excon-0.99.0/lib/excon/middlewares/response_parser.rb:12:in `response_call'                                                                                    
        from /home/pupeno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/excon-0.99.0/lib/excon/connection.rb:459:in `response'                                                                                                         
        from /home/pupeno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/excon-0.99.0/lib/excon/connection.rb:290:in `request'                                                                                                          
        from /home/pupeno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/heroics-0.1.2/lib/heroics/link.rb:118:in `block in request_with_cache'                                                                                         
        from /home/pupeno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rate_throttle_client-0.1.2/lib/rate_throttle_client/clients/exponential_increase_proportional_remaining_decrease.rb:17:in `call'                               
        from /home/pupeno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/heroics-0.1.2/lib/heroics/link.rb:117:in `request_with_cache'                                                                                                  
        from /home/pupeno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/heroics-0.1.2/lib/heroics/link.rb:68:in `run'                                                                                                                  
        from /home/pupeno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/heroics-0.1.2/lib/heroics/resource.rb:28:in `method_missing'                                                                                                   
        from /home/pupeno/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/platform-api-3.5.0/lib/platform-api/client.rb:2610:in `list'                                                                                                   
        from (irb):3:in `<main>'

What am I missing here?

1

There are 1 answers

0
Pablo Fernandez On

Instead of

heroku = PlatformAPI.connect_token(`heroku auth:token`.strip)

I used

heroku = PlatformAPI.connect(`heroku auth:token`.strip)

which worked. Apparently what heroku auth:token gives you is not a token but an api key: http://heroku.github.io/platform-api/PlatformAPI.html#connect-class_method