Skip to content

Commit

Permalink
utf8 encode textual basic auth username/password, pass bytes unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Mar 13, 2020
1 parent e4e1eda commit 2ec4804
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -29,7 +29,7 @@
install_requires=[
"incremental",
"requests >= 2.1.0",
"six",
"six >= 1.12.0",
"Twisted[tls] >= 16.4.0 ; python_version < '3.7'",
"Twisted[tls] >= 18.7.0 ; python_version >= '3.7'",
"attrs",
Expand Down
8 changes: 6 additions & 2 deletions src/treq/auth.py
@@ -1,8 +1,11 @@
from __future__ import absolute_import, division, print_function

from twisted.web.http_headers import Headers
import base64

import six

from twisted.web.http_headers import Headers


class UnknownAuthConfig(Exception):
def __init__(self, config):
Expand All @@ -28,7 +31,8 @@ def request(self, method, uri, headers=None, bodyProducer=None):

def add_basic_auth(agent, username, password):
creds = base64.b64encode(
'{0}:{1}'.format(username, password).encode('ascii'))
b':'.join([six.ensure_binary(username), six.ensure_binary(password)])
)
return _RequestHeaderSettingAgent(
agent,
Headers({b'Authorization': [b'Basic ' + creds]}))
Expand Down

0 comments on commit 2ec4804

Please sign in to comment.