25 lines
936 B
Python
25 lines
936 B
Python
import requests
|
|
from . import config
|
|
|
|
def get_gitea_token(code: str):
|
|
"""Меняет временный код на access token."""
|
|
url = f"{config.GITEA_URL}/login/oauth/access_token"
|
|
data = {
|
|
"client_id": config.GITEA_CLIENT_ID,
|
|
"client_secret": config.GITEA_CLIENT_SECRET,
|
|
"code": code,
|
|
"grant_type": "authorization_code",
|
|
"redirect_uri": "https://portal.morozovka.space/auth/callback"
|
|
}
|
|
response = requests.post(url, data=data, headers={"Accept": "application/json"})
|
|
return response.json().get("access_token")
|
|
|
|
def get_gitea_user(token: str):
|
|
"""Получает данные пользователя из Gitea по токену."""
|
|
url = f"{config.GITEA_URL}/api/v1/user"
|
|
headers = {"Authorization": f"token {token}"}
|
|
response = requests.get(url, headers=headers)
|
|
if response.status_code == 200:
|
|
return response.json()
|
|
return None
|