Skip to content

Commit

Permalink
improvements for 1.6.0 (#65)
Browse files Browse the repository at this point in the history
Major update with a few breaking changes.

*MAJOR BREAKING CHANGE*
- the `BearerAuth` class no longer exists. You can use a `BearerToken` directly as a `requests` auth handler instead.

*MINOR BREAKING CHANGES*
- parameter `url` to `ApiClient.request()`, `ApiClient.get()`, `ApiClient.post()`, etc. is now renamed to `path`. This doesn't matter as long as you use it as positional parameter (which was the case everywhere in the docs and tests and is usually the case when using `requests` directly).
- renamed class `AccessToken` to `TokenResponse` (it was not used anywhere anyway)
- rename `TokenEndpointPoolingJob` to `BaseTokenEndpointPoolingJob`
- rename `ClientAssertionAuthenticationMethod` to `BaseClientAssertionAuthenticationMethod`
- convert most classes to `attrs.frozen` classes. This should not create any regressions, but trying to modify attributes in instances of those classes will not work anymore. It was unsupported before anyway.
- renamed `GrantType` enum to `GrantTypes`
- reworked exceptions:
  * better error messages
  * added more context in exceptions
  * renamed `MismatchingAudience` to `MismatchingIdTokenAudience`
  * renamed `MismatchingAzp` to `MismatchingIdTokenAzp`
  * renamed `MismatchingNonce` to `MismatchingIdTokenNonce`
  * introduced `MismatchingIdTokenIssuer`
  * introduced many custom exceptions
- renamed `PkceUtils.code_verifier_re` to `code_verifier_pattern`
- `expires_at` is now rounded down to the exact second.
- `expires_in` is now rounded up

*OTHER CHANGES*
- enable ALL ruff rules, implement fixes
- improved tests mock `time.sleep` in tests
- updated dependencies
- improve test coverage to 100%
- introduce `ResponseTypes` and move `CodeChallengeMethods` enums
- introduce `Endpoints` enum
- introduce `validate_bool_fields()`
- reviewed and updated some docstrings
- token_class can now be passed as parameter to `OAuth2Client`
- added authorization header name as ClassVar in `BearerToken`, for #70
  • Loading branch information
guillp authored Sep 4, 2024
1 parent 719a514 commit 8f5417f
Show file tree
Hide file tree
Showing 39 changed files with 2,766 additions and 1,737 deletions.
16 changes: 0 additions & 16 deletions .coveragerc

This file was deleted.

2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
*.* text eol=lf
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ repos:
args:
- --in-place
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.2
rev: v0.6.3
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
rev: v1.11.2
hooks:
- id: mypy
args:
- --strict
- --implicit-reexport
- --show-error-codes
- --show-error-context
- --show-column-numbers
additional_dependencies:
- pytest-mock
- pytest-mypy
- pytest-freezer
- jwskate>=0.11.1
- types-requests
- requests_mock
- flask
- freezegun
- furl
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Please note that despite the name, this library has no relationship with Google
[oauth2client](https://github.com/googleapis/oauth2client) library.

[![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/)
[![PyPi version](https://img.shields.io/pypi/v/black)](https://pypi.org/project/black/)
[![PyPi version](https://img.shields.io/pypi/v/requests_oauth2client)](https://pypi.org/project/requests_oauth2client/)
[![Downloads](https://static.pepy.tech/badge/requests_oauth2client/month)](https://pepy.tech/project/requests_oauth2client)
[![Supported Versions](https://img.shields.io/pypi/pyversions/requests_oauth2client.svg)](https://pypi.org/project/requests_oauth2client)
[![PyPi license](https://badgen.net/pypi/license/requests_oauth2client/)](https://pypi.com/project/requests_oauth2client/)
Expand Down Expand Up @@ -67,15 +67,15 @@ Or you can import individual objects from this package as usual. Note that impor

## Calling APIs with Access Tokens

If you already managed to obtain an access token for the API you want to call, you can simply use the [BearerAuth] Auth
Handler for [requests]:
If you already managed to obtain an access token for the API you want to call, you can simply convert it to an instance of [BearerToken].
Instances of that class work as a `requests` compatible auth handler.

```python
import requests
from requests_oauth2client import BearerAuth
from requests_oauth2client import BearerToken

token = "an_access_token"
resp = requests.get("https://my.protected.api/endpoint", auth=BearerAuth(token))
token = BearerToken("my_access_token")
resp = requests.get("https://my.protected.api/endpoint", auth=token)
```

This authentication handler will add a `Authorization: Bearer <access_token>` header in the request, with your access
Expand Down
3 changes: 0 additions & 3 deletions docs/authors.md

This file was deleted.

24 changes: 14 additions & 10 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ nav:
- Installation: installation.md
- API: api.md
- Contributing: contributing.md
#- Authors: authors.md
#- Changelog: history.md
theme:
name: material
language: en
Expand Down Expand Up @@ -41,6 +39,9 @@ markdown_extensions:
generic: true
- pymdownx.highlight:
linenums: true
anchor_linenums: true
line_spans: __span
pygments_lang_class: true
- pymdownx.inlinehilite
- pymdownx.superfences
- pymdownx.details
Expand All @@ -54,21 +55,24 @@ plugins:
- include-markdown
- search:
lang: en
- autorefs
- mkdocstrings:
default_handler: python
handlers:
python:
options:
filters:
- "!^_"
- "^__init__"
- "!^utils"
members_order: source
show_root_heading: true
show_submodules: true
#extensions:
#- griffe_fieldz: {include_inherited: true}
filters:
- "!^_"
- "^__init__"
- "!^utils"
members_order: source
show_root_heading: true
show_submodules: true
import:
- https://requests.readthedocs.io/en/master/objects.inv

- https://guillp.github.io/jwskate/objects.inv
extra:
social:
- icon: fontawesome/brands/github
Expand Down
1,067 changes: 549 additions & 518 deletions poetry.lock

Large diffs are not rendered by default.

83 changes: 39 additions & 44 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool]
[tool.poetry]
name = "requests_oauth2client"
version = "1.5.3"
version = "1.6.0"
homepage = "https://github.com/guillp/requests_oauth2client"
description = "An OAuth2.x client based on `requests`."
authors = ["Guillaume Pujol <[email protected]>"]
Expand Down Expand Up @@ -35,8 +35,8 @@ attrs = ">=23.2.0"


[tool.poetry.dev-dependencies]
coverage = ">=7.4"
flask = ">=2.0.1"
coverage = ">=7.6.1"
flask = ">=3.0.3"
livereload = ">=2.6.3"
mypy = ">=1.8"
mkdocs = ">=1.3.1"
Expand All @@ -49,6 +49,7 @@ pre-commit = ">=3.5.0"
pytest = ">=7.0.1"
pytest-cov = ">=3.0.0"
pytest-freezer = ">=0.4.8"
pytest-mock = "^3.14.0"
pytest-mypy = ">=0.9.1"
requests-mock = ">=1.9.3"
toml = ">=0.10.2"
Expand All @@ -60,12 +61,36 @@ virtualenv = ">=20.2.2"

[tool.poetry.extras]
test = ["pytest", "pytest-cov"]
doc = ["mdformat", "mkdocs", "mkdocs-autorefs", "mkdocs-include-markdown-plugin", "mkdocs-material", "mkdocs-material-extensions", "mkdocstrings"]
doc = [
"mdformat",
"mkdocs",
"mkdocs-autorefs",
"mkdocs-include-markdown-plugin",
"mkdocs-material",
"mkdocs-material-extensions",
"mkdocstrings"
]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.coverage.run]
source = ["requests_oauth2client"]

[tool.coverage.report]
exclude_also = [
"def __repr__",
"if self.debug:",
"if settings.DEBUG",
"raise AssertionError",
"raise NotImplementedError",
"if 0:",
"if __name__ == .__main__.:",
"def main",
"if TYPE_CHECKING:",
]

[tool.docformatter]
black = true
recursive = true
Expand All @@ -76,58 +101,29 @@ blank = true
[tool.ruff]
target-version = "py38"
line-length = 120
extend-exclude = [
"tests"
]


[tool.ruff.format]
docstring-code-format = true
line-ending = "lf"

[tool.ruff.lint]
select = [
"A",
"B",
"C",
"C4",
"D",
"DTZ",
"E",
"EM",
"ERA",
"F",
"FA",
"FBT",
"I",
"ICN",
"ISC",
"N",
"PGH",
"PLC",
"PLE",
"PLR",
"PLW",
"PTH",
"Q",
"RUF",
"S",
"SIM",
"T",
"TID",
"TRY",
"UP",
"W",
"YTT",
]
select = ["ALL"]
ignore = [
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"ANN401", # any-type in function args
"N818", # Exception names should be named with an Error suffix
"PLR0912", # Too many branches
"D105", # Undocumented magic method
"D107", # Missing docstring in `__init__`
"S105", # Possible hardcoded password
"ISC001", # single-line-implicit-string-concatenation
"COM812",
"ISC001",
]

[tool.ruff.lint.per-file-ignores]
"tests/**.py" = ["ARG001", "B018", "D100", "D101", "D102", "D103", "D104", "F821", "PGH005", "PLR0913", "PLR0915", "PLR2004", "S101", "S106", "S113",
"PT011", "E501"]

[tool.ruff.lint.pylint]
max-args = 10

Expand All @@ -137,7 +133,6 @@ ignore-decorators = ['override']

[tool.mypy]
strict = true
implicit_reexport = true
show_error_context = true
show_column_numbers = true
show_error_codes = true
Expand Down
Loading

0 comments on commit 8f5417f

Please sign in to comment.