Fixed oauth error (#223)
This commit is contained in:
parent
dc0b86f371
commit
b5ce29bbbd
1 changed files with 9 additions and 4 deletions
|
@ -5,6 +5,7 @@ from files.helpers.const import *
|
|||
from files.classes import *
|
||||
from flask import *
|
||||
from files.__main__ import app, limiter
|
||||
import sqlalchemy.exc
|
||||
|
||||
@app.get("/authorize")
|
||||
@auth_required
|
||||
|
@ -24,11 +25,15 @@ def authorize(v):
|
|||
application = g.db.query(OauthApp).filter_by(client_id=client_id).one_or_none()
|
||||
if not application: return {"oauth_error": "Invalid `client_id`"}, 401
|
||||
access_token = secrets.token_urlsafe(128)[:128]
|
||||
|
||||
try:
|
||||
new_auth = ClientAuth(oauth_client = application.id, user_id = v.id, access_token=access_token)
|
||||
|
||||
g.db.add(new_auth)
|
||||
|
||||
g.db.commit()
|
||||
except sqlalchemy.exc.IntegrityError:
|
||||
g.db.rollback()
|
||||
old_auth = g.db.query(ClientAuth).filter_by(oauth_client = application.id, user_id = v.id).one()
|
||||
access_token = old_auth.access_token
|
||||
|
||||
return redirect(f"{application.redirect_uri}?token={access_token}")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue