Registry / auth-security / flask-oauthlib

flask-oauthlib

JSON →
library0.9.6pypypiunverified

Flask-OAuthlib is an extension for Flask that provides both OAuth client and provider functionalities, built upon the `oauthlib` core. It supports OAuth 1.0a and OAuth 2.0. The library's last release was 0.9.6 in September 2020. It is officially deprecated and not actively maintained; users are strongly encouraged to migrate to `Authlib` for current and future projects.

pip install Flask-OAuthlib
INSTALL
IMPORT
SIG · FLASK-OAUTHLIB
F
flask-oauthlib
auth-securitypythonv0.9.6
Install
3.1s avg
Import
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 27.6MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.1s · import 0.000s · 28MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OAuth
from flask_oauthlib.client import OAuth
from flask_oauthlib.client import OAuth
OAuthRemoteApp
from flask_oauthlib.client import OAuthRemoteApp
OAuthProvider
from flask_oauthlib.provider import OAuthProvider

This quickstart demonstrates a basic OAuth 2.0 client setup using `flask-oauthlib` to connect to a generic remote service. It configures a remote application, handles the authorization flow, stores the access token in the Flask session, and makes an example API call. Replace placeholder URLs and credentials with your actual OAuth provider details. Remember that `flask-oauthlib` is deprecated and this code serves mainly as a reference for existing implementations.

import os from flask import Flask, redirect, url_for, session, request from flask_oauthlib.client import OAuth app = Flask(__name__) app.debug = True app.secret_key = 'development' # NOTE: For local development over HTTP, you might need: # os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' # Configure your remote application details # Replace with your actual consumer_key and consumer_secret # These values should ideally come from environment variables for production REMOTE_APP_CLIENT_ID = os.environ.get('REMOTE_APP_CLIENT_ID', 'your_client_id') REMOTE_APP_CLIENT_SECRET = os.environ.get('REMOTE_APP_CLIENT_SECRET', 'your_client_secret') # Initialize OAuth oauth = OAuth(app) remote_service = oauth.remote_app( 'remote_service', consumer_key=REMOTE_APP_CLIENT_ID, consumer_secret=REMOTE_APP_CLIENT_SECRET, base_url='https://api.example.com/', request_token_url=None, # Not needed for OAuth2 client credentials or implicit grant request_token_params={'scope': 'email profile'}, access_token_url='https://example.com/oauth/token', authorize_url='https://example.com/oauth/authorize', # Example using a tokengetter/tokensetter for persistent storage # In a real app, this would store tokens in a database associated with a user access_token_method='POST' ) @remote_service.tokengetter def get_remote_service_token(): return session.get('remote_service_oauth_token') @app.route('/') def index(): if 'remote_service_oauth_token' in session: resp = remote_service.get('userinfo') # Example API call return f'Logged in as {resp.data.get("email")}<br><a href="/logout">Logout</a>' return '<p>Hello! <a href="/login">Login with Remote Service</a></p>' @app.route('/login') def login(): return remote_service.authorize(callback=url_for('authorized', _external=True)) @app.route('/logout') def logout(): session.pop('remote_service_oauth_token', None) return redirect(url_for('index')) @app.route('/authorized') def authorized(): resp = remote_service.authorized_response() if resp is None or resp.get('access_token') is None: return f'Access denied: reason={request.args["error"]}, error={request.args["error_description"]}' session['remote_service_oauth_token'] = (resp['access_token'], '') # OAuth2 bearer token, secret is empty return redirect(url_for('index')) if __name__ == '__main__': app.run(port=5000)
Debug
Known issues
breakingFlask-OAuthlib is officially deprecated and no longer maintained. Active development and support have shifted to the `Authlib` library. Continuing to use Flask-OAuthlib may expose your application to unpatched security vulnerabilities or compatibility issues with newer Python/Flask versions.
fix
Migrate your application to use `Authlib` (https://authlib.org/). This often involves significant code changes due to different API designs.
affects: All versions
breakingThere are known version conflicts between `flask-oauthlib` (which requires `oauthlib < 3.0.0`) and `requests-oauthlib` (which requires `oauthlib >= 3.0.0`). Installing both in the same environment often leads to dependency resolution errors.
fix
If you must use `flask-oauthlib`, pin `oauthlib` to a compatible version (e.g., `oauthlib==2.1.0`) and `requests-oauthlib` to an older version (e.g., `requests-oauthlib==1.1.0`). The recommended fix is to migrate to `Authlib`, which handles OAuthlib versions gracefully.
affects: 0.9.x
deprecatedThe `@authorized_handler` decorator for handling OAuth callbacks was deprecated in version 0.7 in favor of the `authorized_response()` method. While still functional in 0.9.x, it's best to update.
fix
Replace `@remote_service.authorized_handler` with the pattern shown in the quickstart using `remote_service.authorized_response()` within your callback route.
affects: >=0.7.0
gotchaFor OAuth2 client flows, ensure you specify a `scope` in `request_token_params` during `remote_app` configuration or in the `authorize` call. Omitting it can lead to 'Missing access credentials' or similar errors from the OAuth provider.
fix
Always include `request_token_params={'scope': 'your_required_scopes'}` when defining your `remote_app` or explicitly pass the `scope` parameter to `authorize()`.
affects: All versions
Upgrade
Version history
0.9.6latest on PyPI · released Sep 7, 2020
Audit
Dependencies
oauthlibrequiredCore OAuth protocol implementation. Known to have version conflicts with Flask-OAuthlib.
FlaskrequiredThe web framework it extends.
Agent activity
25 hits · last 30 days
node
24
OpenAI (training)
1
Resources