c10l / cookbook-deploy_key

Idempotent Chef LWRP for creating, adding, removing and deleting SSH Deploy Keys on Bitbucket and Github
https://supermarket.getchef.com/cookbooks/deploy_key
Other
44 stars 27 forks source link

Token with bitbucket? #4

Open allaire opened 10 years ago

allaire commented 10 years ago

Which token are we supposed to use with Bitbucket? Currently I'm using username/password, and using the API key as the password.

c10l commented 10 years ago

I'm not sure what's the API key you're using for password. My understanding is that if you use HTTP Basic authentication (as when you supply the LWRP with a user/pass combination) you're using an actual Bitbucket user and its password for credentials.

The token authentication scheme is for OAuth tokens.

allaire commented 10 years ago

See here: https://confluence.atlassian.com/display/BITBUCKET/Use+the+Bitbucket+REST+APIs#UsetheBitbucketRESTAPIs-Authentication

You can use the Bitbucket API key for authentification (password).

The page oauth page you linked to creates two keys

c10l commented 10 years ago

Hey, sorry for not having looked into this for so long, but I was busy moving to another country. :)

I couldn't find any mention to an API key on the docs you linked. That's for a user's username and password as I mentioned before (or I might be drunk).

For the OAuth scheme, you have to create an Application Key first, then create an Access Token. The latter is the one you'll use to authenticate against the API.

bgaillard commented 10 years ago

Hi, I follow the guide provided here to create an Access Token.

https://confluence.atlassian.com/display/BITBUCKET/OAuth+on+Bitbucket

At the end of the guide (Step 4. Request an Access Token) the last request returns something like this :

oauth_token_secret=XXXX&oauth_token=YYYY

What do I have to use in the :token parameter ? Is it XXXX or YYYY ?

I tried both but I always get an HTTP 403 error (Access Forbidden).

deploy_key "bitbucket_key" do
  provider Chef::Provider::DeployKeyBitbucket
  path '/home/vagrant/.ssh'
  credentials({
    :token => 'XXXX'
  })
  repo 'my_company/my_project'
  owner 'vagrant'
  group 'vagrant'
  mode 00640
  action :add
end

Thanks,

Baptiste

c10l commented 10 years ago

I have to be honest with you and say that I haven't used this auth mechanism in BitBucket.

That said, have you tried sending the whole string, as in :token => 'oauth_token_secret=XXXX&oauth_token=YYYY'? That seems to be what you need. Let me know if it works for you.

bgaillard commented 10 years ago

Hi @cassianoleal, thanks for you quick response.

I tried with :token => 'oauth_token_secret=XXXX&oauth_token=YYYY' but encounter the same 403 error code.

mariomarin commented 10 years ago

@bgaillard Did you find a workaround?

bgaillard commented 10 years ago

Hi @mariomarin, sadly I did not found any solution for this, let me know if you find a workaround.

c10l commented 10 years ago

I've been doing some reading, and this should actually have been a full-blown OAuth implementation. I'll have to study it a bit further in order to get this to work, and I'm not sure I'll have the time any time soon.

If any of you want to take a stab at it, please do so. Pull requests are always welcome! :smile:

paralin commented 10 years ago

Wow, the last message on this is really recent.

I'd also like to set this up properly. It seems you have to get the token like

https://bitbucket.org/api/1.0/oauth/request_token?oauth_version=1.0&oauth_nonce=7f2325b3c36bd49afa0a33044d7c6930&oauth_timestamp=1366243208&oauth_consumer_key=HUpRcDUduZrepL6sYJ&oauth_callback=http%3A%2F%2Flocal%3Fdump&oauth_signature_method=HMAC-SHA1&oauth_signature=qZyTwVA48RzmtCHvN9mYWmlmSVU%3D

So we would need a full oauth implementation...

Why not just use https://github.com/vongrippen/bitbucket? Install the bitbucket gem and use the API to deploy.

7h3kk1d commented 10 years ago

+1

c10l commented 10 years ago

@kidovate I might have a look at that. It's worth noting, though that the maintainer has dropped support for that gem.

dynnamitt commented 9 years ago

https://bitbucket.org/site/master/issue/10182/access-tokens-for-command-line-use