Skip to content

Commit

Permalink
Merge pull request #106 from aliev/release/2.0.0
Browse files Browse the repository at this point in the history
Release/2.0.0
  • Loading branch information
aliev authored Jan 12, 2025
2 parents 64769d8 + fcab1ef commit 9e9d13b
Show file tree
Hide file tree
Showing 43 changed files with 1,492 additions and 654 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: '3.11'
- name: Install dependencies
run: |
make dev-install
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ on:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
junit.xml
*.cover
.hypothesis/
.pytest_cache/
Expand Down
27 changes: 20 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ fail_fast: true

repos:
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.10.0
hooks:
- id: black

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
exclude: ^(setup\.cfg)
Expand All @@ -19,13 +19,26 @@ repos:
- id: check-merge-conflict
- id: detect-private-key

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.950
- repo: local
hooks:
- id: mypy
exclude: ^(docs/|setup\.py|tests/)
name: mypy
entry: "mypy"
language: system
types: [python]
require_serial: true
verbose: false
exclude: ^(docs/|setup\.py)
# - id: bandit
# name: bandit
# entry: "bandit"
# language: system
# types: [python]
# require_serial: true
# verbose: false

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 7.1.1
hooks:
- id: flake8
- id: flake8
additional_dependencies: [flake8-pyproject]
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ clean-pyc: ## remove Python file artifacts

clean-test: ## remove test and coverage artifacts
rm -f .coverage
rm -f coverage.xml
rm -fr htmlcov/
rm -fr .pytest_cache

Expand All @@ -56,8 +57,7 @@ release: dist ## package and upload a release
twine upload dist/*

dist: clean ## builds source and wheel package
python setup.py sdist
python setup.py bdist_wheel
python -m build
ls -l dist

install: clean ## install the package to the active Python's site-packages
Expand All @@ -66,6 +66,7 @@ install: clean ## install the package to the active Python's site-packages
dev-install: clean ## install the package and test dependencies for local development
python -m pip install --upgrade pip
pip install -e ."[dev]"
pip install -r examples/requirements.txt
pre-commit install

docs-install: ## install packages for local documentation.
Expand Down
2 changes: 2 additions & 0 deletions aioauth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

__version__ = "2.0.0"

logging.getLogger("aioauth").addHandler(logging.NullHandler())
8 changes: 0 additions & 8 deletions aioauth/__version__.py

This file was deleted.

2 changes: 2 additions & 0 deletions aioauth/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ class Settings:

AVAILABLE: bool = True
"""Boolean indicating whether or not the server is available."""

DEBUG: bool = False
48 changes: 29 additions & 19 deletions aioauth/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
from urllib.parse import urljoin
from typing_extensions import Literal

from .requests import Request

from .collections import HTTPHeaderDict
from .constances import default_headers
from .requests import TRequest
from .types import ErrorType
from .types import ErrorType, UserType


class OAuth2Error(Exception, Generic[TRequest]):
class OAuth2Error(Generic[UserType], Exception):
"""Base exception that all other exceptions inherit from."""

error: ErrorType
Expand All @@ -31,7 +32,7 @@ class OAuth2Error(Exception, Generic[TRequest]):

def __init__(
self,
request: TRequest,
request: Request[UserType],
description: Optional[str] = None,
headers: Optional[HTTPHeaderDict] = None,
state: Optional[str] = None,
Expand All @@ -53,7 +54,7 @@ def __init__(
super().__init__(f"({self.error}) {self.description}")


class MethodNotAllowedError(OAuth2Error[TRequest]):
class MethodNotAllowedError(Generic[UserType], OAuth2Error[UserType]):
"""
The request is valid, but the method trying to be accessed is not
available to the resource owner.
Expand All @@ -64,7 +65,7 @@ class MethodNotAllowedError(OAuth2Error[TRequest]):
error: ErrorType = "method_is_not_allowed"


class InvalidRequestError(OAuth2Error[TRequest]):
class InvalidRequestError(Generic[UserType], OAuth2Error[UserType]):
"""
The request is missing a required parameter, includes an invalid
parameter value, includes a parameter more than once, or is
Expand All @@ -74,7 +75,7 @@ class InvalidRequestError(OAuth2Error[TRequest]):
error: Literal["invalid_request"] = "invalid_request"


class InvalidClientError(OAuth2Error[TRequest]):
class InvalidClientError(Generic[UserType], OAuth2Error[UserType]):
"""
Client authentication failed (e.g. unknown client, no client
authentication included, or unsupported authentication method).
Expand All @@ -92,7 +93,7 @@ class InvalidClientError(OAuth2Error[TRequest]):

def __init__(
self,
request: TRequest,
request: Request,
description: Optional[str] = None,
headers: Optional[HTTPHeaderDict] = None,
state: Optional[str] = None,
Expand All @@ -109,14 +110,14 @@ def __init__(
self.headers["WWW-Authenticate"] = "Basic " + ", ".join(auth_values)


class InsecureTransportError(OAuth2Error[TRequest]):
class InsecureTransportError(Generic[UserType], OAuth2Error[UserType]):
"""An exception will be thrown if the current request is not secure."""

description = "OAuth 2 MUST utilize https."
error: ErrorType = "insecure_transport"


class UnsupportedGrantTypeError(OAuth2Error[TRequest]):
class UnsupportedGrantTypeError(Generic[UserType], OAuth2Error[UserType]):
"""
The authorization grant type is not supported by the authorization
server.
Expand All @@ -125,7 +126,7 @@ class UnsupportedGrantTypeError(OAuth2Error[TRequest]):
error: ErrorType = "unsupported_grant_type"


class UnsupportedResponseTypeError(OAuth2Error[TRequest]):
class UnsupportedResponseTypeError(Generic[UserType], OAuth2Error[UserType]):
"""
The authorization server does not support obtaining an authorization
code using this method.
Expand All @@ -134,7 +135,7 @@ class UnsupportedResponseTypeError(OAuth2Error[TRequest]):
error: ErrorType = "unsupported_response_type"


class InvalidGrantError(OAuth2Error[TRequest]):
class InvalidGrantError(Generic[UserType], OAuth2Error[UserType]):
"""
The provided authorization grant (e.g. authorization code, resource
owner credentials) or refresh token is invalid, expired, revoked, does
Expand All @@ -147,14 +148,14 @@ class InvalidGrantError(OAuth2Error[TRequest]):
error: ErrorType = "invalid_grant"


class MismatchingStateError(OAuth2Error[TRequest]):
class MismatchingStateError(Generic[UserType], OAuth2Error[UserType]):
"""Unable to securely verify the integrity of the request and response."""

description = "CSRF Warning! State not equal in request and response."
error: Literal["mismatching_state"] = "mismatching_state"


class UnauthorizedClientError(OAuth2Error[TRequest]):
class UnauthorizedClientError(Generic[UserType], OAuth2Error[UserType]):
"""
The authenticated client is not authorized to use this authorization
grant type.
Expand All @@ -163,7 +164,7 @@ class UnauthorizedClientError(OAuth2Error[TRequest]):
error: ErrorType = "unauthorized_client"


class InvalidScopeError(OAuth2Error[TRequest]):
class InvalidScopeError(Generic[UserType], OAuth2Error[UserType]):
"""
The requested scope is invalid, unknown, or malformed, or
exceeds the scope granted by the resource owner.
Expand All @@ -174,7 +175,7 @@ class InvalidScopeError(OAuth2Error[TRequest]):
error: ErrorType = "invalid_scope"


class ServerError(OAuth2Error[TRequest]):
class ServerError(Generic[UserType], OAuth2Error[UserType]):
"""
The authorization server encountered an unexpected condition that
prevented it from fulfilling the request. (This error code is needed
Expand All @@ -183,9 +184,10 @@ class ServerError(OAuth2Error[TRequest]):
"""

error: ErrorType = "server_error"
status_code: HTTPStatus = HTTPStatus.BAD_REQUEST


class TemporarilyUnavailableError(OAuth2Error[TRequest]):
class TemporarilyUnavailableError(Generic[UserType], OAuth2Error[UserType]):
"""
The authorization server is currently unable to handle the request
due to a temporary overloading or maintenance of the server.
Expand All @@ -196,19 +198,27 @@ class TemporarilyUnavailableError(OAuth2Error[TRequest]):
error: ErrorType = "temporarily_unavailable"


class InvalidRedirectURIError(OAuth2Error[TRequest]):
class InvalidRedirectURIError(Generic[UserType], OAuth2Error[UserType]):
"""
The requested redirect URI is missing or not allowed.
"""

error: ErrorType = "invalid_request"


class UnsupportedTokenTypeError(OAuth2Error[TRequest]):
class UnsupportedTokenTypeError(Generic[UserType], OAuth2Error[UserType]):
"""
The authorization server does not support the revocation of the presented
token type. That is, the client tried to revoke an access token on a server
not supporting this feature.
"""

error: ErrorType = "unsupported_token_type"


class AccessDeniedError(Generic[UserType], OAuth2Error[UserType]):
"""
The resource owner or authorization server denied the request
"""

error: ErrorType = "access_denied"
Loading

0 comments on commit 9e9d13b

Please sign in to comment.