Skip to content

Automate browser based workflows with AI

get_valid_org_auth_tokens (#531)

Kerem Yilmaz6a6119b406b9
diff --git a/skyvern/forge/sdk/db/client.py b/skyvern/forge/sdk/db/client.py
index 70140a794..b18f01195 100644
--- a/skyvern/forge/sdk/db/client.py
+++ b/skyvern/forge/sdk/db/client.py
@@ -524,6 +524,7 @@ class AgentDB:
.filter_by(organization_id=organization_id)
.filter_by(token_type=token_type)
.filter_by(valid=True)
+ .order_by(OrganizationAuthTokenModel.created_at.desc())
)
).first():
return convert_to_organization_auth_token(token)
@@ -536,6 +537,30 @@ class AgentDB:
LOG.error("UnexpectedError", exc_info=True)
raise
+ async def get_valid_org_auth_tokens(
+ self,
+ organization_id: str,
+ token_type: OrganizationAuthTokenType,
+ ) -> list[OrganizationAuthToken]:
+ try:
+ async with self.Session() as session:
+ tokens = (
+ await session.scalars(
+ select(OrganizationAuthTokenModel)
+ .filter_by(organization_id=organization_id)
+ .filter_by(token_type=token_type)
+ .filter_by(valid=True)
+ .order_by(OrganizationAuthTokenModel.created_at.desc())
+ )
+ ).all()
+ return [convert_to_organization_auth_token(token) for token in tokens]
+ except SQLAlchemyError:
+ LOG.error("SQLAlchemyError", exc_info=True)
+ raise
+ except Exception:
+ LOG.error("UnexpectedError", exc_info=True)
+ raise
+
async def validate_org_auth_token(
self,
organization_id: str,