commit fb34edc21ad27bb2982c297648a6234be17333aa Author: Kairi Anderson Date: Sun Feb 19 16:28:53 2023 -0600 Initial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f813b31 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# Ignore pycache +*/__pycache__/** +*.pyc + +# I called my virtual environment "venv", this is so I don't commit it. +venv/** diff --git a/README.md b/README.md new file mode 100644 index 0000000..9a3f6fa --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# GoToSocial FE + +I'm gonna try to make a GoToSocial front-end. Right now, using Flask. + +# Usage + +`./deploy.sh development` or `./deploy.sh production` to run the Flask server. diff --git a/app/app.py b/app/app.py new file mode 100644 index 0000000..67ab0be --- /dev/null +++ b/app/app.py @@ -0,0 +1,50 @@ +from flask import Flask, render_template, url_for, redirect, request +from authlib.integrations.flask_client import OAuth +from secrets import token_urlsafe +from requests import post + +app = Flask(__name__) + +SECRET_KEY = token_urlsafe(32) +app.secret_key = SECRET_KEY + +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', + authorize_params={'grant_type':'authorization_code'}, + api_base_url='https://gts.werefox.cafe/api', + client_kwargs={'scope': 'read'}, +) + + +@app.route('/') +def index(): + return render_template('index.html') + + +@app.route('/login') +def login(): + redirect_uri = url_for('authorize', _external=True) + return gotosocial.authorize_redirect(redirect_uri) + + +@app.route('/authorize') +def authorize(): + token = gotosocial.authorize_access_token() + print(token) + response = gotosocial.get( + 'api/v1/accounts/verify_credentials', token=token) + response.raise_for_status() + account_info = response.json() + return account_info + diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..4529c53 --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,12 @@ + + + + + Some kind of Flask App + +
+

I guess you should input something

+ login +
+ + diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..caf71e0 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -xe + +FLASK_NAME=flaskoauth +FLASK_ENV=$1 + +if [ "$FLASK_ENV" == "development" ] || [ "$FLASK_ENV" == "production" ]; then + cd app/ + flask run --host=0.0.0.0 +else + echo "Please use 'development' or 'production' as an argument." +fi diff --git a/register_app.py b/register_app.py new file mode 100755 index 0000000..7802ce3 --- /dev/null +++ b/register_app.py @@ -0,0 +1,14 @@ +#!/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 new file mode 100644 index 0000000..eed6339 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +Authlib>=1.2.0 +Flask>=2.2.3 +