Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signing requests with python-oauth2 [closed]

The Github page of python-oauth2 gives instructions on creating signed requests with req = oauth.Request(...), which returns a dictionary that can be signed. But how do I actually send these requests?

like image 575
Steve Avatar asked Mar 26 '12 15:03

Steve


People also ask

How does OAuth 2.0 work in REST API?

Using OAuth 2.0, it is possible for the application to access the user's data without the disclosure of the user's credentials to the application. The API will grant access only when it receives a valid access token from the application.

Does OAuth2 require browser?

OAuth 2.0 requires a browser for user consent once A browser is required, so that the user can agree to the request of the app to access the users data. After the user agreed on sharing the data with the app, the app can use the refresh token without a browser based flow.


2 Answers

Just add this line at the end:

rs = urllib2.urlopen(req.to_url())

Where req is your Request object.

like image 150
Manish Avatar answered Sep 28 '22 03:09

Manish


Look at the next step in the README.

Using the Client

import oauth2 as oauth

# Create your consumer with the proper key/secret.
consumer = oauth.Consumer(key="your-twitter-consumer-key", 
    secret="your-twitter-consumer-secret")

# Request token URL for Twitter.
request_token_url = "http://twitter.com/oauth/request_token"

# Create our client.
client = oauth.Client(consumer)

# The OAuth Client request works just like httplib2 for the most part.
resp, content = client.request(request_token_url, "GET")
print resp
print content
like image 31
abraham Avatar answered Sep 28 '22 03:09

abraham