Used to parse http Authentication headers, and to call handlers per scheme.
Project description
authparser
Used to parse http Authentication headers, and to call handlers per scheme.
Provides
AuthParser
This class does the parsing and dispatches to handler methods per scheme.
add_handler(scheme, user_record_fn, challenge_fn=None, **kwargs)
- Registers an authentication scheme to be handled, and is details
- scheme: (string) the name of the auth scheme, e.g. Basic, Bearer, Digest, etc.
- user_record_fn (callable) the function
get_user_record()
calls after parsing the Authorization header.- The function will receive either the token for this scheme, or the params (see RFC 7235).
- The function can return whatever your application needs, eg. True or False whether the Authoriation is valid, or a whole dict of claims.
get_user_record()
merely passes what is returned back to your application.
- challenge_fn (callable) [optional] if specified,
get_challenge_header()
will call this function while building theWWW-Authenticate
header.- The function receives all kwargs passed to
get_challenge_header()
. - The function should return a dict of name-value pairs which will be added to the scheme's challenge params. e.g. a Digest challenge (without qop) will issue a challenge similar to:
WWW-Authenticate: Digest nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", realm="pointw.com", opaque="5ccc069c403ebaf9f0171e9517f40e41"
- The function receives all kwargs passed to
- kwargs - if any, they are passed through to the handler function. For example, you may wish to pass the URL being requested, the method being used, or even the entire request object.
clear_handlers()
- Clears all handlers.
get_user_record(auth_header)
- Parses the Authorization header and passes the results to the handler for the corresponding scheme.
- auth_header (string) the Authorization header from the request (with or without the starting
Authorization:
keyword).
- auth_header (string) the Authorization header from the request (with or without the starting
get_challenge_header(**kwargs)
- Returns the challenge header based on the handlers previously added. Call this when forming the response to an unauthorized request.
- kwargs [optional]
- set
multi_line=True
to have this method return an array of headers, one item in the array per scheme/handler. - all other kwargs are passed to the
challenge_fn
for it to use as it sees fit. For example, if the request had anAuthorization:
header that had bad credentials, you could pass that fact to theget_challenge_header()
so it can add details to the challenge header params. e.g.WWW-Authenticate: Bearer error="invalid_token"
- set
- kwargs [optional]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
authparser-1.1.tar.gz
(4.8 kB
view details)
Built Distribution
File details
Details for the file authparser-1.1.tar.gz
.
File metadata
- Download URL: authparser-1.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 328212eb5f3b4315091f17a0823d00ef0f8584988cbcd6b0ac0842918d48ccda |
|
MD5 | 1c8b8219380111043b6e465cf74c2ab6 |
|
BLAKE2b-256 | 99a3eec87a795e7cae40bc1b9b9209d44a7ec893a8af5819e3a8a87b60f06b01 |
File details
Details for the file authparser-1.1-py3-none-any.whl
.
File metadata
- Download URL: authparser-1.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31cc7f12aa22aa4ac8fdbab59e6ad55a2c8f3b80ad96b8bf84ec5eabe7f8318b |
|
MD5 | 9e20b082d3049718160491b9186802e0 |
|
BLAKE2b-256 | 4670f94ed9841352cf4315d869e11086d3ce4155eda0a1d3d08ba28e673aceb7 |