Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

refactor(sdk): simplify OAuth token detection to truthiness checks

jkomynoe300d2f0cfa6
diff --git a/python/composio/core/models/connected_accounts.py b/python/composio/core/models/connected_accounts.py
index 869e07589..a11b7daeb 100644
--- a/python/composio/core/models/connected_accounts.py
+++ b/python/composio/core/models/connected_accounts.py
@@ -94,13 +94,10 @@ class AuthScheme:
"""
Create a new connected account using OAuth 1.0.
"""
- oauth_token = options.get("oauth_token") # type: ignore[union-attr]
- oauth_token_secret = options.get("oauth_token_secret") # type: ignore[union-attr]
- has_tokens = (
- isinstance(oauth_token, str)
- and len(oauth_token) > 0
- and isinstance(oauth_token_secret, str)
- and len(oauth_token_secret) > 0
+ has_tokens = bool(
+ options.get("oauth_token") # type: ignore[union-attr]
+ ) and bool(
+ options.get("oauth_token_secret") # type: ignore[union-attr]
)
status = "ACTIVE" if has_tokens else "INITIALIZING"
return {
@@ -120,8 +117,7 @@ class AuthScheme:
"""
Create a new connected account using OAuth 2.0.
"""
- access_token = options.get("access_token") # type: ignore[union-attr]
- has_token = isinstance(access_token, str) and len(access_token) > 0
+ has_token = bool(options.get("access_token")) # type: ignore[union-attr]
status = "ACTIVE" if has_token else "INITIALIZING"
return {
"auth_scheme": "OAUTH2",
diff --git a/ts/packages/core/src/models/AuthScheme.ts b/ts/packages/core/src/models/AuthScheme.ts
index cf6ff8ce2..9ee42abb8 100644
--- a/ts/packages/core/src/models/AuthScheme.ts
+++ b/ts/packages/core/src/models/AuthScheme.ts
@@ -33,7 +33,7 @@ export class AuthScheme {
expired_at?: string;
}
): ConnectionData {
- const hasToken = typeof params.access_token === 'string' && params.access_token.length > 0;
+ const hasToken = !!params.access_token;
return {
authScheme: AuthSchemeTypes.OAUTH2,
val: {
@@ -60,11 +60,7 @@ export class AuthScheme {
expired_at?: string;
}
): ConnectionData {
- const hasTokens =
- typeof params.oauth_token === 'string' &&
- params.oauth_token.length > 0 &&
- typeof params.oauth_token_secret === 'string' &&
- params.oauth_token_secret.length > 0;
+ const hasTokens = !!params.oauth_token && !!params.oauth_token_secret;
return {
authScheme: AuthSchemeTypes.OAUTH1,
val: {