Skip to content

Synchronous OAuth 2.0 authentication for command-line python programs

Notifications You must be signed in to change notification settings

vivekseth/generic_oauth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Synchronous OAuth 2.0 authentication for command-line python programs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages