diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 0000000..499fb2a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:alpine + +WORKDIR /var/www/ + +COPY ./requirements.txt /var/www/requirements.txt + +RUN pip install -r /var/www/requirements.txt \ No newline at end of file diff --git a/app/app.py b/app/app.py index 67ab0be..88a7a44 100644 --- a/app/app.py +++ b/app/app.py @@ -12,17 +12,13 @@ oauth = OAuth(app) gotosocial = oauth.register( name='gotosocial', - # 010DGVDVM5ZN0D8W9WM0X59YMD - # 01JFPCR4Q8FYP273DPCW8FGDMJ - client_id='010DGVDVM5ZN0D8W9WM0X59YMD', - # 917ab929-90f5-4c87-b902-be6bed0d3a4e - # 5c190ea8-1984-4e05-b610-d7ed4d241079 - client_secret='917ab929-90f5-4c87-b902-be6bed0d3a4e', - access_token_url='https://gts.werefox.cafe/oauth/token', - access_token_params={'response_type':'token', 'grant_type':'authorization_code', 'client_id':'010DGVDVM5ZN0D8W9WM0X59YMD', 'client_secret':'917ab929-90f5-4c87-b902-be6bed0d3a4e'}, - authorize_url='https://gts.werefox.cafe/oauth/authorize', + client_id='', + client_secret='', + access_token_url='/oauth/token', + access_token_params={'response_type':'token', 'grant_type':'authorization_code', 'client_id':'', 'client_secret':''}, + authorize_url='/oauth/authorize', authorize_params={'grant_type':'authorization_code'}, - api_base_url='https://gts.werefox.cafe/api', + api_base_url='/api', client_kwargs={'scope': 'read'}, ) @@ -32,6 +28,30 @@ def index(): return render_template('index.html') +@app.route('/set_domain', methods=['POST']) +def set_domain(): + if(request.method == 'POST'): + payload = { + 'client_name':'gotosocial-fe', + 'redirect_uris':url_for('index', _external=True) + } + response = post(f'https://{request.form["domain"]}/api/v1/apps', data=payload) + client_data = response.json() + gotosocial.client_id = client_data['client_id'] + gotosocial.client_secret = client_data['client_secret'] + gotosocial.access_token_params = { + 'response_type':'token', + 'grant_type':'authorization_code', + 'client_id':client_data['client_id'], + 'client_secret':client_data['client_secret'] + } + gotosocial.access_token_url = f'https://{request.form["domain"]}{gotosocial.access_token_url}' + gotosocial.authorize_url = f'https://{request.form["domain"]}{gotosocial.authorize_url}' + gotosocial.api_base_url = f'https://{request.form["domain"]}{gotosocial.api_base_url}' + return redirect('/login') + else: + return "Sorry, but you can't get *GET* /set_domain, hun." + @app.route('/login') def login(): redirect_uri = url_for('authorize', _external=True) diff --git a/app/templates/index.html b/app/templates/index.html index 4529c53..a8a69b8 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -5,7 +5,11 @@ Some kind of Flask App
-

I guess you should input something

+

Put in your instance domain!

+
+ + +
login
diff --git a/deploy.sh b/deploy.sh index caf71e0..c5cb1be 100755 --- a/deploy.sh +++ b/deploy.sh @@ -6,8 +6,10 @@ FLASK_NAME=flaskoauth FLASK_ENV=$1 if [ "$FLASK_ENV" == "development" ] || [ "$FLASK_ENV" == "production" ]; then - cd app/ - flask run --host=0.0.0.0 + # cd app/ + # flask run --host=0.0.0.0 + FLASK_ENV=$FLASK_ENV docker compose up --build --remove-orphans -d && \ + docker compose logs -f else echo "Please use 'development' or 'production' as an argument." fi diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100755 index 0000000..ea1878e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +--- +version: "3" + +services: + app: + image: gotosocialfe:latest + build: . + volumes: + - ./app:/var/www/app + #environment: + # - + ports: + - 5000:5000 + command: 'sh -c "cd app && flask run --host=0.0.0.0"' diff --git a/register_app.py b/register_app.py deleted file mode 100755 index 7802ce3..0000000 --- a/register_app.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/python - -from requests import post - -payload={ - 'client_name':'anotherone', - 'redirect_uris':'localhost:5000' -} - -def register_app(): - resp = post('https://gts.werefox.cafe/api/v1/apps', data=payload) - return resp.text - -print(register_app()) diff --git a/requirements.txt b/requirements.txt index eed6339..c4072e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ Authlib>=1.2.0 Flask>=2.2.3 - +requests