You've already forked httpie-cli
mirror of
https://github.com/httpie/cli.git
synced 2025-08-10 22:42:05 +02:00
Extend auth plugin API
This extends the `AuthPlugin` API by the following attributes: * `auth_require`: set to `False` to make `--auth, -a` optional * `auth_parse`: set to `False` to disable `username:password` parsing (access the raw value passed to `-a` via `self.raw_auth`). * `prompt_password`: set to`False` to disable password prompt when no password provided (only relevant when `auth_parse == True`) These changes should be 100% backwards-compatible. What needs more testing is auth support in sessions. Close #433 Close #431 Close #378 Ping teracyhq/httpie-jwt-auth#3
This commit is contained in:
@@ -17,13 +17,36 @@ class AuthPlugin(BasePlugin):
|
||||
|
||||
See <https://github.com/jkbrzt/httpie-ntlm> for an example auth plugin.
|
||||
|
||||
See also `test_auth_plugins.py`
|
||||
|
||||
"""
|
||||
# The value that should be passed to --auth-type
|
||||
# to use this auth plugin. Eg. "my-auth"
|
||||
auth_type = None
|
||||
|
||||
def get_auth(self, username, password):
|
||||
# Set to `False` to make it possible to invoke this auth
|
||||
# plugin without requiring the user to specify credentials
|
||||
# through `--auth, -a`.
|
||||
auth_require = True
|
||||
|
||||
# By default the `-a` argument is parsed for `username:password`.
|
||||
# Set this to `False` to disable the parsing and error handling.
|
||||
auth_parse = True
|
||||
|
||||
# If both `auth_parse` and `prompt_password` are set to `True`,
|
||||
# and the value of `-a` lacks the password part,
|
||||
# then the user will be prompted to type the password in.
|
||||
prompt_password = True
|
||||
|
||||
# Will be set to the raw value of `-a` (if provided) before
|
||||
# `get_auth()` gets called.
|
||||
raw_auth = None
|
||||
|
||||
def get_auth(self, username=None, password=None):
|
||||
"""
|
||||
If `auth_parse` is set to `True`, then `username`
|
||||
and `password` contain the parsed credentials.
|
||||
|
||||
Return a ``requests.auth.AuthBase`` subclass instance.
|
||||
|
||||
"""
|
||||
|
@@ -36,6 +36,7 @@ class BasicAuthPlugin(BuiltinAuthPlugin):
|
||||
name = 'Basic HTTP auth'
|
||||
auth_type = 'basic'
|
||||
|
||||
# noinspection PyMethodOverriding
|
||||
def get_auth(self, username, password):
|
||||
return HTTPBasicAuth(username, password)
|
||||
|
||||
@@ -45,5 +46,6 @@ class DigestAuthPlugin(BuiltinAuthPlugin):
|
||||
name = 'Digest HTTP auth'
|
||||
auth_type = 'digest'
|
||||
|
||||
# noinspection PyMethodOverriding
|
||||
def get_auth(self, username, password):
|
||||
return requests.auth.HTTPDigestAuth(username, password)
|
||||
|
@@ -24,6 +24,9 @@ class PluginManager(object):
|
||||
for plugin in plugins:
|
||||
self._plugins.append(plugin)
|
||||
|
||||
def unregister(self, plugin):
|
||||
self._plugins.remove(plugin)
|
||||
|
||||
def load_installed_plugins(self):
|
||||
for entry_point_name in ENTRY_POINT_NAMES:
|
||||
for entry_point in iter_entry_points(entry_point_name):
|
||||
|
Reference in New Issue
Block a user