Added a container option for deployment, since that's what I'll be doing. Added requests library to requirements. Authentication flow now happens with a form submission of an instance domain.

This commit is contained in:
Ada Werefox 2023-02-23 00:08:18 +00:00
parent fb34edc21a
commit 83248bab22
7 changed files with 61 additions and 28 deletions

7
Dockerfile Executable file
View File

@ -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

View File

@ -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)

View File

@ -5,7 +5,11 @@
<title>Some kind of Flask App</title>
</head>
<div>
<p>I guess you should input something</p>
<p>Put in your instance domain!</p>
<form method="POST" action={{url_for('set_domain')}}>
<input type="text" name="domain"></input>
<input type="submit" value="Go!"></input>
</form>
<a href="/login">login</a>
</div>
</body>

View File

@ -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

14
docker-compose.yml Executable file
View File

@ -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"'

View File

@ -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())

View File

@ -1,3 +1,3 @@
Authlib>=1.2.0
Flask>=2.2.3
requests