Skip to main content

a simple, lightweight oauth client

Project description

oauth2py

PyPI version Build Status

a simple, lightweight oauth client

require

python 2.7

supported

  • [x] Weibo

  • [ ] QQ

  • [x] Facebook

  • [x] Github

  • [x] Twitter

  • [ ] Other…

useage

  1. create client

    • put oauth2py.config.json in your app folder

    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': ''
    })
  2. get login url

    url = github.get_login_url(state='abc')
  3. get user info

    user = github.get_user_info('code=12345&state=abc')
    # or
    user = github.get_user_info({'code': '12345', 'state': 'abc'})
  4. get access token

    token = github.get_access_token()

add providers

  • inherit oauth2py.Oauth2 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': response['id'],
            'name': response['name'],
            'avatar': response['avatar_url'],
            'raw': response
        }

Project details


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.0.2.tar.gz (4.6 kB view hashes)

Uploaded source

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