Requests authentication using existing helpers
Project description
Installation
pip install helper-auth
Usage
Objects of the HelperAuth
class are intended to be used as custom
authentication handlers as per the
Requests documentation.
Default scenario
Suppose you have an existing GitHub personal access token, and a Git credential helper already set up for Git to authenticate to GitHub using this token as the password. This helper prints the following to standard output:
$ git credential-github
username=your_github_username
password=your_github_token
You want to use the same token to make GitHub API calls in Python with
the help of the Requests library. The API expects a
token your_github_token
string as the value of
your request's Authorization
header.
You can use a HelperAuth
authentication handler with its default settings:
import requests
from helper_auth import HelperAuth
auth = HelperAuth("git credential-github")
response = requests.get("https://api.github.com/user/repos", auth=auth)
Specifying the helper command
Simple helper command with no command-line arguments can be a string or a path-like object.
auth = HelperAuth("helper")
auth = HelperAuth(Path("helper"))
If the helper command contains command-line arguments, it can be a string or a list of strings.
auth = HelperAuth("helper --option arg")
auth = HelperAuth(["helper", "--option", "arg"])
Caching the token
By default, a HelperAuth
authentication handler never stores the value of
the token (password) in its internal state. Rather, the helper command is
invoked on each call to the handler. This is an intentional precaution
(such that the token cannot be retrieved ex post by the introspection
of the handler) but can be expensive. You can override this by
passing cache_token=True
to the constructor:
auth = HelperAuth("helper", cache_token=True)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for helper_auth-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6180695e29f59dd81b7ef617634f2d2aa0ba8d0b1b7a05c7385369e1c246be0 |
|
MD5 | fe0625465d96c71ae2dfc3fefca5d0d9 |
|
BLAKE2b-256 | 90e3e52d9097d648a6bf9d6ed19a4d5ef1bbdbc045b479bc1109d8328df3b876 |