Skip to content

Commit 42e6ff9

Browse files
inimazprmths128
authored andcommitted
fix: add authlib + format code
1 parent 5de8648 commit 42e6ff9

7 files changed

Lines changed: 755 additions & 716 deletions

File tree

carbonserver/carbonserver/api/routers/authenticate.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import logging
44
import random
55
from typing import Optional
6-
from authlib.integrations.starlette_client import OAuth, OAuthError
76

8-
import requests
7+
from authlib.integrations.starlette_client import OAuthError
98
from dependency_injector.wiring import Provide, inject
109
from fastapi import APIRouter, Depends, HTTPException, Query, Request, Response
1110
from fastapi.responses import RedirectResponse
@@ -88,7 +87,7 @@ async def get_login(
8887
if code:
8988
try:
9089
token = await auth_provider.client.authorize_access_token(request)
91-
except OAuthError as error:
90+
except OAuthError:
9291
return "Error"
9392
user = token.get("userinfo")
9493
if user:
@@ -121,7 +120,7 @@ async def get_login(
121120
return response
122121
return await auth_provider.get_authorize_url(request, str(login_url))
123122

124-
state = str(int(random.random() * 1000))
123+
str(int(random.random() * 1000))
125124
client_id, _ = auth_provider.get_client_credentials()
126125
return await auth_provider.client.authorize_redirect(
127126
request, str(login_url), scope=" ".join(OAUTH_SCOPES)

carbonserver/carbonserver/api/services/auth_providers/oidc_auth_provider.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@
55
It can work with any OIDC-compliant provider (Fief, Keycloak, Auth0, etc.).
66
"""
77

8-
import asyncio
9-
from typing import Any, Dict, List, Optional, Tuple
10-
from urllib.parse import urlencode
11-
from carbonserver.config import settings
8+
from typing import Any, Dict, Optional, Tuple
129

13-
import httpx
14-
from fastapi_oidc import discovery, get_auth
15-
from jose import jwt
10+
from authlib.integrations.starlette_client import OAuth
11+
from carbonserver.config import settings
1612

1713
DEFAULT_SIGNATURE_CACHE_TTL = 3600 # seconds
1814
OAUTH_SCOPES = ["openid", "email", "profile"]
1915

20-
from authlib.integrations.starlette_client import OAuth
16+
2117
oauth = OAuth()
2218
oauth.register(
2319
"client",
@@ -27,6 +23,7 @@
2723
client_kwargs={"scope": "openid profile email"},
2824
)
2925

26+
3027
class OIDCAuthProvider:
3128
def __init__(
3229
self,

carbonserver/carbonserver/api/services/auth_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import jwt
55
from dependency_injector.wiring import Provide
66
from fastapi import Depends, HTTPException
7-
from fastapi.security import APIKeyCookie, HTTPBearer, OAuth2AuthorizationCodeBearer
7+
from fastapi.security import APIKeyCookie, HTTPBearer
88

99
from carbonserver.api.services.auth_providers.oidc_auth_provider import (
1010
OIDCAuthProvider,

carbonserver/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from fastapi_pagination import add_pagination
55
from pydantic import ValidationError
66
from starlette.middleware.cors import CORSMiddleware
7+
from starlette.middleware.sessions import SessionMiddleware
78
from starlette.requests import Request
89
from starlette.responses import JSONResponse
910

@@ -24,7 +25,6 @@
2425
from carbonserver.container import ServerContainer
2526
from carbonserver.database.database import engine
2627
from carbonserver.logger import logger
27-
from starlette.middleware.sessions import SessionMiddleware
2828

2929

3030
async def db_exception_handler(request: Request, exc: DBException):

carbonserver/uv.lock

Lines changed: 88 additions & 339 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies = [
4242
"requests",
4343
"questionary",
4444
"rich",
45-
"typer"
45+
"typer",
4646
]
4747

4848
[tool.setuptools.dynamic]
@@ -79,6 +79,32 @@ Changelog = "https://github.com/mlco2/codecarbon/releases"
7979

8080

8181
[dependency-groups]
82+
api = [
83+
"alembic<2.0.0",
84+
"authlib>=1.2.1",
85+
"bcrypt<5.0.0",
86+
"python-dateutil<3.0.0",
87+
"dependency-injector<5.0.0",
88+
"fastapi<1.0.0",
89+
"fief-client[fastapi]",
90+
"httpx",
91+
"pydantic[email]<2.0.0",
92+
"psycopg2-binary<3.0.0",
93+
"requests<3.0.0",
94+
"sqlalchemy<2.0.0",
95+
"uvicorn[standard]<1.0.0",
96+
"fastapi-pagination<1.0.0",
97+
"pytest",
98+
"mock",
99+
"responses",
100+
"fastapi-oidc;python_version>='3.10'",
101+
"numpy",
102+
"psutil",
103+
"requests-mock",
104+
"rapidfuzz",
105+
"PyJWT",
106+
"logfire[fastapi]>=1.0.1",
107+
]
82108
dev = [
83109
"taskipy",
84110
"bumpver",
@@ -110,6 +136,7 @@ viz-legacy = [
110136
"dash_bootstrap_components > 1.0.0",
111137
"fire",
112138
]
139+
113140
api = [
114141
"alembic<2.0.0",
115142
"bcrypt<5.0.0",

0 commit comments

Comments
 (0)