|
1 | | -from enum import Enum |
2 | | -from typing import Dict, TypedDict |
| 1 | +from typing import List, Optional, Type |
3 | 2 |
|
| 3 | +from social_core.backends.oauth import BaseOAuth2 |
4 | 4 |
|
5 | | -class OAuth2Provider(str, Enum): |
6 | | - github = "github" |
7 | 5 |
|
8 | | - |
9 | | -class OAuth2Client(Dict[str, str]): |
| 6 | +class OAuth2Client: |
| 7 | + backend: Type[BaseOAuth2] |
10 | 8 | client_id: str |
11 | 9 | client_secret: str |
12 | | - redirect_uri: str |
13 | | - |
14 | | - |
15 | | -class ConfigParams(TypedDict): |
| 10 | + redirect_uri: Optional[str] |
| 11 | + |
| 12 | + def __init__( |
| 13 | + self, |
| 14 | + *, |
| 15 | + backend: Type[BaseOAuth2], |
| 16 | + client_id: str, |
| 17 | + client_secret: str, |
| 18 | + redirect_uri: Optional[str] = None, |
| 19 | + ): |
| 20 | + self.backend = backend |
| 21 | + self.client_id = client_id |
| 22 | + self.client_secret = client_secret |
| 23 | + self.redirect_uri = redirect_uri |
| 24 | + |
| 25 | + |
| 26 | +class OAuth2Config: |
16 | 27 | allow_http: bool |
17 | 28 | jwt_secret: str |
18 | 29 | jwt_expires: int |
19 | 30 | jwt_algorithm: str |
20 | | - providers: Dict[OAuth2Provider, OAuth2Client] |
21 | | - |
22 | | - |
23 | | -class Config: |
24 | | - allow_http: bool = False |
25 | | - jwt_secret: str = "" |
26 | | - jwt_expires: int = 900 |
27 | | - jwt_algorithm: str = "HS256" |
28 | | - providers: Dict[OAuth2Provider, OAuth2Client] = {} |
29 | | - |
30 | | - def __init__(self, **kwargs): |
31 | | - for key, value in kwargs.items(): |
32 | | - setattr(self, key, value) |
| 31 | + clients: List[OAuth2Client] |
| 32 | + |
| 33 | + def __init__( |
| 34 | + self, |
| 35 | + *, |
| 36 | + allow_http: bool = False, |
| 37 | + jwt_secret: str = "", |
| 38 | + jwt_expires: int = 900, |
| 39 | + jwt_algorithm: str = "HS256", |
| 40 | + clients: List[OAuth2Client] = None, |
| 41 | + ): |
| 42 | + self.allow_http = allow_http |
| 43 | + self.jwt_secret = jwt_secret |
| 44 | + self.jwt_expires = jwt_expires |
| 45 | + self.jwt_algorithm = jwt_algorithm |
| 46 | + self.clients = clients or [] |
0 commit comments