File tree Expand file tree Collapse file tree 1 file changed +5
-19
lines changed Expand file tree Collapse file tree 1 file changed +5
-19
lines changed Original file line number Diff line number Diff line change 2
2
from fastapi .responses import RedirectResponse
3
3
from starlette .requests import Request
4
4
5
- from fastapi_oauth2 .github import GitHubOAuth2
6
- from .config import (
7
- OAUTH2_CLIENT_ID ,
8
- OAUTH2_CLIENT_SECRET ,
9
- OAUTH2_CALLBACK_URL ,
10
- )
11
-
12
5
router = APIRouter (prefix = "/oauth2" )
13
- oauth2 = GitHubOAuth2 (
14
- client_id = OAUTH2_CLIENT_ID ,
15
- client_secret = OAUTH2_CLIENT_SECRET ,
16
- callback_url = OAUTH2_CALLBACK_URL ,
17
- allow_insecure_http = True ,
18
- )
19
6
20
7
21
8
@router .get ("/{provider}/auth" )
22
- async def login (provider : str ):
23
- print (provider )
24
- return await oauth2 .login_redirect ()
9
+ async def login (request : Request , provider : str ):
10
+ return await request .auth .clients [provider ].login_redirect (request )
25
11
26
12
27
- @router .get ("/token" )
28
- async def token (request : Request ):
29
- return await oauth2 .token_redirect (request )
13
+ @router .get ("/{provider}/ token" )
14
+ async def token (request : Request , provider : str ):
15
+ return await request . auth . clients [ provider ] .token_redirect (request )
30
16
31
17
32
18
@router .get ("/logout" )
You can’t perform that action at this time.
0 commit comments