(fix:auth) refresh drive token

This commit is contained in:
ManishMadan2882
2025-09-19 22:57:09 +05:30
parent 0ee875bee4
commit 896612a5a3
3 changed files with 177 additions and 140 deletions

View File

@@ -441,9 +441,29 @@ class ConnectorValidateSession(Resource):
auth = ConnectorCreator.create_auth(provider)
is_expired = auth.is_token_expired(token_info)
if is_expired and token_info.get('refresh_token'):
try:
new_token_info = auth.refresh_access_token(token_info.get('refresh_token'))
sessions_collection.update_one(
{"session_token": session_token},
{"$set": {"token_info": new_token_info}}
)
token_info = new_token_info
is_expired = False
except Exception as refresh_error:
current_app.logger.error(f"Failed to refresh token: {refresh_error}")
if is_expired:
return make_response(jsonify({
"success": False,
"expired": True,
"error": "Session token has expired. Please reconnect."
}), 401)
return make_response(jsonify({
"success": True,
"expired": is_expired,
"expired": False,
"user_email": session.get('user_email', 'Connected User'),
"access_token": token_info.get('access_token')
}), 200)