Skip to content

Commit

Permalink
Merge 56bfb3a into c591a38
Browse files Browse the repository at this point in the history
  • Loading branch information
labeneator committed Nov 19, 2018
2 parents c591a38 + 56bfb3a commit 5553d47
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -35,6 +35,7 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_.
* Changed the default ``--style`` from ``solarized`` to ``auto`` (on Windows it stays ``fruity``).
* Fixed default headers being incorrectly case-sensitive.
* Removed Python 2.6 support.
* Load credentials from netrc for auth plugins if user requests it.



Expand Down
15 changes: 15 additions & 0 deletions httpie/input.py
Expand Up @@ -6,6 +6,7 @@
import sys
import re
import errno
import netrc
import mimetypes
import getpass
from io import BytesIO
Expand Down Expand Up @@ -239,6 +240,20 @@ def _process_auth(self):
self.args.auth_type = default_auth_plugin.auth_type
plugin = plugin_manager.get_auth_plugin(self.args.auth_type)()

if (plugin.auth_require and self.args.auth is None
and plugin.netrc_parse):
# Authentication required, no credentials provided and
# plugin allows netrc parsing
netrc_entries = netrc.netrc()
if url.netloc in netrc_entries.hosts:
login, account, password = netrc_entries.authenticators(url.netloc)
self.args.auth = plugin.get_auth(
username=login,
password=password,
)
# Break early, we have acquired netrc credentials
return

if plugin.auth_require and self.args.auth is None:
self.error('--auth required')

Expand Down
4 changes: 4 additions & 0 deletions httpie/plugins/base.py
Expand Up @@ -29,6 +29,10 @@ class AuthPlugin(BasePlugin):
# through `--auth, -a`.
auth_require = True

# Set to `True` to make it possible for this auth
# plugin to acquire credentials from netrc
netrc_parse = False

# By default the `-a` argument is parsed for `username:password`.
# Set this to `False` to disable the parsing and error handling.
auth_parse = True
Expand Down

0 comments on commit 5553d47

Please sign in to comment.