Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New --auth-type NTLM per https://github.com/jkbr/httpie/issues/76 #160

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,7 @@ Any of the default headers can be overwritten.
Authentication
==============

The currently supported authentication schemes are Basic and Digest (more to
come). There are two flags that control authentication:
The currently supported authentication schemes are Basic, Digest and NTLM (requires the `requests-ntlm <https://github.com/requests/requests-ntlm>`_ library). There are two flags that control authentication:

=================== ======================================================
``--auth, -a`` Pass a ``username:password`` pair as
Expand All @@ -472,8 +471,8 @@ come). There are two flags that control authentication:
have higher priority).

``--auth-type`` Specify the auth mechanism. Possible values are
``basic`` and ``digest``. The default value is
``basic`` so it can often be omitted.
``basic``, ``digest`` and ``NTLM``. The default value
``basic`` so it can often be omitted.
=================== ======================================================


Expand Down
2 changes: 1 addition & 1 deletion httpie/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def _split_lines(self, text, width):

auth.add_argument(
'--auth-type',
choices=['basic', 'digest'],
choices=['basic', 'digest', 'NTLM'],
default='basic',
help="""
The authentication mechanism to be used. Defaults to "basic".
Expand Down
16 changes: 12 additions & 4 deletions httpie/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,18 @@ def get_requests_kwargs(args):

credentials = None
if args.auth:
credentials = {
'basic': requests.auth.HTTPBasicAuth,
'digest': requests.auth.HTTPDigestAuth,
}[args.auth_type](args.auth.key, args.auth.value)
if args.auth_type == 'basic':
credentials = requests.auth.HTTPBasicAuth(args.auth.key, args.auth.value)
elif args.auth_type == 'digest':
credentials = requests.auth.HTTPDigestAuth(args.auth.key, args.auth.value)
elif args.auth_type == 'NTLM':
try:
from requests_ntlm import HttpNtlmAuth
except ImportError:
sys.stderr.write("Please install the requests-ntlm library from https://github.com/requests/requests-ntlm")
raise
credentials = HttpNtlmAuth(args.auth.key, args.auth.value)


kwargs = {
'stream': True,
Expand Down