Skip to main content
Basic OAuth v2
==============

What is it?
-----------

The Oauth v2 spec defines several authorization grant. This library implements
the "Resource Owner Password Credentials Grant" as described in
<http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-4.3>

Requirements:

* [Flask](http://flask.pocoo.org/)
* [Redis](http://redis.io/)

Why using it?
-------------

The goal of this Grant is to replace the classic "HTTP Basic over SSL" widely
used. With Oauth, you exchange your crendentials against a token.

This mechanism has several advantages:

* The client does not pass the full credentials for each request.
* The server does not check the username and password each time, it will
only check the access token, this will reduce the database lookups.

Basic Oauth uses Redis to store the sessions.

Is it secure?
-------------

__It would be stupid to use this mechanism without SSL__. Even if the token is
passed instead of the credentials, the credentials needs to be passed in clear
text during the Authentication phase. Also, it can be problematic to lose the
token.

To limit the risk of losing the token, every single token generated is signed
using the User-Agent and the client IP address. If an attacker tries to re-use
a stolen token, he will have to connect to the same IP and using the same
User-Agent (browser version, OS, architecture) to get access. A wrong try will
result in destroying the session.

How to use it?
--------------

Install basic_oauth from PYPI:

```
pip install basic_oauth
```

Create a sample WSGI app with [Flask](http://flask.pocoo.org/):

```python
import flask
import basic_oauth

app = flask.Flask(__name__)

oauth = basic_oauth.BasicOauth(app)
oauth.mount_endpoint('login', '/login')
oauth.mount_endpoint('script', '/js/oauth_client.js')
oauth.credentials.append(('johndoe', 'foobar42'))
# You can declare "oauth.authenticate_handler" to plug your own
# database instead of using the in-memory credentials

@app.route('/')
@oauth.require
def hello(user_id):
return 'Hello World!'

if __name__ == '__main__':
app.debug = True
app.run()
```

Checkout the ["example" directory](https://github.com/samalba/basic_oauth/tree/master/example) for a complete server/client example.

Metadata

Release files for basic_oauth 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for basic_oauth 0.1.5
File Size Uploaded Provenance Actions
basic_oauth-0.1.5.tar.gz 5.3 kB Without provenance Details for basic_oauth-0.1.5.tar.gz

Release files / basic_oauth-0.1.5.tar.gz

Download URL basic_oauth-0.1.5.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
44d0aef33128a170e35f4c7fc713df0d6b317fe9737117c8e2e41804e5e20fc0
BLAKE2b-256 checksum
How to use checksums
1b95f408e33ad8d6fa6d1aa57a6e87f486d6e56f9174185d16c94d595e16f564
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for basic_oauth 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page