[PYTHON] Bitbucket OAuth: Until access token acquisition

It didn't work if it was on the official website, so make a note of it.

Consumer registration

There is a place to log in to the Bitbucket site and register for Integrated applications in your account settings.

Authenticate

Now that we have the Consumer key and Consumer secret, we need to look up the authentication URL. https://confluence.atlassian.com/display/BITBUCKET/oauth+Endpoint Is like an official document, but for some reason this Japanese page http://confluence.atlassian.jp/pages/viewpage.action?pageId=33687493 Is more like the correct answer. I felt uncomfortable with the! On the URL, so I took it and it succeeded.

OAUTH_REQUEST = "https://bitbucket.org/api/1.0/oauth/request_token"
OAUTH_AUTH = "https://bitbucket.org/api/1.0/oauth/authenticate"
OAUTH_ACCESS = "https://bitbucket.org/api/1.0/oauth/access_token"

Now, all you have to do is authenticate. I'd like to say that you can use any method you like, but I'll post a sample (Python) because it's a big deal. I am using a library called rauth.

from rauth.service import OAuth1Service
def authorize():
    service = OAuth1Service(name='bitbucket', consumer_key=CONSUMER_KEY, consumer_secret=CONSUMER_SECRET,
                         request_token_url=OAUTH_REQUEST,
                         access_token_url=OAUTH_ACCESS,
                         authorize_url=OAUTH_AUTH)
    rtoken, rtokensecret = service.get_request_token(method='GET')
    auth_url = service.get_authorize_url(rtoken)
    print "Visit this url and copy&paste your PIN.\n{0}".format(auth_url)
    pin = raw_input('Please enter your PIN:')
    r = service.get_access_token('POST', request_token=rtoken, request_token_secret=rtokensecret,
                                 data={'oauth_verifier': pin})
    content = r.content
    return content['oauth_token'], content['oauth_token_secret']

Then.

Recommended Posts

Bitbucket OAuth: Until access token acquisition
Get an access token by OAuth authentication