Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
- [ ] 微信
- [ ] QQ
- [ ] 抖音
- [ ] 飞书
- [x] 飞书
- [ ] 钉钉
- [ ] 微博
- [ ] 百度
- [x] Gitee
- [x] Github
- [X] 开源中国
- [ ] 阿里云
- [ ] TestHome
36 changes: 36 additions & 0 deletions src/fastapi_oauth20/clients/feishu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import httpx

from fastapi_oauth20.oauth20 import OAuth20Base

AUTHORIZE_ENDPOINT = 'https://passport.feishu.cn/suite/passport/oauth/authorize'
ACCESS_TOKEN_ENDPOINT = 'https://passport.feishu.cn/suite/passport/oauth/token'
REFRESH_TOKEN_ENDPOINT = AUTHORIZE_ENDPOINT
DEFAULT_SCOPES = ['contact:user.employee_id:readonly', 'contact:user.base:readonly', 'contact:user.email:readonly']
PROFILE_ENDPOINT = 'https://passport.feishu.cn/suite/passport/oauth/userinfo'


class FeiShuOAuth20(OAuth20Base):
def __init__(self, client_id: str, client_secret: str):
super().__init__(
client_id=client_id,
client_secret=client_secret,
authorize_endpoint=AUTHORIZE_ENDPOINT,
access_token_endpoint=ACCESS_TOKEN_ENDPOINT,
refresh_token_endpoint=REFRESH_TOKEN_ENDPOINT,
revoke_token_endpoint=None,
oauth_callback_route_name='feishu',
default_scopes=DEFAULT_SCOPES,
)

async def get_userinfo(self, access_token: str) -> dict:
"""Get user info from FeiShu"""
headers = {'Authorization': f'Bearer {access_token}'}
async with httpx.AsyncClient() as client:
response = await client.get(PROFILE_ENDPOINT, headers=headers)
await self.raise_httpx_oauth20_errors(response)

res = response.json()

return res
2 changes: 1 addition & 1 deletion src/fastapi_oauth20/clients/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

AUTHORIZE_ENDPOINT = 'https://github.com/login/oauth/authorize'
ACCESS_TOKEN_ENDPOINT = 'https://github.com/login/oauth/access_token'
DEFAULT_SCOPES = ['user user:email']
DEFAULT_SCOPES = ['user', 'user:email']
PROFILE_ENDPOINT = 'https://api.github.com/user'
EMAILS_ENDPOINT = 'https://api.github.com/user/emails'

Expand Down