我如何使用令牌在Ruby中使用他们的gem与Heroku进行身份验证?

neskvpey  于 2023-05-22  发布在  Ruby
关注(0)|答案(1)|浏览(85)

我可以使用heroku-cli成功地列出管道(为了安全起见隐藏了实际名称):

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

当我尝试在Ruby中做同样的事情时,我得到了一个401 Unauthorized:

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

这导致:

/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>'

我错过了什么?

pgpifvop

pgpifvop1#

而不是

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

我以前

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

这很有效显然,heroku auth:token给你的不是一个令牌,而是一个API密钥:http://heroku.github.io/platform-api/PlatformAPI.html#connect-class_method

相关问题