You've already forked httpie-cli
mirror of
https://github.com/httpie/cli.git
synced 2025-08-10 22:42:05 +02:00
Added netrc support for auth plugins.
Enabled for --auth-type=basic and digest, 3rd parties may opt in. This closes #718, closes #719, closes #852, and also closes #934
This commit is contained in:
@@ -35,13 +35,22 @@ class AuthPlugin(BasePlugin):
|
||||
# Set this to `False` to disable the parsing and error handling.
|
||||
auth_parse = True
|
||||
|
||||
# Set to `True` to make it possible for this auth
|
||||
# plugin to acquire credentials from the user’s netrc file(s).
|
||||
# It is used as a fallback when the credentials are not provided explicitly
|
||||
# through `--auth, -a`. Enabling this will allow skipping `--auth, -a`
|
||||
# even when `auth_require` is set `True` (provided that netrc provides
|
||||
# credential for a given host).
|
||||
netrc_parse = False
|
||||
|
||||
# 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.
|
||||
# `get_auth()` gets called. If the credentials came from a netrc file,
|
||||
# then this is `None`.
|
||||
raw_auth = None
|
||||
|
||||
def get_auth(self, username=None, password=None):
|
||||
|
@@ -22,6 +22,7 @@ class HTTPBasicAuth(requests.auth.HTTPBasicAuth):
|
||||
See https://github.com/jakubroztocil/httpie/issues/212
|
||||
|
||||
"""
|
||||
# noinspection PyTypeChecker
|
||||
request.headers['Authorization'] = type(self).make_header(
|
||||
self.username, self.password).encode('latin1')
|
||||
return request
|
||||
@@ -36,6 +37,7 @@ class HTTPBasicAuth(requests.auth.HTTPBasicAuth):
|
||||
class BasicAuthPlugin(BuiltinAuthPlugin):
|
||||
name = 'Basic HTTP auth'
|
||||
auth_type = 'basic'
|
||||
netrc_parse = True
|
||||
|
||||
# noinspection PyMethodOverriding
|
||||
def get_auth(self, username: str, password: str) -> HTTPBasicAuth:
|
||||
@@ -43,9 +45,9 @@ class BasicAuthPlugin(BuiltinAuthPlugin):
|
||||
|
||||
|
||||
class DigestAuthPlugin(BuiltinAuthPlugin):
|
||||
|
||||
name = 'Digest HTTP auth'
|
||||
auth_type = 'digest'
|
||||
netrc_parse = True
|
||||
|
||||
# noinspection PyMethodOverriding
|
||||
def get_auth(
|
||||
|
Reference in New Issue
Block a user