Skip to content

Commit

Permalink
Refurb #5
Browse files Browse the repository at this point in the history
Refurbish
  • Loading branch information
Nazar1ky authored May 13, 2024
2 parents ff83a69 + 449b629 commit 926b5fd
Showing 1 changed file with 59 additions and 24 deletions.
83 changes: 59 additions & 24 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import requests
from rich.console import Console

TIMEOUT_IN_SECONDS = 10


class DeleteFriends:
def __init__(self):
def __init__(self) -> None:
self.client = base64.b64encode(
"98f7e42c2e3a4f86a74eb43fbb41ed39:0a2449a2-001a-451e-afec-3e812901c4d7"
.encode("utf-8")
).decode("utf-8") # https://github.com/MixV2/EpicResearch/blob/master/docs/auth/auth_clients.md
b"98f7e42c2e3a4f86a74eb43fbb41ed39:0a2449a2-001a-451e-afec-3e812901c4d7",
).decode(
"utf-8",
) # https://github.com/MixV2/EpicResearch/blob/master/docs/auth/auth_clients.md

self.console = Console()
self.console.clear()
Expand All @@ -21,15 +24,17 @@ def __init__(self):

auth_link, device_code = self.device_code(token)

self.console.input(f"[green bold]Verify login [/green bold][yellow](click enter to continue)[/yellow][green bold]:[/green bold] [red]{auth_link}")
self.console.input(
f"[green bold]Verify login [/green bold][yellow](click enter to continue)[/yellow][green bold]:[/green bold] [red]{auth_link}",
)
data = self.device_code_verify(device_code)

if not data:
self.console.print("[red][bold][ERROR][/bold] Try restart script.")

self.data = data

def run(self):
def run(self) -> None:
self.console.clear()

self.console.print(f"[green]Successfully logged in {self.data['display_name']}")
Expand All @@ -39,9 +44,13 @@ def run(self):
friends_count = self.get_friend_count()
self.delete_friends()

self.console.print(f"[green bold]Removed {friends_count} friends![/green bold] [yellow]You can kill all sessions to reset token.")
self.console.print(
f"[green bold]Removed {friends_count} friends![/green bold] [yellow]You can kill all sessions to reset token.",
)

def create_token(self): # Reference: https://github.com/MixV2/EpicResearch/blob/master/docs/auth/grant_types/client_credentials.md
def create_token(
self,
): # Reference: https://github.com/MixV2/EpicResearch/blob/master/docs/auth/grant_types/client_credentials.md
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": f"basic {self.client}",
Expand All @@ -50,25 +59,36 @@ def create_token(self): # Reference: https://github.com/MixV2/EpicResearch/blob/
"grant_type": "client_credentials",
}

response = requests.post("https://account-public-service-prod.ol.epicgames.com/account/api/oauth/token", headers=headers, data=body)

data = response.json()
data = requests.post(
"https://account-public-service-prod.ol.epicgames.com/account/api/oauth/token",
headers=headers,
data=body,
timeout=TIMEOUT_IN_SECONDS,
).json()

return data["access_token"]

def device_code(self, token): # Reference: https://github.com/LeleDerGrasshalmi/FortniteEndpointsDocumentation/blob/main/EpicGames/AccountService/Authentication/DeviceCode/Create.md
def device_code(
self,
token,
): # Reference: https://github.com/LeleDerGrasshalmi/FortniteEndpointsDocumentation/blob/main/EpicGames/AccountService/Authentication/DeviceCode/Create.md
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": f"bearer {token}",
}

response = requests.post("https://account-public-service-prod03.ol.epicgames.com/account/api/oauth/deviceAuthorization", headers=headers)

data = response.json()
data = requests.post(
"https://account-public-service-prod03.ol.epicgames.com/account/api/oauth/deviceAuthorization",
headers=headers,
timeout=TIMEOUT_IN_SECONDS,
).json()

return data["verification_uri_complete"], data["device_code"]

def device_code_verify(self, device_code): # Reference: https://github.com/MixV2/EpicResearch/blob/master/docs/auth/grant_types/device_code.md
def device_code_verify(
self,
device_code,
): # Reference: https://github.com/MixV2/EpicResearch/blob/master/docs/auth/grant_types/device_code.md
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": f"basic {self.client}",
Expand All @@ -79,9 +99,12 @@ def device_code_verify(self, device_code): # Reference: https://github.com/MixV2
"device_code": device_code,
}

response = requests.post("https://account-public-service-prod.ol.epicgames.com/account/api/oauth/token", headers=headers, data=body)

data = response.json()
data = requests.post(
"https://account-public-service-prod.ol.epicgames.com/account/api/oauth/token",
headers=headers,
data=body,
timeout=TIMEOUT_IN_SECONDS,
).json()

if "errorCode" in data:
return None
Expand All @@ -92,24 +115,36 @@ def device_code_verify(self, device_code): # Reference: https://github.com/MixV2
"access_token": data["access_token"],
}

def get_friend_count(self): # Reference: https://github.com/LeleDerGrasshalmi/FortniteEndpointsDocumentation/blob/main/EpicGames/FriendsService/Friends/FriendsList.md
def get_friend_count(
self,
): # Reference: https://github.com/LeleDerGrasshalmi/FortniteEndpointsDocumentation/blob/main/EpicGames/FriendsService/Friends/FriendsList.md
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": f"bearer {self.data['access_token']}",
}

data = requests.get(f"https://friends-public-service-prod.ol.epicgames.com/friends/api/v1/{self.data['account_id']}/summary", headers=headers).json()
data = requests.get(
f"https://friends-public-service-prod.ol.epicgames.com/friends/api/v1/{self.data['account_id']}/summary",
headers=headers,
timeout=TIMEOUT_IN_SECONDS,
).json()

return len(data["friends"])


def delete_friends(self): # Reference: https://github.com/LeleDerGrasshalmi/FortniteEndpointsDocumentation/blob/main/EpicGames/FriendsService/Friends/Clear.md
def delete_friends(
self,
) -> None: # Reference: https://github.com/LeleDerGrasshalmi/FortniteEndpointsDocumentation/blob/main/EpicGames/FriendsService/Friends/Clear.md
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": f"bearer {self.data['access_token']}",
}

requests.delete(f"https://friends-public-service-prod.ol.epicgames.com/friends/api/v1/{self.data["account_id"]}/friends", headers=headers)
requests.delete(
f"https://friends-public-service-prod.ol.epicgames.com/friends/api/v1/{self.data["account_id"]}/friends",
headers=headers,
timeout=TIMEOUT_IN_SECONDS,
)


if __name__ == "__main__":
app = DeleteFriends()
Expand Down

0 comments on commit 926b5fd

Please sign in to comment.