Skip to main content

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


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

sanic_oauth-0.1.1-py2.py3-none-any.whl (13.6 kB view hashes)

Uploaded Python 2 Python 3

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