Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 22, 03:15 UTC
refactor(sdk): simplify OAuth token detection to truthiness checks
Replace verbose typeof/isinstance + length checks with simple truthiness checks (!! in TS, bool() in Python). The type system already constrains these params to string|undefined, so truthiness correctly handles undefined, None, and empty string.
jkomyno committed
Mar 13, 2026 at 02:15 UTC
e300d2f0cfa62d488e6a992802773f50ce7f65ec
2 files changed
+7
-15
python/composio/core/models/connected_accounts.py
+5
-9
@@ -94,13 +94,10 @@ class AuthScheme:
94
"""
95
Create a new connected account using OAuth 1.0.
96
"""
97
- oauth_token = options.get("oauth_token") # type: ignore[union-attr]
98
- oauth_token_secret = options.get("oauth_token_secret") # type: ignore[union-attr]
99
- has_tokens = (
100
- isinstance(oauth_token, str)
101
- and len(oauth_token) > 0
102
- and isinstance(oauth_token_secret, str)
103
- and len(oauth_token_secret) > 0
97
+ has_tokens = bool(
98
+ options.get("oauth_token") # type: ignore[union-attr]
99
+ ) and bool(
100
+ options.get("oauth_token_secret") # type: ignore[union-attr]
101
)
102
status = "ACTIVE" if has_tokens else "INITIALIZING"
103
return {
@@ -120,8 +117,7 @@ class AuthScheme:
117
"""
118
Create a new connected account using OAuth 2.0.
119
"""
123
- access_token = options.get("access_token") # type: ignore[union-attr]
124
- has_token = isinstance(access_token, str) and len(access_token) > 0
120
+ has_token = bool(options.get("access_token")) # type: ignore[union-attr]
121
status = "ACTIVE" if has_token else "INITIALIZING"
122
return {
123
"auth_scheme": "OAUTH2",
ts/packages/core/src/models/AuthScheme.ts
+2
-6
@@ -33,7 +33,7 @@ export class AuthScheme {
33
expired_at?: string;
34
}
35
): ConnectionData {
36
- const hasToken = typeof params.access_token === 'string' && params.access_token.length > 0;
36
+ const hasToken = !!params.access_token;
37
return {
38
authScheme: AuthSchemeTypes.OAUTH2,
39
val: {
@@ -60,11 +60,7 @@ export class AuthScheme {
60
expired_at?: string;
61
}
62
): ConnectionData {
63
- const hasTokens =
64
- typeof params.oauth_token === 'string' &&
65
- params.oauth_token.length > 0 &&
66
- typeof params.oauth_token_secret === 'string' &&
67
- params.oauth_token_secret.length > 0;
63
+ const hasTokens = !!params.oauth_token && !!params.oauth_token_secret;
64
return {
65
authScheme: AuthSchemeTypes.OAUTH1,
66
val: {