Skip to content

Commit 68921e0

Browse files
committed
Fix linux do get token
1 parent 774cf87 commit 68921e0

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

fastapi_oauth20/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
"""在 FastAPI 中异步授权 OAuth2 客户端"""
22

3-
__version__ = '0.0.1a1'
3+
__version__ = '0.0.1a2'
44

5-
__all__ = ['OSChinaOAuth20', 'GoogleOAuth20', 'FeiShuOAuth20', 'GiteeOAuth20', 'GitHubOAuth20', 'FastAPIOAuth20']
5+
__all__ = [
6+
'OSChinaOAuth20',
7+
'GoogleOAuth20',
8+
'FeiShuOAuth20',
9+
'GiteeOAuth20',
10+
'GitHubOAuth20',
11+
'FastAPIOAuth20',
12+
'LinuxDoOAuth20',
13+
]
614

715
from .clients.feishu import FeiShuOAuth20
816
from .clients.gitee import GiteeOAuth20
917
from .clients.github import GitHubOAuth20
1018
from .clients.google import GoogleOAuth20
19+
from .clients.linuxdo import LinuxDoOAuth20
1120
from .clients.oschina import OSChinaOAuth20
1221
from .integrations.fastapi import OAuth20 as FastAPIOAuth20

fastapi_oauth20/clients/linuxdo.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,30 @@ def __init__(self, client_id: str, client_secret: str):
2525
default_scopes=DEFAULT_SCOPES,
2626
)
2727

28+
async def get_access_token(self, code: str, redirect_uri: str, code_verifier: str | None = None) -> dict:
29+
"""Obtain the token based on the Linux do authorization method"""
30+
data = {
31+
'code': code,
32+
'redirect_uri': redirect_uri,
33+
'grant_type': 'authorization_code',
34+
}
35+
36+
auth = httpx.BasicAuth(self.client_id, self.client_secret)
37+
38+
if code_verifier:
39+
data.update({'code_verifier': code_verifier})
40+
async with httpx.AsyncClient(auth=auth) as client:
41+
response = await client.post(
42+
self.access_token_endpoint,
43+
data=data,
44+
headers=self.request_headers,
45+
)
46+
await self.raise_httpx_oauth20_errors(response)
47+
48+
res = response.json()
49+
50+
return res
51+
2852
async def get_userinfo(self, access_token: str) -> dict:
2953
"""Get user info from Linux Do"""
3054
headers = {'Authorization': f'Bearer {access_token}'}

0 commit comments

Comments
 (0)