mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-09-21 21:15:13 +00:00
Bump fastapi oauth2 from 0.0.1 to 0.0.2 (#896)
This commit is contained in:
@@ -231,7 +231,9 @@ class Settings(BaseSettings):
|
||||
OAUTH2_LINUX_DO_CLIENT_SECRET: str
|
||||
|
||||
# 基础配置
|
||||
OAUTH2_BACKEND_BASE_URL: str = 'http://127.0.0.1:8000'
|
||||
OAUTH2_GITHUB_REDIRECT_URI: str = 'http://127.0.0.1:8000/api/v1/oauth2/github/callback'
|
||||
OAUTH2_GOOGLE_REDIRECT_URI: str = 'http://127.0.0.1:8000/api/v1/oauth2/google/callback'
|
||||
OAUTH2_LINUX_DO_REDIRECT_URI: str = 'http://127.0.0.1:8000/api/v1/oauth2/linux-do/callback'
|
||||
OAUTH2_FRONTEND_REDIRECT_URI: str = 'http://localhost:5173/oauth2/callback'
|
||||
|
||||
##################################################
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, Request, Response
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, Response
|
||||
from fastapi_limiter.depends import RateLimiter
|
||||
from fastapi_oauth20 import FastAPIOAuth20, GitHubOAuth20
|
||||
from starlette.responses import RedirectResponse
|
||||
@@ -17,10 +17,8 @@ github_client = GitHubOAuth20(settings.OAUTH2_GITHUB_CLIENT_ID, settings.OAUTH2_
|
||||
|
||||
|
||||
@router.get('', summary='获取 Github 授权链接')
|
||||
async def get_github_oauth2_url(request: Request) -> ResponseSchemaModel[str]:
|
||||
auth_url = await github_client.get_authorization_url(
|
||||
redirect_uri=f'{settings.OAUTH2_BACKEND_BASE_URL}{request.url.path}/callback'
|
||||
)
|
||||
async def get_github_oauth2_url() -> ResponseSchemaModel[str]:
|
||||
auth_url = await github_client.get_authorization_url(redirect_uri=settings.OAUTH2_GITHUB_REDIRECT_URI)
|
||||
return response_base.success(data=auth_url)
|
||||
|
||||
|
||||
@@ -36,11 +34,11 @@ async def github_oauth2_callback( # noqa: ANN201
|
||||
background_tasks: BackgroundTasks,
|
||||
oauth2: Annotated[
|
||||
FastAPIOAuth20,
|
||||
Depends(FastAPIOAuth20(github_client, redirect_route_name='github_oauth2_callback')),
|
||||
Depends(FastAPIOAuth20(github_client, redirect_uri=settings.OAUTH2_GITHUB_REDIRECT_URI)),
|
||||
],
|
||||
):
|
||||
token, _state = oauth2
|
||||
access_token = token['access_token']
|
||||
token_data, _state = oauth2
|
||||
access_token = token_data['access_token']
|
||||
user = await github_client.get_userinfo(access_token)
|
||||
data = await oauth2_service.create_with_login(
|
||||
db=db,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, Request, Response
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, Response
|
||||
from fastapi_limiter.depends import RateLimiter
|
||||
from fastapi_oauth20 import FastAPIOAuth20, GoogleOAuth20
|
||||
from starlette.responses import RedirectResponse
|
||||
@@ -17,10 +17,8 @@ google_client = GoogleOAuth20(settings.OAUTH2_GOOGLE_CLIENT_ID, settings.OAUTH2_
|
||||
|
||||
|
||||
@router.get('', summary='获取 google 授权链接')
|
||||
async def get_google_oauth2_url(request: Request) -> ResponseSchemaModel[str]:
|
||||
auth_url = await google_client.get_authorization_url(
|
||||
redirect_uri=f'{settings.OAUTH2_BACKEND_BASE_URL}{request.url.path}/callback'
|
||||
)
|
||||
async def get_google_oauth2_url() -> ResponseSchemaModel[str]:
|
||||
auth_url = await google_client.get_authorization_url(redirect_uri=settings.OAUTH2_GOOGLE_REDIRECT_URI)
|
||||
return response_base.success(data=auth_url)
|
||||
|
||||
|
||||
@@ -36,11 +34,11 @@ async def google_oauth2_callback( # noqa: ANN201
|
||||
background_tasks: BackgroundTasks,
|
||||
oauth2: Annotated[
|
||||
FastAPIOAuth20,
|
||||
Depends(FastAPIOAuth20(google_client, redirect_route_name='google_oauth2_callback')),
|
||||
Depends(FastAPIOAuth20(google_client, redirect_uri=settings.OAUTH2_GOOGLE_REDIRECT_URI)),
|
||||
],
|
||||
):
|
||||
token, _state = oauth2
|
||||
access_token = token['access_token']
|
||||
token_data, _state = oauth2
|
||||
access_token = token_data['access_token']
|
||||
user = await google_client.get_userinfo(access_token)
|
||||
data = await oauth2_service.create_with_login(
|
||||
db=db,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, Request, Response
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, Response
|
||||
from fastapi_limiter.depends import RateLimiter
|
||||
from fastapi_oauth20 import FastAPIOAuth20, LinuxDoOAuth20
|
||||
from starlette.responses import RedirectResponse
|
||||
@@ -17,10 +17,8 @@ linux_do_client = LinuxDoOAuth20(settings.OAUTH2_LINUX_DO_CLIENT_ID, settings.OA
|
||||
|
||||
|
||||
@router.get('', summary='获取 LinuxDo 授权链接')
|
||||
async def get_linux_do_oauth2_url(request: Request) -> ResponseSchemaModel[str]:
|
||||
auth_url = await linux_do_client.get_authorization_url(
|
||||
redirect_uri=f'{settings.OAUTH2_BACKEND_BASE_URL}{request.url.path}/callback'
|
||||
)
|
||||
async def get_linux_do_oauth2_url() -> ResponseSchemaModel[str]:
|
||||
auth_url = await linux_do_client.get_authorization_url(redirect_uri=settings.OAUTH2_LINUX_DO_REDIRECT_URI)
|
||||
return response_base.success(data=auth_url)
|
||||
|
||||
|
||||
@@ -36,11 +34,11 @@ async def linux_do_oauth2_callback( # noqa: ANN201
|
||||
background_tasks: BackgroundTasks,
|
||||
oauth2: Annotated[
|
||||
FastAPIOAuth20,
|
||||
Depends(FastAPIOAuth20(linux_do_client, redirect_route_name='linux_do_oauth2_callback')),
|
||||
Depends(FastAPIOAuth20(linux_do_client, redirect_uri=settings.OAUTH2_LINUX_DO_REDIRECT_URI)),
|
||||
],
|
||||
):
|
||||
token, _state = oauth2
|
||||
access_token = token['access_token']
|
||||
token_data, _state = oauth2
|
||||
access_token = token_data['access_token']
|
||||
user = await linux_do_client.get_userinfo(access_token)
|
||||
data = await oauth2_service.create_with_login(
|
||||
db=db,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[plugin]
|
||||
summary = 'OAuth 2.0'
|
||||
version = '0.0.6'
|
||||
version = '0.0.7'
|
||||
description = '通过 OAuth 2.0 的方式登录系统'
|
||||
author = 'wu-clan'
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
fastapi-oauth20>=0.0.1
|
||||
fastapi-oauth20>=0.0.2
|
||||
|
||||
Reference in New Issue
Block a user