Skip to main content

A Python wrapper for the OAuth 2.0 specification.

Project description

A Python wrapper for the OAuth 2.0 specification

Installation

pip:

pip install py-oauth2

easy_install:

easy_install py-oauth2

Usage Examples

Demo for Google

Get user info:

from pyoauth2 import Client

CLIENT_ID = ''
CLIENT_SECRET = ''
REDIRECT_URL = ''
SCOPE = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'

client = Client(CLIENT_ID, CLIENT_SECRET,
                site='https://www.googleapis.com/oauth2/v1',
                authorize_url='https://accounts.google.com/o/oauth2/auth',
                token_url='https://accounts.google.com/o/oauth2/token')

print '-' * 80
authorize_url = client.auth_code.authorize_url(redirect_uri=REDIRECT_URL, scope=SCOPE)
print 'Go to the following link in your browser:'
print authorize_url

code = raw_input('Enter the verification code and hit ENTER when you\'re done:')
code = code.strip()
access_token = client.auth_code.get_token(code, redirect_uri=REDIRECT_URL)
print 'token', access_token.headers

print '-' * 80
print 'get user info'
ret = access_token.get('/userinfo')
print ret.parsed

Demo for Douban

Get access_token:

from pyoauth2 import Client

KEY = ''
SECRET = ''
CALLBACK = ''

client = Client(KEY, SECRET,
                site='https://api.douban.com',
                authorize_url='https://www.douban.com/service/auth2/auth',
                token_url='https://www.douban.com/service/auth2/token')

authorize_url = client.auth_code.authorize_url(redirect_uri=CALLBACK, scope='shuo_basic_w,douban_basic_common')

access_token = client.auth_code.get_token(code, redirect_uri=CALLBACK)

Get data:

ret = access_token.get('/v2/user/~me')
print ret.parsed

Upload image:

ret = access_token.post('/shuo/v2/statuses/', text='content from py-oauth2', files={ 'image': open('/path/pic.jpg')})
print ret.parsed

More:

Examples

Demo for Google

Demo for Douban(auth with code)

Demo for Douban(auth with token)

Demo for Douban(auth with password)

Demo for GitHub

Demo for Weibo

Demo for QQ

Demo for Taobao

Demo for Box.com

Demo for Instagram

Submitting a Pull Request

  • Fork the repository.

  • Create a topic branch.

  • Implement your feature or bug fix.

  • Add, commit, and push your changes.

  • Submit a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-oauth2-0.0.10.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file py-oauth2-0.0.10.tar.gz.

File metadata

  • Download URL: py-oauth2-0.0.10.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py-oauth2-0.0.10.tar.gz
Algorithm Hash digest
SHA256 9a5a12a38f98afca008f81ca412125d576d053cd73f2d61b574be8a65309f515
MD5 8b6875c1ab9c01fc9bc8fc5525d82452
BLAKE2b-256 93fe2a44efad2c7a65eac33c1b559bb2b3e3883ee629d05af55221aa00c4a0bd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page