Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
MAINT: Make authentication via JWT Tokens possible (header format Aut…
Browse files Browse the repository at this point in the history
…horization: Bearer TOKEN)
  • Loading branch information
jotelha committed Apr 22, 2022
1 parent c562be3 commit fa151e3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aiopenapi3/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __call__(self, *args, **kwargs):
return self.request(*args, **kwargs)

def _factory_args(self):
return {"auth": self.req.auth, "headers": {"user-agent": f"aiopenapi3/{__version__}"}}
return {"headers": {"user-agent": f"aiopenapi3/{__version__}", **self.req.headers}}

def request(self, data=None, parameters=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion aiopenapi3/v30/glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _prepare_secschemes(self, scheme: str, value: List[str]):
self.req.auth = httpx.DigestAuth(*value)

if ss.type == "http" and ss.scheme_ == "bearer":
header = ss.bearerFormat or "Bearer {}"
header = "Bearer {}"
self.req.headers["Authorization"] = header.format(value)

if ss.type == "mutualTLS":
Expand Down

1 comment on commit fa151e3

@commonism
Copy link

@commonism commonism commented on fa151e3 Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
I'd really expect Bearer to work without any modifications

api.authenticate(None, bearerAuth=auth)
api._.api_v1_auth_login_create(data={}, parameters={})
request = httpx_mock.get_requests()[-1]
assert request.headers["Authorization"] == "Bearer %s" % (auth,)

Maybe the security requirements in the description document for the path/operation do not specify the requirement to authenticate, which is why you chose to force feed authentication?

For flask_smorest as used in https://github.com/jotelha/dtool-lookup-server/blob/a64a661f5c1fc5537a33c57339f051fe8b5e15bd/dtool_lookup_server/dataset_routes.py
look at
marshmallow-code/flask-smorest#91

Please sign in to comment.