Commit f0db7485 authored by echel0n's avatar echel0n
Browse files

cleaned up oauth2 offline token migration code

parent 5ae9e877
......@@ -31,20 +31,25 @@ def upgrade():
with op.get_context().begin_transaction():
for row in conn.execute(oauth2_token.select()):
refresh_token = row.refresh_token
if refresh_token:
break
if refresh_token:
certs = sickrage.app.auth_server.certs()
new_token = sickrage.app.auth_server.refresh_token(refresh_token)
decoded_token = sickrage.app.auth_server.decode_token(new_token['access_token'], certs)
apikey = decoded_token['apikey']
try:
session = sickrage.app.config.db.session()
general = session.query(ConfigDB.General).one()
general.sso_api_key = apikey
session.commit()
except orm.exc.NoResultFound:
pass
if certs:
new_token = sickrage.app.auth_server.refresh_token(refresh_token)
if new_token:
decoded_token = sickrage.app.auth_server.decode_token(new_token['access_token'], certs)
apikey = decoded_token.get('apikey')
try:
if apikey:
session = sickrage.app.config.db.session()
general = session.query(ConfigDB.General).one()
general.sso_api_key = apikey
session.commit()
except orm.exc.NoResultFound:
pass
if conn.engine.dialect.has_table(conn.engine, 'oauth2_token'):
op.drop_table('oauth2_token')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment