Coverage for polar/oauth2/exceptions.py: 85%
13 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 17:15 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 17:15 +0000
1from typing import Any 1a
3from authlib.oauth2.rfc6750 import InvalidTokenError as _InvalidTokenError 1a
5from polar.config import settings 1a
8class InvalidTokenError(_InvalidTokenError): 1a
9 def __init__(self, description: str | None = None, **extra_attributes: Any) -> None: 1a
10 super().__init__(
11 description, realm=settings.WWW_AUTHENTICATE_REALM, **extra_attributes
12 )
15class InsufficientScopeError(_InvalidTokenError): 1a
16 """The request requires higher privileges than provided by the
17 access token. The resource server SHOULD respond with the HTTP
18 403 (Forbidden) status code and MAY include the "scope"
19 attribute with the scope necessary to access the protected
20 resource.
22 https://tools.ietf.org/html/rfc6750#section-3.1
24 We don't use the one provided by Authlib because it doesn't have
25 the logic to handle the headers attribute, contrary to `InvalidTokenError` 🤷♂️
26 """
28 error = "insufficient_scope" 1a
29 description = ( 1a
30 "The request requires higher privileges than provided by the access token."
31 )
32 status_code = 403 1a
34 def __init__(self, required_scopes: set[str]) -> None: 1a
35 super().__init__(
36 realm=settings.WWW_AUTHENTICATE_REALM, scope=" ".join(required_scopes)
37 )
40__all__ = ["InvalidTokenError", "InsufficientScopeError"] 1a