Skip to content

Commit c794260

Browse files
committed
Code coverage: use direct assignments instead of setters
1 parent 92467f0 commit c794260

File tree

1 file changed

+11
-34
lines changed

1 file changed

+11
-34
lines changed

src/fastapi_oauth2/middleware.py

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from starlette.types import Send
2424

2525
from .claims import Claims
26-
from .client import OAuth2Client
2726
from .config import OAuth2Config
2827
from .core import OAuth2Core
2928

@@ -37,32 +36,8 @@ class Auth(AuthCredentials):
3736
expires: int
3837
algorithm: str
3938
scopes: List[str]
40-
provider: OAuth2Core = None
41-
clients: Dict[str, OAuth2Core] = {}
42-
43-
@classmethod
44-
def set_ssr(cls, ssr: bool) -> None:
45-
cls.ssr = ssr
46-
47-
@classmethod
48-
def set_http(cls, http: bool) -> None:
49-
cls.http = http
50-
51-
@classmethod
52-
def set_secret(cls, secret: str) -> None:
53-
cls.secret = secret
54-
55-
@classmethod
56-
def set_expires(cls, expires: int) -> None:
57-
cls.expires = expires
58-
59-
@classmethod
60-
def set_algorithm(cls, algorithm: str) -> None:
61-
cls.algorithm = algorithm
62-
63-
@classmethod
64-
def register_client(cls, client: OAuth2Client) -> None:
65-
cls.clients[client.backend.name] = OAuth2Core(client)
39+
provider: OAuth2Core
40+
clients: Dict[str, OAuth2Core]
6641

6742
@classmethod
6843
def jwt_encode(cls, data: dict) -> str:
@@ -122,13 +97,15 @@ def __init__(
12297
config: OAuth2Config,
12398
callback: Callable[[Auth, User], Union[Awaitable[None], None]] = None,
12499
) -> None:
125-
Auth.set_ssr(config.enable_ssr)
126-
Auth.set_http(config.allow_http)
127-
Auth.set_secret(config.jwt_secret)
128-
Auth.set_expires(config.jwt_expires)
129-
Auth.set_algorithm(config.jwt_algorithm)
130-
for client in config.clients:
131-
Auth.register_client(client)
100+
Auth.ssr = config.enable_ssr
101+
Auth.http = config.allow_http
102+
Auth.secret = config.jwt_secret
103+
Auth.expires = config.jwt_expires
104+
Auth.algorithm = config.jwt_algorithm
105+
Auth.clients = {
106+
client.backend.name: OAuth2Core(client)
107+
for client in config.clients
108+
}
132109
self.callback = callback
133110

134111
async def authenticate(self, request: Request) -> Optional[Tuple[Auth, User]]:

0 commit comments

Comments
 (0)