Skip to content

Commit 0f94a13

Browse files
committed
Move the OAuth2Client to a separate module
1 parent e3a7450 commit 0f94a13

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from social_core.backends.github import GithubOAuth2
77

88
from demo.router import router as demo_router
9+
from fastapi_oauth2.client import OAuth2Client
910
from fastapi_oauth2.middleware import OAuth2Middleware
1011
from fastapi_oauth2.router import router as oauth2_router
11-
from fastapi_oauth2.types import OAuth2Client
1212

1313
router = APIRouter()
1414
templates = Jinja2Templates(directory="templates")
@@ -31,6 +31,7 @@ async def root(request: Request):
3131
client_id="eccd08d6736b7999a32a",
3232
client_secret="642999c1c5f2b3df8b877afdc78252ef5b594d31",
3333
redirect_uri="http://127.0.0.1:8000/",
34+
scope=["user:email"],
3435
),
3536
]
3637
})

src/fastapi_oauth2/client.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from typing import Optional, Type, Sequence
2+
3+
from social_core.backends.oauth import BaseOAuth2
4+
5+
6+
class OAuth2Client:
7+
backend: Type[BaseOAuth2]
8+
client_id: str
9+
client_secret: str
10+
redirect_uri: Optional[str]
11+
scope: Optional[Sequence[str]]
12+
13+
def __init__(
14+
self,
15+
*,
16+
backend: Type[BaseOAuth2],
17+
client_id: str,
18+
client_secret: str,
19+
redirect_uri: Optional[str] = None,
20+
scope: Optional[Sequence[str]] = None,
21+
):
22+
self.backend = backend
23+
self.client_id = client_id
24+
self.client_secret = client_secret
25+
self.redirect_uri = redirect_uri
26+
self.scope = scope or []

0 commit comments

Comments
 (0)