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

If you're not sure about the file name format, learn more about wheel file names.

sanic_oauth-0.1.0-py2.py3-none-any.whl (4.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sanic_oauth-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sanic_oauth-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1206e07897e1437307111f9efc5793293578858f5196382ec4765a1ff4393c54
MD5 a7e7f0605e6dfebf51161d346f038ddd
BLAKE2b-256 44eed5d5d6b29fe5371047e0f98376156c8ca72f3fea5188e4deb84a504b62e5

See more details on using hashes here.

Supported by

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