Giter VIP home page Giter VIP logo

generic_oauth's Introduction

Generic Oauth

Description

generic_oauth provides synchronous OAuth 2.0 authentication for command-line python programs. With any of the provided implementations you can get an access token for an OAuth service in just 2 lines of code.

To install use: pip install generic_oauth

Typically, OAuth services are used by web-apps becuase the protocol requires use of a browser. This can be frustrating for people who want to build simple, command-line programs that use OAuth APIs. Let's say you want to use Spotify's API, to get data on the music you listen to. You shouldnt have to build a web-app first. Using generic_oauth you can authenticate your app to use an OAuth API directly from your python program.

The following implementations included:

  • Google
  • Github
  • Facebook
  • Spotify

Sample Usage

import requests
from generic_oauth import SpotifyOAuth

client_id = '<your info here>'
client_secret = '<your info here>'
redirect_uri = 'http://localhost:5555'
scope_string = '<your info here>'

# Get a spotify access_token in just 2 lines. 
o = SpotifyOAuth(client_id, client_secret, redirect_uri, scope_string)
access_data = o.get_access_code()

headers = {'Authorization': 'Bearer ' + access_data['access_token']}
r = requests.get('https://api.spotify.com/v1/me', headers=headers)
print r.json()

Documentation

OAuthWebFlowController is an abstract class responsible for handling the bulk of the oauth 2.0 web flow. To implement a handler for an OAuth api not already included, you will need to make a subclass of this class and override the authorization_url() and parse_temp_code() methods.

OAuthWebFlowController creates a temporarly local HTTP server to accept data sent to the redirect_uri. The default redirect_uri supported is http://localhost:5555. If you would like to use a different url, you will need to change the port param in the __init__ method. For example if you use http://localhost:4321, you would set port=4321.

generic_oauth's People

Contributors

oylbin avatar vivekseth avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.