No project description provided
Project description
Simple OAuth library to work with sanic. Basically, just rewrited version of aioauth_client with async/await syntax and some optimization. Can be used only with python 3.5/3.6.
Available providers:
Google
GitLab
BitBucket
BitBucket v2
Flickr
Meetup
Plurk
Twitter
Tumblr
Vimeo
Yahoo
Amazon
Eventbrite
Facebook
Foursquare
Github
vk.com
ok.ru
Yandex
LinkedIn
Pinterest
Requirements
python >= 3.6
Installation
Just install via pip:
pip install sanic_oauth
Usage
# OAuth1
import aiohttp
from sanic_oauth import TwitterClient
session = aiohttp.ClientSession()
twitter = TwitterClient(
session
consumer_key='J8MoJG4bQ9gcmGh8H7XhMg',
consumer_secret='7WAscbSy65GmiVOvMU5EBYn5z80fhQkcFWSLMJJu4',
)
request_token, request_token_secret, _ = await twitter.get_request_token()
authorize_url = twitter.get_authorize_url(request_token)
print("Open",authorize_url,"in a browser")
# ...
# Reload client to authorize_url and get oauth_verifier
# ...
print("PIN code:")
oauth_verifier = input()
oauth_token, oauth_token_secret, _ = await twitter.get_access_token(oauth_verifier)
# Save the tokens for later use
# ...
twitter = TwitterClient(
session,
consumer_key='J8MoJG4bQ9gcmGh8H7XhMg',
consumer_secret='7WAscbSy65GmiVOvMU5EBYn5z80fhQkcFWSLMJJu4',
oauth_token=oauth_token,
oauth_token_secret=oauth_token_secret,
)
timeline = await twitter.request('GET', 'statuses/home_timeline.json')
content = await timeline.read()
print(content)
session.close()
# OAuth2
import aiohttp
from aioauth_client import GithubClient
session = aiohttp.ClientSession()
github = GithubClient(
session,
client_id='b6281b6fe88fa4c313e6',
client_secret='21ff23d9f1cad775daee6a38d230e1ee05b04f7c',
)
authorize_url = github.get_authorize_url(scope="user:email")
# ...
# Reload client to authorize_url and get code
# ...
otoken, _ = await github.get_access_token(code)
# Save the token for later use
# ...
github = GithubClient(
session,
client_id='b6281b6fe88fa4c313e6',
client_secret='21ff23d9f1cad775daee6a38d230e1ee05b04f7c',
access_token=otoken,
)
response = await github.request('GET', 'user')
user_info = await response.json()
session.close()
Example
You can see example with sanic_session usage. Google credentials are wrong, so to run it you will need own.
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for sanic_oauth-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05da017a63f295c2cb630786149698784146c0cd2c93bf42b8ee27cd3c30749d |
|
MD5 | f657a8ea682aeaa7ec1048754d67963b |
|
BLAKE2b-256 | 025ae3cdbe41d123bc48dd67fc6d6b298ff9ab5b7e86b24a8da8171997075f2b |