mirror of
https://github.com/norohind/FDEV-CAPI-Handler.git
synced 2025-06-08 19:32:21 +03:00
add RandomToken for internal purposes
This commit is contained in:
parent
24950cb8d7
commit
7a51aaeb67
33
main.py
33
main.py
@ -226,6 +226,38 @@ class Admin:
|
|||||||
sql_connection.close()
|
sql_connection.close()
|
||||||
|
|
||||||
|
|
||||||
|
class RandomToken:
|
||||||
|
def on_get(self, req: falcon.request.Request, resp: falcon.response.Response):
|
||||||
|
access_key = req.headers.get('AUTH')
|
||||||
|
|
||||||
|
if access_key != 'hEjesv79YUZNeQgJ':
|
||||||
|
raise falcon.HTTPNotFound
|
||||||
|
|
||||||
|
sql_connection = sqlite3.connect(database="companion-api.sqlite")
|
||||||
|
random_token = sql_connection.execute(
|
||||||
|
'select state from authorizations where nickname is not null limit 1;',()).fetchone()
|
||||||
|
|
||||||
|
if random_token is None:
|
||||||
|
sql_connection.close()
|
||||||
|
raise falcon.HTTPNotFound(description="DB is empty")
|
||||||
|
|
||||||
|
state = random_token[0]
|
||||||
|
|
||||||
|
refresh_one_token(state)
|
||||||
|
|
||||||
|
access_token, expires_timestamp, nickname = sql_connection.execute(
|
||||||
|
'select access_token, timestamp_got_expires_in + expires_in, nickname from authorizations where state = ?',
|
||||||
|
[state]).fetchone()
|
||||||
|
|
||||||
|
import json
|
||||||
|
resp.text = json.dumps({'access_token': access_token,
|
||||||
|
'expires_over': expires_timestamp - int(time.time()),
|
||||||
|
'expires_on': expires_timestamp,
|
||||||
|
'nickname': nickname})
|
||||||
|
resp.content_type = falcon.MEDIA_JSON
|
||||||
|
sql_connection.close()
|
||||||
|
|
||||||
|
|
||||||
app = falcon.App()
|
app = falcon.App()
|
||||||
|
|
||||||
# routing
|
# routing
|
||||||
@ -233,5 +265,6 @@ app.add_route('/authorize', Authorize())
|
|||||||
app.add_route('/fdev-redirect', FDEV_redirect())
|
app.add_route('/fdev-redirect', FDEV_redirect())
|
||||||
app.add_route('/users/{user}', User())
|
app.add_route('/users/{user}', User())
|
||||||
app.add_route('/admin/{_state}', Admin())
|
app.add_route('/admin/{_state}', Admin())
|
||||||
|
app.add_route('/random_token', RandomToken())
|
||||||
|
|
||||||
waitress.serve(app, host='127.0.0.1', port=9000)
|
waitress.serve(app, host='127.0.0.1', port=9000)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user