Skip to content

Commit

Permalink
use local ip address instad of localhost
Browse files Browse the repository at this point in the history
if we are not doing that we cant make the ssh setup work
  • Loading branch information
prochy-exe committed May 12, 2024
1 parent 7888e5d commit ccb7bff
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions malfetcher/mal_config_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import socket
import os, webbrowser, platform, requests, gevent, gc, string, random
from flask import Flask, request, redirect
from gevent.pywsgi import WSGIServer
Expand All @@ -17,6 +18,19 @@ def generate_random_string(length):

code_verifier = generate_mal_verifier()

def get_ip_address():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip_address = s.getsockname()[0]
s.close()
return ip_address
except Exception as e:
print("Error:", e)
return None

host_ip = get_ip_address()

# Paths
script_path = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(script_path, 'config', 'config.json')
Expand Down Expand Up @@ -108,7 +122,7 @@ def make_request(code):
'client_secret': global_secret,
'grant_type': "authorization_code",
'code': code,
'redirect_uri': f"http://localhost:8888/access_token",
'redirect_uri': f"http://{host_ip}:8888/access_token",
'code_verifier': code_verifier,
'state': "authrequest"
}
Expand Down Expand Up @@ -143,7 +157,7 @@ def start_webserver():
webbrowser.open(global_tooltip, 0)
http_server.serve_forever()

http_server = WSGIServer(("127.0.0.1", 8888), app, log=None)
http_server = WSGIServer((host_ip, 8888), app, log=None)

return start_webserver, http_server

Expand Down Expand Up @@ -172,7 +186,7 @@ def generate_api_key(client_id, client_secret):
global_tooltip = "https://myanimelist.net/v1/oauth2/authorize?"
global_tooltip += "response_type=code"
global_tooltip += f"&client_id={global_id}"
global_tooltip += "&redirect_uri=http://localhost:8888/access_token"
global_tooltip += f"&redirect_uri=http://{host_ip}:8888/access_token"
global_tooltip += f"&code_challenge={code_verifier}"
global_tooltip += "&code_challenge_method=plain"
global_tooltip += "&state=authrequest"
Expand Down

0 comments on commit ccb7bff

Please sign in to comment.