2026-02-06 01:29:26 +01:00
|
|
|
import requests
|
2026-06-21 23:37:29 +02:00
|
|
|
from config import settings
|
2026-06-23 06:50:34 +02:00
|
|
|
from argon2 import PasswordHasher
|
2026-02-06 01:29:26 +01:00
|
|
|
|
|
|
|
|
API_URL = "https://account.spfn.net/api/v2"
|
2026-06-21 23:37:29 +02:00
|
|
|
CLIENT_ID = "splatnet"
|
|
|
|
|
CLIENT_SECRET = settings.account_client_secret
|
2026-06-23 06:50:34 +02:00
|
|
|
ph = PasswordHasher()
|
|
|
|
|
|
|
|
|
|
def hash_password(password: str):
|
|
|
|
|
return ph.hash(password)
|
2026-02-06 01:29:26 +01:00
|
|
|
|
|
|
|
|
def get_token(username, password):
|
2026-06-21 23:37:29 +02:00
|
|
|
url = f"{API_URL}/oauth2/generate_token"
|
|
|
|
|
|
|
|
|
|
payload = {
|
|
|
|
|
"grant_type": "password",
|
|
|
|
|
"username": username,
|
|
|
|
|
"password": password,
|
|
|
|
|
"client_id": CLIENT_ID,
|
|
|
|
|
"client_secret": CLIENT_SECRET
|
|
|
|
|
}
|
2026-02-06 01:29:26 +01:00
|
|
|
|
|
|
|
|
headers = {
|
2026-06-21 23:37:29 +02:00
|
|
|
"User-Agent": "chiyo & eri should lwk kiss..."
|
2026-02-06 01:29:26 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-21 23:37:29 +02:00
|
|
|
response = requests.post(url, data=payload, headers=headers, timeout=10)
|
2026-02-06 04:00:43 +01:00
|
|
|
return response.json() if response.ok else None
|
2026-02-06 01:29:26 +01:00
|
|
|
|
|
|
|
|
def get_profile(token):
|
2026-06-21 23:37:29 +02:00
|
|
|
url = f"{API_URL}/users/@me/profile"
|
|
|
|
|
|
2026-02-06 01:29:26 +01:00
|
|
|
headers = {
|
|
|
|
|
"Authorization": f"Bearer {token}",
|
2026-06-21 23:37:29 +02:00
|
|
|
"User-Agent": "lets make the most of the night like were gonna die young!!"
|
2026-02-06 01:29:26 +01:00
|
|
|
}
|
2026-06-21 23:37:29 +02:00
|
|
|
|
|
|
|
|
response = requests.get(url, headers=headers, timeout=10)
|
|
|
|
|
|
|
|
|
|
return response.json() if response.ok else None
|