Source

copelco / lib / copelco / apps / flickr / api / auth.py

Full commit
# requires oauth2==1.5.170
def _authenticate(self):
    consumer = oauth.Consumer(key=self._consumer_key,
                              secret=self._consumer_secret)
    # get request token
    params = {
        'oauth_timestamp': str(int(time.time())),
        'oauth_signature_method': "HMAC-SHA1",
        'oauth_version': "1.0",
        'oauth_callback': ' ',
        'oauth_nonce': oauth.generate_nonce(),
        'oauth_consumer_key': self._consumer_key,
    }
    req = oauth.Request('GET', self.request_token_url, params)
    req.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, None)
    response = urllib2.urlopen(req.to_url())
    data = dict(urlparse.parse_qsl(response.read()))
    self.request_token = oauth.Token(data['oauth_token'],
                                     data['oauth_token_secret'])
    # authorize
    auth_params = {
        'perms': 'read',
        'oauth_token': self.request_token.key,
    }
    req = oauth.Request('GET', self.authorize_url, auth_params)
    req.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, None)
    response = urllib2.urlopen(req.to_url())