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.1-py2.py3-none-any.whl (13.6 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

File hashes

Hashes for sanic_oauth-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1f7fb0597436913e04493b0ff206075d4bcf4edff25328c88e03f6c6840b9539
MD5 bee23b163cc1996f92a04e19e33c8a0c
BLAKE2b-256 a4da0e6a2f0cdee1882e64b4597d417d488e771845d873931c77233d2bd3fcd8

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