# Requests-OAuthlib: OAuth for Humans

Requests-OAuthlib uses the Python Requests and OAuthlib libraries to provide an easy-to-use Python interface for building OAuth1 and OAuth2 clients.

## Overview

A simple Flask application which connects to the Github OAuth2 API looks approximately like this:

    from requests_oauthlib import OAuth2Session

    from flask import Flask, request, redirect, session, url_for
    from flask.json import jsonify

    # This information is obtained upon registration of a new GitHub
    client_id = "<your client key>"
    client_secret = "<your client secret>"
    authorization_base_url = 'https://github.com/login/oauth/authorize'
    token_url = 'https://github.com/login/oauth/access_token'

    @app.route("/login")
    def login():
        github = OAuth2Session(client_id)
        authorization_url, state = github.authorization_url(authorization_base_url)

        # State is used to prevent CSRF, keep this for later.
        session['oauth_state'] = state
        return redirect(authorization_url)

    @app.route("/callback")
    def callback():
        github = OAuth2Session(client_id, state=session['oauth_state'])
        token = github.fetch_token(token_url, client_secret=client_secret,
                                   authorization_response=request.url)

        return jsonify(github.get('https://api.github.com/user').json())

The above is a truncated example. A full working example is available here: Web App Example of OAuth 2 web application flow

# Installation

Requests-OAuthlib can be installed with pip:

    $ pip install requests_oauthlib

# Getting Started:

- OAuth 1 Workflow
  - Workflow example showing use of both OAuth1 and OAuth1Session
  - Signature placement - header, query or body?
  - Signature types - HMAC (most common), RSA, Plaintext
- OAuth 2 Workflow
  - Introduction
  - Web Application Flow
  - Mobile Application Flow
  - Legacy Application Flow
  - Backend Application Flow
  - Refreshing tokens
- Examples
  - Bitbucket OAuth 1 Tutorial
  - GitHub OAuth 2 Tutorial
  - Google OAuth 2 Tutorial
  - Facebook OAuth 2 Tutorial
  - Fitbit OAuth 2 (Mobile Application Flow) Tutorial
  - LinkedIn OAuth 2 Tutorial
  - Outlook Calender OAuth 2 Tutorial
  - Tumblr OAuth1 Tutorial
  - Web App Example of OAuth 2 web application flow
  - Refreshing tokens in OAuth 2
- Developer Interface
  - OAuth 1.0
  - OAuth 1.0 Session
  - OAuth 2.0
  - OAuth 2.0 Session

# Indices and tables

- Index
- Module Index
- Search Page