0

Timestamp returns out of bounds when seemingly in bounds

I've been trying to solve this for the past few days. I get through getting a request token and user authorization but the exchange is giving me trouble. Every request returns: oauth_problem=timestamp_refused but the code is telling me that the timestamp is in the threshold.

My outputted stamp: 1374799548 oauth_acceptable_timestamps=1374798948-1374800148

Can someone help me understand what I might be missing?

import oauth2 as oauth
import time
import urllib
import urlparse

GET_TOKEN_URL = '<https://api.login.yahoo.com/oauth/v2/get_token>'
AUTHORIZATION_URL = '<https://api.login.yahoo.com/oauth/v2/request_auth>'
REQUEST_TOKEN_URL = '<https://api.login.yahoo.com/oauth/v2/get_request_token?oauth_callback=oob>'
CUSTOMER_SECRET = 'xxxx'
CUSTOMER_ID = 'xxxx'


consumer = oauth.Consumer(CUSTOMER_ID, CUSTOMER_SECRET)
client = oauth.Client(consumer)


def request_token():

    params = {
        'oauth_version': "1.0",
        'oauth_nonce':oauth.generate_nonce(),
        'oauth_consumer_key': CUSTOMER_ID, 
        'oauth_signature_method':'HMAC-SHA1',
        'oauth_version':1.0,
        'xoauth_lang_pref':'en-us',
        'oauth_timestamp':str(int(time.time()))
    }


    token = oauth.Token(key="tok-test-key", secret="tok-test-secret")

    req = oauth.Request(method="GET", url=REQUEST_TOKEN_URL, parameters=params)
    signature_method = oauth.SignatureMethod_HMAC_SHA1()
    req.sign_request(signature_method, consumer, token)
    resp = client.request(req.url)
    response = dict(urlparse.parse_qsl(resp[1]))
    token_secret = response['oauth_token_secret']
    print response['xoauth_request_auth_url']

    if resp[0]['status'] != '200':
        raise Exception("Invalid response %s." % resp[0]['status'])

    oauth_token = response['oauth_token']

    accepted='n'
    while accepted.lower() == 'n':
        accepted = raw_input('Have you authorized me? (y/n) ')

    oauth_verifier = raw_input('oauth_verifier code: ')


    return oauth_token, token_secret, oauth_verifier

def req_auth(token, token_secret, url):

    params = {
        'oauth_version': "1.0",
        'oauth_nonce':oauth.generate_nonce(),
        'oauth_consumer_key': CUSTOMER_ID, 
        'oauth_signature_method':'PLAINTEXT',
        'oauth_version':1.0,
        'xoauth_lang_pref':'en-us',
        'oauth_timestamp':str(int(time.time())),
        'oauth_verifier':url,
        'oauth_token':token,      
    }


    ntoken = oauth.Token(token,token_secret)
    ntoken.set_verifier(url)

    token = oauth.Token(key=CUSTOMER_SECRET, secret=token_secret)

    req = oauth.Request(method="GET", url=GET_TOKEN_URL, parameters=params)
    signature_method = oauth.SignatureMethod_HMAC_SHA1()
    req.sign_request(signature_method, consumer, token) 
    encode_url = urllib.urlencode(req)
    print req.url+'?'+encode_url

    resp, content = client.request(req.url+'?'+encode_url)
    print params['oauth_timestamp']
    print resp, content

a, b, c = request_token()
req_auth(a, b, c)

by
0 Replies

Recent Posts

in OAuth General Discussion YDN SDKs