This commit is contained in:
parent
c89806fe87
commit
0b5e56b69b
6 changed files with 27 additions and 25 deletions
|
|
@ -18,6 +18,7 @@ class Settings(BaseSettings):
|
||||||
twitter_client_id: str
|
twitter_client_id: str
|
||||||
twitter_client_secret: str
|
twitter_client_secret: str
|
||||||
twitter_redirect_uri: str
|
twitter_redirect_uri: str
|
||||||
|
account_client_secret: str
|
||||||
|
|
||||||
model_config = SettingsConfigDict(
|
model_config = SettingsConfigDict(
|
||||||
env_file=[
|
env_file=[
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ async def get_equipment_composite(request: Request, db: DBSession = Depends(get_
|
||||||
try:
|
try:
|
||||||
decrypted_pass = cipher.decrypt(user.spfn_pass_enc.encode()).decode()
|
decrypted_pass = cipher.decrypt(user.spfn_pass_enc.encode()).decode()
|
||||||
token_data = auth.get_token(user.username, decrypted_pass)
|
token_data = auth.get_token(user.username, decrypted_pass)
|
||||||
profile = json.loads(auth.get_profile(token_data["token"]))
|
profile = json.loads(auth.get_profile(token_data["access_token"]))
|
||||||
pid_val = int(profile.get("pid"))
|
pid_val = int(profile.get("pid"))
|
||||||
mii_name = profile.get("name", user.username)
|
mii_name = profile.get("name", user.username)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ async def get_history(request: Request, db: DBSession = Depends(get_db)):
|
||||||
try:
|
try:
|
||||||
decrypted_pass = cipher.decrypt(user.spfn_pass_enc.encode()).decode()
|
decrypted_pass = cipher.decrypt(user.spfn_pass_enc.encode()).decode()
|
||||||
token_data = auth.get_token(user.username, decrypted_pass)
|
token_data = auth.get_token(user.username, decrypted_pass)
|
||||||
profile = json.loads(auth.get_profile(token_data["token"]))
|
profile = json.loads(auth.get_profile(token_data["access_token"]))
|
||||||
pid_val = int(profile.get("pid"))
|
pid_val = int(profile.get("pid"))
|
||||||
print(f"Fetching History for PID: {pid_val}")
|
print(f"Fetching History for PID: {pid_val}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,10 @@ async def get_my_profile(request: Request, db: DBSession = Depends(get_db)):
|
||||||
decrypted_pass = cipher.decrypt(user.spfn_pass_enc.encode()).decode()
|
decrypted_pass = cipher.decrypt(user.spfn_pass_enc.encode()).decode()
|
||||||
|
|
||||||
token_data = auth.get_token(user.username, decrypted_pass)
|
token_data = auth.get_token(user.username, decrypted_pass)
|
||||||
if not token_data or "token" not in token_data:
|
if not token_data or "access_token" not in token_data:
|
||||||
return RedirectResponse(url="/sign_in/")
|
return RedirectResponse(url="/sign_in/")
|
||||||
|
|
||||||
profile_data = auth.get_profile(token_data["token"])
|
profile_data = auth.get_profile(token_data["access_token"])
|
||||||
if not profile_data:
|
if not profile_data:
|
||||||
raise HTTPException(status_code=404, detail="Profile not found")
|
raise HTTPException(status_code=404, detail="Profile not found")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ async def login(
|
||||||
try:
|
try:
|
||||||
print("fetching spfn token")
|
print("fetching spfn token")
|
||||||
data = auth.get_token(username, password)
|
data = auth.get_token(username, password)
|
||||||
if not data or "token" not in data:
|
if not data or "access_token" not in data:
|
||||||
print("auth failed")
|
print("auth failed")
|
||||||
return RedirectResponse(f"{auth_path}{sep}error=auth&username={username}", 303)
|
return RedirectResponse(f"{auth_path}{sep}error=auth&username={username}", 303)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,36 @@
|
||||||
import requests
|
import requests
|
||||||
import base64
|
from config import settings
|
||||||
from argon2 import PasswordHasher
|
|
||||||
|
|
||||||
API_URL = "https://account.spfn.net/api/v2"
|
API_URL = "https://account.spfn.net/api/v2"
|
||||||
ph = PasswordHasher()
|
CLIENT_ID = "splatnet"
|
||||||
|
CLIENT_SECRET = settings.account_client_secret
|
||||||
def hash_password(password: str):
|
|
||||||
return ph.hash(password)
|
|
||||||
|
|
||||||
def verify_password(hashed: str, password: str):
|
|
||||||
try:
|
|
||||||
return ph.verify(hashed, password)
|
|
||||||
except Exception:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def get_token(username, password):
|
def get_token(username, password):
|
||||||
creds = f"{username} {password}"
|
url = f"{API_URL}/oauth2/generate_token"
|
||||||
encoded = base64.b64encode(creds.encode()).decode()
|
|
||||||
|
|
||||||
headers = {
|
payload = {
|
||||||
"Authorization": f"Basic {encoded}",
|
"grant_type": "password",
|
||||||
"User-Agent": "saturday & allison should lwk kiss..."
|
"username": username,
|
||||||
|
"password": password,
|
||||||
|
"client_id": CLIENT_ID,
|
||||||
|
"client_secret": CLIENT_SECRET
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.get(f"{API_URL}/oauth2/generate_token", headers=headers, timeout=10)
|
headers = {
|
||||||
|
"User-Agent": "chiyo & eri should lwk kiss..."
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(url, data=payload, headers=headers, timeout=10)
|
||||||
return response.json() if response.ok else None
|
return response.json() if response.ok else None
|
||||||
|
|
||||||
def get_profile(token):
|
def get_profile(token):
|
||||||
|
url = f"{API_URL}/users/@me/profile"
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {token}",
|
"Authorization": f"Bearer {token}",
|
||||||
"User-Agent": "every update im going to change this user agent because im bored!!"
|
"User-Agent": "lets make the most of the night like were gonna die young!!"
|
||||||
}
|
}
|
||||||
response = requests.get(f"{API_URL}/users/@me/profile", headers=headers, timeout=10)
|
|
||||||
return response.text if response.ok else None
|
response = requests.get(url, headers=headers, timeout=10)
|
||||||
|
|
||||||
|
return response.json() if response.ok else None
|
||||||
Loading…
Reference in a new issue