-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,6 @@ | |
- [ ] 百度 | ||
- [x] Gitee | ||
- [x] Github | ||
- [ ] 开源中国 | ||
- [X] 开源中国 | ||
- [ ] 阿里云 | ||
- [ ] TestHome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
import httpx | ||
|
||
from fastapi_oauth20.oauth20 import OAuth20Base | ||
|
||
AUTHORIZE_ENDPOINT = 'https://www.oschina.net/action/oauth2/authorize' | ||
ACCESS_TOKEN_ENDPOINT = 'https://www.oschina.net/action/openapi/token' | ||
REFRESH_TOKEN_ENDPOINT = ACCESS_TOKEN_ENDPOINT | ||
PROFILE_ENDPOINT = 'https://www.oschina.net/action/openapi/user' | ||
|
||
|
||
class OSChinaOAuth20(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='oschina', | ||
default_scopes=None, | ||
) | ||
|
||
async def get_userinfo(self, access_token: str) -> dict: | ||
"""Get user info from OSChina""" | ||
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 |