Skip to content

Commit

Permalink
BasicAuth instead of post data for OAuth2 token
Browse files Browse the repository at this point in the history
According to RFC6749 Section 2.3.1 all token servers are required to
support http basic auth. Instead supporting the credentials as post
data is specified as optional. Furthermore the RCF discourages using
the latter.
  • Loading branch information
mdellweg committed Sep 17, 2024
1 parent 24b5d00 commit 7bc94ad
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES/pulp-glue/+oauth2_token_basicauth.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use BasicAuth for token retrieval to comply with RFC6749.
7 changes: 2 additions & 5 deletions pulp-glue/pulp_glue/common/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def __init__(
token_url: str,
scopes: t.Optional[t.List[str]] = None,
):
self.client_id = client_id
self.client_secret = client_secret
self.token_auth = requests.auth.HTTPBasicAuth(client_id, client_secret)
self.token_url = token_url
self.scopes = scopes

Expand Down Expand Up @@ -76,15 +75,13 @@ def handle401(

def retrieve_token(self) -> None:
data = {
"client_id": self.client_id,
"client_secret": self.client_secret,
"grant_type": "client_credentials",
}

if self.scopes:
data["scope"] = " ".join(self.scopes)

response: requests.Response = requests.post(self.token_url, data=data)
response: requests.Response = requests.post(self.token_url, data=data, auth=self.token_auth)

response.raise_for_status()

Expand Down
2 changes: 1 addition & 1 deletion pulp-glue/tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def raise_for_status(self):
def json(self):
return {"expires_in": 1, "access_token": "aaa"}

def _requests_post_mocked(url: str, data: t.Dict[str, t.Any]):
def _requests_post_mocked(url: str, data: t.Dict[str, t.Any], **kwargs: t.Any):
assert "scope" not in data
return OAuth2MockResponse()

Expand Down

0 comments on commit 7bc94ad

Please sign in to comment.