-
Notifications
You must be signed in to change notification settings - Fork 35
feat: bearer auth #111
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
base: develop
Are you sure you want to change the base?
feat: bearer auth #111
Changes from all commits
1817410
48a1833
ca326cf
85f99eb
657ab57
64c6b80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,8 +39,13 @@ Before creating an issue please make sure that it was not already reported. | |
| #### Code | ||
|
|
||
| 1) Create a new branch based on `develop` branch. | ||
| * Optional: create and enable virtualenv: | ||
| ``` | ||
| python3 -m venv myenv | ||
| source myenv/bin/activate | ||
| ``` | ||
| 2) Fetch all dev dependencies. | ||
| * Install required python modules using `pip`: **python -m pip install .[testing]** | ||
| * Install required python modules using `pip`: **python -m pip install ".[testing]"** | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my shell (zsh) didn't like the |
||
| 3) Ensure tests are ok by running them using [`pytest`](http://doc.pytest.org/en/latest/index.html). | ||
| 4) Add your changes. | ||
| 5) Follow [Black](https://black.readthedocs.io/en/stable/) code formatting. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ issues = "https://github.com/Colin-b/httpx_auth/issues" | |
|
|
||
| [project.optional-dependencies] | ||
| testing = [ | ||
| "pytest==8.3.4", | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure why this was missing here, I assume it comes with |
||
| # Used to generate test tokens | ||
| "pyjwt==2.*", | ||
| # Used to mock httpx | ||
|
|
@@ -55,12 +56,15 @@ testing = [ | |
| "pytest-asyncio==0.25.*", | ||
| ] | ||
|
|
||
| [tool.setuptools] | ||
| py-modules = [ | ||
| "httpx_auth" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is needed for: possibly related to the virtualenv? |
||
| ] | ||
|
|
||
| [tool.setuptools.dynamic] | ||
| version = {attr = "httpx_auth.version.__version__"} | ||
|
|
||
| [tool.pytest.ini_options] | ||
| filterwarnings = [ | ||
| "error", | ||
| ] | ||
| # Silence deprecation warnings about option "asyncio_default_fixture_loop_scope" | ||
| asyncio_default_fixture_loop_scope = "function" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [pytest] | ||
| asyncio_mode = auto | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this, I get: |
||
| asyncio_default_fixture_loop_scope = "function" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from pytest_httpx import HTTPXMock | ||
| import httpx | ||
| import pytest | ||
|
|
||
| import httpx_auth | ||
|
|
||
|
|
||
| def test_bearer_requires_atoken(): | ||
| with pytest.raises(Exception) as exception_info: | ||
| httpx_auth.BearerToken(None) | ||
| assert str(exception_info.value) == "Token is mandatory." | ||
|
|
||
| def test_bearer_token_is_sent(httpx_mock: HTTPXMock): | ||
| auth = httpx_auth.BearerToken("my_token") | ||
|
|
||
| httpx_mock.add_response( | ||
| url="https://authorized_only", | ||
| method="GET", | ||
| match_headers={"Authorization": "Bearer my_token"}, | ||
| ) | ||
|
|
||
| with httpx.Client() as client: | ||
| client.get("https://authorized_only", auth=auth) |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used a virtualenv here as I didn't want to pollute my local machine with extra packages. Thought it might be useful for others, too.