-
Notifications
You must be signed in to change notification settings - Fork 2
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
5 changed files
with
48 additions
and
5 deletions.
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
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
import uvicorn | ||
|
||
from fastapi import Depends, FastAPI | ||
|
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,36 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
import httpx | ||
|
||
from fastapi_oauth20.oauth20 import OAuth20Base | ||
|
||
AUTHORIZE_ENDPOINT = 'https://gitee.com/oauth/authorize' | ||
ACCESS_TOKEN_ENDPOINT = 'https://gitee.com/oauth/token' | ||
REFRESH_TOKEN_ENDPOINT = ACCESS_TOKEN_ENDPOINT | ||
DEFAULT_SCOPES = ['user_info'] | ||
PROFILE_ENDPOINT = 'https://gitee.com/api/v5/user' | ||
|
||
|
||
class GiteeOAuth20(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='gitee', | ||
default_scopes=DEFAULT_SCOPES, | ||
) | ||
|
||
async def get_userinfo(self, access_token: str) -> dict: | ||
"""Get user info from Gitee""" | ||
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 |
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
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