Skip to content

Commit a252f5e

Browse files
authored
Add FeiShu OAuth2 (#5)
1 parent d21ab6e commit a252f5e

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
- [ ] 微信
1616
- [ ] QQ
1717
- [ ] 抖音
18-
- [ ] 飞书
18+
- [x] 飞书
1919
- [ ] 钉钉
2020
- [ ] 微博
2121
- [ ] 百度
2222
- [x] Gitee
2323
- [x] Github
2424
- [X] 开源中国
2525
- [ ] 阿里云
26-
- [ ] TestHome

src/fastapi_oauth20/clients/feishu.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
import httpx
4+
5+
from fastapi_oauth20.oauth20 import OAuth20Base
6+
7+
AUTHORIZE_ENDPOINT = 'https://passport.feishu.cn/suite/passport/oauth/authorize'
8+
ACCESS_TOKEN_ENDPOINT = 'https://passport.feishu.cn/suite/passport/oauth/token'
9+
REFRESH_TOKEN_ENDPOINT = AUTHORIZE_ENDPOINT
10+
DEFAULT_SCOPES = ['contact:user.employee_id:readonly', 'contact:user.base:readonly', 'contact:user.email:readonly']
11+
PROFILE_ENDPOINT = 'https://passport.feishu.cn/suite/passport/oauth/userinfo'
12+
13+
14+
class FeiShuOAuth20(OAuth20Base):
15+
def __init__(self, client_id: str, client_secret: str):
16+
super().__init__(
17+
client_id=client_id,
18+
client_secret=client_secret,
19+
authorize_endpoint=AUTHORIZE_ENDPOINT,
20+
access_token_endpoint=ACCESS_TOKEN_ENDPOINT,
21+
refresh_token_endpoint=REFRESH_TOKEN_ENDPOINT,
22+
revoke_token_endpoint=None,
23+
oauth_callback_route_name='feishu',
24+
default_scopes=DEFAULT_SCOPES,
25+
)
26+
27+
async def get_userinfo(self, access_token: str) -> dict:
28+
"""Get user info from FeiShu"""
29+
headers = {'Authorization': f'Bearer {access_token}'}
30+
async with httpx.AsyncClient() as client:
31+
response = await client.get(PROFILE_ENDPOINT, headers=headers)
32+
await self.raise_httpx_oauth20_errors(response)
33+
34+
res = response.json()
35+
36+
return res

src/fastapi_oauth20/clients/github.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
AUTHORIZE_ENDPOINT = 'https://github.com/#/oauth/authorize'
88
ACCESS_TOKEN_ENDPOINT = 'https://github.com/#/oauth/access_token'
9-
DEFAULT_SCOPES = ['user user:email']
9+
DEFAULT_SCOPES = ['user', 'user:email']
1010
PROFILE_ENDPOINT = 'https://api.github.com/user'
1111
EMAILS_ENDPOINT = 'https://api.github.com/user/emails'
1212

0 commit comments

Comments
 (0)