apexauthlib 0.1.3__tar.gz → 0.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {apexauthlib-0.1.3 → apexauthlib-0.1.4}/PKG-INFO +1 -1
- {apexauthlib-0.1.3 → apexauthlib-0.1.4}/apexauthlib/entities/auth.py +6 -0
- {apexauthlib-0.1.3 → apexauthlib-0.1.4}/apexauthlib/fastapi/auth.py +22 -1
- {apexauthlib-0.1.3 → apexauthlib-0.1.4}/apexauthlib/integration/api.py +24 -0
- {apexauthlib-0.1.3 → apexauthlib-0.1.4}/pyproject.toml +1 -1
- {apexauthlib-0.1.3 → apexauthlib-0.1.4}/LICENSE +0 -0
- {apexauthlib-0.1.3 → apexauthlib-0.1.4}/README.md +0 -0
- {apexauthlib-0.1.3 → apexauthlib-0.1.4}/apexauthlib/__init__.py +0 -0
- {apexauthlib-0.1.3 → apexauthlib-0.1.4}/apexauthlib/entities/__init__.py +0 -0
- {apexauthlib-0.1.3 → apexauthlib-0.1.4}/apexauthlib/fastapi/__init__.py +0 -0
- {apexauthlib-0.1.3 → apexauthlib-0.1.4}/apexauthlib/integration/__init__.py +0 -0
|
@@ -7,10 +7,11 @@ from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
|
|
7
7
|
from starlette import status
|
|
8
8
|
|
|
9
9
|
from apexauthlib.entities import User
|
|
10
|
-
from apexauthlib.integration.api import AuthApiProvider
|
|
10
|
+
from apexauthlib.integration.api import AuthApiProvider, AuthCodeApi
|
|
11
11
|
|
|
12
12
|
auth_api = APIRouter(tags=["Auth"])
|
|
13
13
|
AuthApiProviderDependable = Annotated[AuthApiProvider[Any], inject("auth")]
|
|
14
|
+
AuthCodeApiDependable = Annotated[AuthCodeApi, inject("auth_code")]
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
def oauth2() -> OAuth2PasswordBearer:
|
|
@@ -90,3 +91,23 @@ def login(
|
|
|
90
91
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
91
92
|
detail="Incorrect username or password",
|
|
92
93
|
)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@auth_api.post(
|
|
97
|
+
"/login/code",
|
|
98
|
+
status_code=200,
|
|
99
|
+
response_model=TokenResponse,
|
|
100
|
+
)
|
|
101
|
+
def login_code(
|
|
102
|
+
code: str,
|
|
103
|
+
auth_code: AuthCodeApiDependable,
|
|
104
|
+
) -> TokenResponse:
|
|
105
|
+
try:
|
|
106
|
+
return TokenResponse(
|
|
107
|
+
access_token=auth_code.token_for(code),
|
|
108
|
+
)
|
|
109
|
+
except Exception:
|
|
110
|
+
raise HTTPException(
|
|
111
|
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
112
|
+
detail="Incorrect username or password",
|
|
113
|
+
)
|
|
@@ -71,3 +71,27 @@ class AuthApi(Generic[ItemT]):
|
|
|
71
71
|
)
|
|
72
72
|
|
|
73
73
|
return self.formatter.load(JsonDict(result["data"]["metadata"]["metadata"]))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@dataclass
|
|
77
|
+
class AuthCodeApi:
|
|
78
|
+
http: FluentHttp
|
|
79
|
+
client_id: str
|
|
80
|
+
client_secret: str
|
|
81
|
+
|
|
82
|
+
def token_for(self, code: str) -> str:
|
|
83
|
+
data = {
|
|
84
|
+
"code": code,
|
|
85
|
+
"client_id": self.client_id,
|
|
86
|
+
"client_secret": self.client_secret,
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return str(
|
|
90
|
+
(
|
|
91
|
+
self.http.with_data(JsonDict(data))
|
|
92
|
+
.post()
|
|
93
|
+
.on_endpoint("/auth/oauth/token")
|
|
94
|
+
.on_failure(raises=RuntimeError)
|
|
95
|
+
.json()
|
|
96
|
+
)["access_token"]
|
|
97
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|