a simple, lightweight oauth client
Project description
oauth2py
a simple, lightweight oauth client
require
python 2.7+
python 3.3+
supported
[x] Weibo
[x] QQ
[x] Facebook
[x] Github
[x] Twitter
[ ] Other…
useage
create client
put oauth2py.json in your app root folder
[{ "name": "github", "client_id": "", "client_secret": "", "redirect_uri": "", "scope": "" }, { "name": "twitter", "client_id": "", "client_secret": "", "redirect_uri": "", "scope": "" }]from oauth2py.client import OauthClient as oauth github = oauth.load('github')or set config in code
github.init({ 'client_id': '', 'client_secret': '', 'redirect_uri': '', 'scope': '' })oauth
get login url
url = github.get_login_url(state='abc')get user info
user = github.get_user_info('code=12345&state=abc') # or user = github.get_user_info({'code': '12345', 'state': 'abc'})save access token
token = github.get_access_token() # save token ...access resource
get github repo list
github.set_access_token({ 'access_token': '...' }) github.access_resource( 'GET', 'https://api.github.com/user/repos')another example: post status to twitter
twitter.set_access_token({ 'access_token': '...', 'access_token_secret': '...' } ) twitter.access_resource( 'POST', url='https://api.twitter.com/1.1/statuses/update.json', data={ 'status': 'test from oauth2py!' } )
implement new providers
inherit oauth2py.Oauth2 or oauth2py.Oauth and set oauth urls
class Github(Oauth2): NAME = 'Github' AUTHORIZATION_URL = 'https://github.com/login/oauth/authorize' ACCESS_TOKEN_URL = 'https://github.com/login/oauth/access_token' GET_USERINFO_URL = 'https://api.github.com/user' def __init__(self): super(Github, self).__init__()parse user info from response
def parse_user_info(self, response): return { 'uid': str(response.get('id')), 'name': response.get('name'), 'avatar': response.get('avatar_url'), 'raw': response }
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
oauth2py-1.1.5.tar.gz
(5.3 kB
view details)
File details
Details for the file oauth2py-1.1.5.tar.gz.
File metadata
- Download URL: oauth2py-1.1.5.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5653e22e025caac775e3a027f250020574f9ca35210b3c8317b235540a27626
|
|
| MD5 |
077b7f1b6ac1a925dcad2b8ec83b6942
|
|
| BLAKE2b-256 |
09a99cd902179562ad534df9f3f5c3fd8001903153ddc6f19aa8d993b55a2bc6
|