online-go / online-go.com

Source code for the Online-Go.com web interface
https://online-go.com/
GNU Affero General Public License v3.0
1.27k stars 345 forks source link

cant get http://online-go.com/oauth2/access_token #2500

Open travisbikkle opened 10 months ago

travisbikkle commented 10 months ago

Describe the bug I followed

  1. create oauth application : https://online-go.com/oauth2/applications/

    image
  2. post to http://online-go.com/oauth2/access_token with client_id, client_secret, grant_type, username, password

    image

    https://ogs.docs.apiary.io/#

    I got

    image

What I'm trying to do I'm trying to making a game, user could login in with their ogs account to watch games or play with others. My understanding is, I need to

  1. create an oauth application, got my client_id and client_secret
  2. let player fill in the username and password
  3. post client_id, client_secret, player's username and password to http://online-go.com/oauth2/access_token to get a access_token
  4. with this access_token, access realtime api like http://online-go.com/game/connect (where do i get the user_id btw) or other rest api like http://online-go.com/games to list games

is that right? or i misunderstood something? cause i've been tyring to figure this out all day and failed, a little frustrating. could anyone help? thanks!

travisbikkle commented 10 months ago

Any reply will be appreciated, please!

n-sweep commented 2 months ago

I am experiencing the same behavior

import requests
import time
import threading

from flask import Flask

app = Flask(__name__)
stop_thread = threading.Event()

def read_file(path):
    with open(path, 'r') as f:
        return f.read().strip()

def run_app():
    app.run(debug=True, threaded=True, use_reloader=False)

@app.route("/")
def hello_world(req):
    print(req)
    return "hello go"

def main():
    thread = threading.Thread(target=run_app)
    thread.start()

    time.sleep(1)

    params = {
        'client_id': read_file('/home/n/.config/ogs/client_id'),
        'client_secret': read_file('/home/n/.config/ogs/client_secret'),
        'grant_type': 'password',
        'username': 'n_sweep',
        'password': read_file('/home/n/.config/ogs/pw'),
    }

    r = requests.post(
        "http://online-go.com/oauth2/access_token",
        headers={'Content-Type': 'application/x-www-form-urlencoded'},
        data=params
    )

    print(r.status_code, r.text)

if __name__ == '__main__':
    main()
λ python run.py
 * Serving Flask app 'py'
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit
404
<!doctype html>
<html lang="en">
<head>
  <title>Not Found</title>
</head>
<body>
  <h1>Not Found</h1><p>The requested resource was not found on this server.</p>
</body>
</html>
curl --include \
     --request POST \
     --header "Content-Type: application/x-www-form-urlencoded" \
     --data-binary "client_id=$(cat ~/.config/ogs/client_id)&client_secret=$(cat ~/.config/ogs/client_secret)&grant_type=password&username=n_sweep&password=$(cat ~/.config/ogs/pw)" \
'http://online-go.com/oauth2/access_token'
HTTP/1.1 301 Moved Permanently
Date: Sun, 22 Sep 2024 17:54:18 GMT
Content-Type: text/html
Content-Length: 167
Connection: keep-alive
Cache-Control: max-age=3600
Expires: Sun, 22 Sep 2024 18:54:18 GMT
Location: https://online-go.com/oauth2/access_token
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=idk_if_this_is_sensitive"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Server: cloudflare
CF-RAY: 8c7428cfe98d2324-ORD

<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>cloudflare</center>
</body>
</html>