bitbucket-rest-api / bitbucket

BitBucket API gem - bitbucket_rest_api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't get oAuth to work with omniauth-bitbucket

keithpitt opened this issue Β· comments

Hey,

Forgive my ignorance, but for the lack of a better idea, I need some help with debugging this oAuth problem - which I'm sure your sick of by now πŸ˜„

I've successfully gotten a token/secret by using https://github.com/sishen/omniauth-bitbucket.

I'm trying to access the BitBucket API like so:

omniauth       = request.env['omniauth.auth']
token          = omniauth['credentials']['token']
secret         = omniauth['credentials']['secret']
bitbucket      = BitBucket.new(oauth_secret: secret, oauth_token: token)

But I'm getting a BitBucket::Error::Unauthorized on every call. Do I have to include my consumer key/secret or something? Am I storing the wrong thing from the bitbucket omniauth auth_hash perhaps?

Keith

Yeah, this is one that people get tripped up on. When initializing the BitBucket object, you have to also set consumer_secret and consumer_id. Check the block-style initialization here: https://github.com/vongrippen/bitbucket#usage

Oh right! Perhaps we should delete this example this:

bitbucket = BitBucket.new oauth_token: 'request_token', oauth_secret: 'request_secret'

That's what I was looking at.

I thought that block was for enterpise only:

Alternatively, you can configure the BitBucket settings by passing a block, for instance, with custom enteprise endpoint like

Yeah, sorry it wasn't very clear. One way of setting things up is to set the consumer_token and _id on the class itself and then any objects instantiated after that time would already have the consumer credentials set, after which you could leave them out of the BitBucket.new

If you get down into the rdocs, it's a bit more explicit if I remember correctly. It was mostly just to show an extended example of the different ways of using it.

Basically you can configure it using a block, using the initializer, or via class methods. However you want.

I've changed the code to allow you to supply your consumer key and consume the api that way. #25