GitHub-Flask Documentation

Similar documents
Flask-Twilio Documentation

sanction Documentation

flask-jwt-simple Documentation

flask-jwt Documentation

Using OAuth 2.0 to Access ionbiz APIs

WEB API. Nuki Home Solutions GmbH. Münzgrabenstraße 92/ Graz Austria F

django-oauth2-provider Documentation

Flask Web Development Course Catalog

Leveraging the Globus Platform in your Web Applications

invenio-oauthclient Documentation

Leveraging the Globus Platform in your Web Applications. GlobusWorld April 26, 2018 Greg Nawrocki

flask-jwt-extended Documentation

PowerExchange for Facebook: How to Configure Open Authentication using the OAuth Utility

bzz Documentation Release Rafael Floriano and Bernardo Heynemann

Flask-Cors Documentation

HOW TO FLASK. And a very short intro to web development and databases

f5-icontrol-rest Documentation

Connexion Documentation

Flask-OAuthlib Documentation

Integrating with ClearPass HTTP APIs

GPII Security. Washington DC, November 2015

CIS192 Python Programming

DJOAuth2 Documentation

httpclient Documentation

Android InsecureBankv2 Usage Guide. InsecureBankv2

Privacy and Security in Online Social Networks Department of Computer Science and Engineering Indian Institute of Technology, Madras

Full Stack Web Developer Nanodegree Syllabus

python-oauth2 Documentation

CIS192 Python Programming

ClickToCall SkypeTest Documentation

bottle-rest Release 0.5.0

PyCrest Documentation

ovirt SSO Specification

OAuth2 Autoconfig. Copyright

django-telegram-login Documentation

The production version of your service API must be served over HTTPS.

Jackalope Documentation

flask-praetorian Documentation

Aruba Central Application Programming Interface

AEM Mobile: Setting up Google as an Identity Provider

sandman Documentation

Building the Modern Research Data Portal using the Globus Platform. Rachana Ananthakrishnan GlobusWorld 2017

Using Keycloak to Provide Authentication, Authorization, and Identity Management Services for Your Gateway

Quick housekeeping Last Two Homeworks Extra Credit for demoing project prototypes Reminder about Project Deadlines/specifics Class on April 12th Resul

hca-cli Documentation

BlackBerry AtHoc Networked Crisis Communication. BlackBerry AtHoc API Quick Start Guide

Lab 2 Third Party API Integration, Cloud Deployment & Benchmarking

Yampy Documentation. Release 1.0. Yammer

Distributed Systems. 03r. Python Web Services Programming Tutorial. Paul Krzyzanowski TA: Long Zhao Rutgers University Fall 2017

E POSTBUSINESS API Login-API Reference. Version 1.1

CS October 2017

Bambu API Documentation

Security Guide Release 7.1

micawber Documentation

Creating relying party clients using the Nimbus OAuth 2.0 SDK with OpenID Connect extensions

Flask restful swagger Documentation

1. License. 2. Introduction. a. Read Leaderboard b. Write and Flush Leaderboards Custom widgets, 3D widgets and VR mode...

Mobile Procurement REST API (MOBPROC): Access Tokens

eventbrite-sdk-python Documentation

yagmail Documentation

NetIQ Access Manager 4.3. REST API Guide

flask-ldap3-login Documentation

Pacific Gas and Electric Company

FAS Authorization Server - OpenID Connect Onboarding

INTEGRATION MANUAL DOCUMENTATION E-COMMERCE

CIS192 Python Programming

FAS Authorization Server - OpenID Connect Onboarding

RSA NetWitness Logs. Salesforce. Event Source Log Configuration Guide. Last Modified: Wednesday, February 14, 2018

python-jose Documentation

boxsdk Documentation Release Author

Usage of "OAuth2" policy action in CentraSite and Mediator

Flask-SimpleLDAP Documentation

Flask-Migrate Documentation. Miguel Grinberg

Inland Revenue. Build Pack. Identity and Access Services. Date: 04/09/2017 Version: 1.5 IN CONFIDENCE

django-ratelimit-backend Documentation

FAS Authorization Server - OpenID Connect Onboarding

Salesforce IoT REST API Getting Started Guide

Back-end development. Outline. Example API: Chatter. 1. Design an example API for Chatter. Tiberiu Vilcu.

json-rpc Documentation

Realtime API. API Version: Document Revision: 16 Last change:26 October Kwebbl Swiss Software House GmbH

The Current State of OAuth 2. Aaron Open Source Bridge Portland, June 2011

ska Documentation Release Artur Barseghyan

Check to enable generation of refresh tokens when refreshing access tokens

fredag 7 september 12 OpenID Connect

RedBarrel Documentation

API Gateway. Version 7.5.1

Kuyruk Documentation. Release 0. Cenk Altı

for Salesforce Question-to-Case Connector

APIs and API Design with Python

py-couchdb Documentation

Bomgar PA Integration with ServiceNow

CIS 192: Lecture 9 Working with APIs

Building Web Applications

PyOTP Documentation. Release PyOTP contributors

MyGeotab Python SDK Documentation

Building Facebook Application using Python

Destiny Vault Raider. Allyn Hunt Blog: AllynH.com Web application: DestinyVaultRaider.com

JSONRPC Documentation

Automation with Meraki Provisioning API

Oracle Communications WebRTC Session Controller

Transcription:

GitHub-Flask Documentation Release 3.2.0 Cenk Altı Jul 01, 2018

Contents 1 Installation 3 2 Configuration 5 3 Authenticating / Authorizing Users 7 4 Invoking Remote Methods 9 5 Full Example 11 6 API Reference 13 Python Module Index 15 i

ii

GitHub-Flask Documentation, Release 3.2.0 GitHub-Flask is an extension to Flask that allows you authenticate your users via GitHub using OAuth protocol and call GitHub API methods. GitHub-Flask depends on the requests library. Contents 1

GitHub-Flask Documentation, Release 3.2.0 2 Contents

CHAPTER 1 Installation Install the extension with the following command: $ pip install GitHub-Flask 3

GitHub-Flask Documentation, Release 3.2.0 4 Chapter 1. Installation

CHAPTER 2 Configuration Here s an example of how GitHub-Flask is typically initialized and configured: from flask import Flask from flask_github import GitHub app = Flask( name ) app.config['github_client_id'] = 'XXX' app.config['github_client_secret'] = 'YYY' # For GitHub Enterprise app.config['github_base_url'] = 'https://hostname/api/v3/' app.config['github_auth_url'] = 'https://hostname/login/oauth/' github = GitHub(app) The following configuration settings exist for GitHub-Flask: GITHUB_CLIENT_ID Your GitHub application s client id. Go to https://github.com/settings/applications to register new application. GITHUB_CLIENT_SECRET Your GitHub application s client secret. GITHUB_BASE_URL Base URL for API requests. Override this to use with GitHub Enterprise. Default is https://api.github.com/. GITHUB_AUTH_URL Base authentication endpoint. Override this to use with GitHub Enterprise. Default is https://github.com/login/oauth/. 5

GitHub-Flask Documentation, Release 3.2.0 6 Chapter 2. Configuration

CHAPTER 3 Authenticating / Authorizing Users To authenticate your users with GitHub simply call authorize() at your login handler: @app.route('/login') def login(): return github.authorize() It will redirect the user to GitHub. If the user accepts the authorization request GitHub will redirect the user to your callback URL with the OAuth code parameter. Then the extension will make another request to GitHub to obtain access token and call your authorized_handler() function with that token. If the authorization fails oauth_token parameter will be None: @app.route('/github-callback') @github.authorized_handler def authorized(oauth_token): next_url = request.args.get('next') or url_for('index') if oauth_token is None: flash("authorization failed.") return redirect(next_url) user = User.query.filter_by(github_access_token=oauth_token).first() if user is None: user = User(oauth_token) db_session.add(user) user.github_access_token = oauth_token db_session.commit() return redirect(next_url) Store this token somewhere securely. It is needed later to make requests on behalf of the user. 7

GitHub-Flask Documentation, Release 3.2.0 8 Chapter 3. Authenticating / Authorizing Users

CHAPTER 4 Invoking Remote Methods We need to register a function as a token getter for Github-Flask extension. It will be called automatically by the extension to get the access token of the user. It should return the access token or None: @github.access_token_getter def token_getter(): user = g.user if user is not None: return user.github_access_token After setting up you can use the get(), post() or other verb methods of the GitHub object. They will return a dictionary representation of the given API endpoint. @app.route('/repo') def repo(): repo_dict = github.get('repos/cenkalti/github-flask') return str(repo_dict) 9

GitHub-Flask Documentation, Release 3.2.0 10 Chapter 4. Invoking Remote Methods

CHAPTER 5 Full Example A full example can be found in example.py file. Install the required Flask-SQLAlchemy package first. Then edit the file and change GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET settings. Then you can run it as a python script: $ pip install Flask-SQLAlchemy $ python example.py 11

GitHub-Flask Documentation, Release 3.2.0 12 Chapter 5. Full Example

CHAPTER 6 API Reference class flask_github.github(app=none) Provides decorators for authenticating users with GitHub within a Flask application. Helper methods are also provided interacting with GitHub API. access_token_getter(f ) Registers a function as the access_token getter. Must return the access_token used to make requests to GitHub on the user s behalf. authorize(scope=none, redirect_uri=none, state=none) Redirect to GitHub and request access to a user s data. Parameters scope (str) List of Scopes for which to request access, formatted as a string or comma delimited list of scopes as a string. Defaults to None, resulting in granting read-only access to public information (includes public user profile info, public repository info, and gists). For more information on this, see the examples in presented in the GitHub API Scopes documentation, or see the examples provided below. redirect_uri (str) Redirect URL to which to redirect the user after authentication. Defaults to None, resulting in using the default redirect URL for the OAuth application as defined in GitHub. This URL can differ from the callback URL defined in your GitHub application, however it must be a subdirectory of the specified callback URL, otherwise raises a GitHubError. For more information on this, see the examples in presented in the GitHub API Redirect URL documentation, or see the example provided below. state (str) An unguessable random string. It is used to protect against cross-site request forgery attacks. For example, if we wanted to use this method to get read/write access to user profile information, in addition to read-write access to code, commit status, etc., we would need to use the Scopes user and repo when calling this method. github.authorize(scope="user,repo") Additionally, if we wanted to specify a different redirect URL following authorization. 13

GitHub-Flask Documentation, Release 3.2.0 # Our application's callback URL is "http://example.com/callback" redirect_uri="http://example.com/callback/my/path" github.authorize(scope="user,repo", redirect_uri=redirect_uri) authorized_handler(f ) Decorator for the route that is used as the callback for authorizing with GitHub. This callback URL can be set in the settings for the app or passed in during authorization. get(resource, params=none, **kwargs) Shortcut for request('get', resource). post(resource, data=none, **kwargs) Shortcut for request('post', resource). Use this to make POST request since it will also encode data to application/json format. raw_request(method, resource, access_token=none, **kwargs) Makes a HTTP request and returns the raw Response object. request(method, resource, all_pages=false, **kwargs) Makes a request to the given endpoint. Keyword arguments are passed to the request() method. If the content type of the response is JSON, it will be decoded automatically and a dictionary will be returned. Otherwise the Response object is returned. class flask_github.githuberror Raised if a request fails to the GitHub API. response The Response object for the request. 14 Chapter 6. API Reference

Python Module Index f flask_github, 3 15

GitHub-Flask Documentation, Release 3.2.0 16 Python Module Index

Index A access_token_getter() (flask_github.github method), 13 authorize() (flask_github.github method), 13 authorized_handler() (flask_github.github method), 14 F flask_github (module), 1 G get() (flask_github.github method), 14 GitHub (class in flask_github), 13 GitHubError (class in flask_github), 14 P post() (flask_github.github method), 14 R raw_request() (flask_github.github method), 14 request() (flask_github.github method), 14 response (flask_github.githuberror attribute), 14 17