summaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
authorJannick <[email protected]>2024-04-10 14:38:50 +0200
committerJannick <[email protected]>2024-04-10 14:38:50 +0200
commit58e2a2d652c07c3fc0666d2d03c05cf3fb629a02 (patch)
tree8ef28b866f715eb72e4b4c21fda038240c796af1 /app.py
parent893c900f682369b0dbf37ff124b7a35d1b5d1601 (diff)
Created the foundation for OAuth2 authentication with battle.net. also
added a log in button.
Diffstat (limited to 'app.py')
-rw-r--r--app.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/app.py b/app.py
index c58833c..7621b28 100644
--- a/app.py
+++ b/app.py
@@ -1,5 +1,17 @@
-from bottle import Bottle, run, debug, static_file
+from bottle import Bottle, run, debug, static_file, request, redirect, response
from bottle import jinja2_template as template
+from oauthlib.oauth2 import WebApplicationClient
+from requests_oauthlib import OAuth2Session
+import secrets
+
+CLIENT_ID = "x" # DOTENV ligger paa discorden, repoet er publkic saa det
+CLIENT_SECRET = "x" # DOTENV PAHAHAH
+REDIRECT_URI = "http://localhost:8080/callback"
+# REDIRECT_URI = "https://google.com"
+
+AUTH_BASE_URL = 'https://oauth.battle.net/authorize'
+TOKEN_URL = "https://oauth.battle.net/token"
+client = WebApplicationClient(CLIENT_ID)
app = Bottle()
@@ -8,6 +20,22 @@ app = Bottle()
def index():
return template("index")
+def battle():
+ state = secrets.token_urlsafe(16)
+ response.set_cookie('oauth_state', state)
+ authorization_url = client.prepare_request_uri(AUTH_BASE_URL, redirect_uri=REDIRECT_URI, state=state)
+ return redirect(authorization_url)
+
[email protected]('/callback')
+def callback():
+ state = request.get_cookie('oauth_state')
+ code = request.query.get('code')
+ oauth2_session = OAuth2Session(CLIENT_ID, state=state, redirect_uri=REDIRECT_URI)
+ token_response = oauth2_session.fetch_token(TOKEN_URL, authorization_response=request.url, client_secret=CLIENT_SECRET)
+
+ return f'Access token: {token_response.get("access_token")}'
+
@app.route("/join.html")
def join_form():
return template("join")