0

how can i invalidate a bearer token from twitter with rauth?(https://dev.twitter.com/docs/api/1.1/post/oauth2/invalidate_token)

I tried to do it via a oauth2 session but it doesn't work. By the way, is there a way to see the complete request which will be send/which is created by rauth? This could be very helpful for debugging and to understand what rauth produces.

Here is my code so far:

session = rauth.OAuth2Session(client_id=c_key,
                              client_secret=c_secret,
                              access_token=o_bearer_token)

bearer_raw = session.post('https://api.twitter.com/oauth2/invalidate_token',
                           params={ 'Host': 'api.twitter.com',
                                            'User-Agent': '',
                                            'Accept': '*/*',
                                            'Content-Type': 'application/x-www-form-urlencoded',
                                            'Content-Length': str(len(o_bearer_token)),
                                            'access_token':str(o_bearer_token)})
tMC
  • 18,105
  • 14
  • 62
  • 98
el_pedro
  • 32
  • 7
  • Why are your headers going into the `params` dict? Remember that Rauth is fundamentally Requests: you should use it just like Requests. Headers should be passed in the `headers` param. – maxcountryman Sep 30 '13 at 20:29
  • Yes right the params have to be in the header. I think there is a problem with the invalidate_token endpoint on twitter. I try to get it to work with pycurl and it works sometimes. Can't say when it works and when it doens't work and why. – el_pedro Oct 01 '13 at 12:35

1 Answers1

0

I think the request is being formatted improperly. It looks like the Twitter docs are indicating that it should be something like this:

session = rauth.OAuth2Session(client_id=KEY,
                              client_secret=SECRET,
                              access_token=TOKEN)

r = session.post('https://api.twitter.com/oauth2/invalidate_token', bearer_auth=True)

By the way, Rauth is Requests; it's just a layer on top of Requests. So yes, you can see a request as you would with Requests. Something like r.request should expose what you're looking for.

maxcountryman
  • 1,562
  • 1
  • 24
  • 51