Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
Don't truncate padding for HTTP Basic auth.
Browse files Browse the repository at this point in the history
b64e_enc_dec removes any trailing '=', which should be left
for HTTP Basic auth.
  • Loading branch information
Rebecka Gulliksson committed Apr 20, 2016
1 parent 92389a1 commit 1145989
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/oic/utils/authn/client.py
Expand Up @@ -106,8 +106,9 @@ def construct(self, cis, request_args=None, http_args=None, **kwargs):
if "headers" not in http_args:
http_args["headers"] = {}

http_args["headers"]["Authorization"] = "Basic {}".format(
b64e_enc_dec("{}:{}".format(user, passwd), "utf-8", "utf-8"))
credentials = "{}:{}".format(user, passwd)
authz = base64.urlsafe_b64encode(credentials.encode("utf-8")).decode("utf-8")
http_args["headers"]["Authorization"] = "Basic {}".format(authz)

try:
del cis["client_secret"]
Expand Down
10 changes: 9 additions & 1 deletion tests/test_client.py
Expand Up @@ -49,9 +49,17 @@ def test_construct(self, client):
http_args = csb.construct(cis)

assert http_args == {"headers": {"Authorization": "Basic {}".format(
base64.b64encode("A:boarding pass".encode("utf-8")).decode(
base64.urlsafe_b64encode("A:boarding pass".encode("utf-8")).decode(
"utf-8"))}}

def test_does_not_remove_padding(self):
cis = AccessTokenRequest(code="foo", redirect_uri="http://example.com")

csb = ClientSecretBasic(None)
http_args = csb.construct(cis, user="ab", password="c")

assert http_args["headers"]["Authorization"].endswith("==")


class TestBearerHeader(object):
def test_construct(self, client):
Expand Down

0 comments on commit 1145989

Please sign in to comment.