SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.
JavaScript a2aagentic-aiai-agentsdevtoolsmcp-clientn8n-alternativeno-codeopen-sourceorchestrationsmythosvisual-builder
add scope&audience support for oauth2 client creds
ahmedcoder010d1a6d8259f4
diff --git a/packages/app/src/backend/routes/api/page/vault.ts b/packages/app/src/backend/routes/api/page/vault.tsindex 28a833f7..c0fa931b 100644--- a/packages/app/src/backend/routes/api/page/vault.ts+++ b/packages/app/src/backend/routes/api/page/vault.ts@@ -65,6 +65,7 @@ function normalizeAuthSettingsObject(authSettings: any): any {'service','platform','scope',+ 'audience','authorizationURL','tokenURL','clientID',@@ -270,6 +271,7 @@ function sanitizeOAuthConnections(connections: any): any {'service','type','scope',+ 'audience','authorizationURL','tokenURL','requestTokenURL',@@ -503,6 +505,7 @@ router.put('/oauth-connections', includeTeamDetails, async (req, res) => {'clientID','clientSecret','scope',+ 'audience','authorizationURL','tokenURL','consumerKey',diff --git a/packages/app/src/backend/routes/oauth/router.ts b/packages/app/src/backend/routes/oauth/router.tsindex 7839577a..8abfc072 100644--- a/packages/app/src/backend/routes/oauth/router.ts+++ b/packages/app/src/backend/routes/oauth/router.ts@@ -73,6 +73,7 @@ function normalizeAuthSettings(mergedSettings: any): any {'service','platform','scope',+ 'audience','authorizationURL','tokenURL','clientID',@@ -803,7 +804,7 @@ router.post('/signOut', includeTeamDetails, async (req, res) => {}});-async function getClientCredentialToken({ clientID, clientSecret, tokenURL }) {+async function getClientCredentialToken({ clientID, clientSecret, tokenURL, scope, audience }) {try {// Sanity checksif (!clientID || !clientSecret || !tokenURL) {@@ -816,6 +817,16 @@ async function getClientCredentialToken({ clientID, clientSecret, tokenURL }) {client_secret: clientSecret,});+ // Add audience if provided (required by some providers like Auth0)+ if (audience && typeof audience === 'string' && audience.trim()) {+ params.append('audience', audience.trim());+ }++ // Add scope if provided (OAuth2 Client Credentials supports scopes)+ if (scope && typeof scope === 'string' && scope.trim()) {+ params.append('scope', scope.trim());+ }+const response = await axios.post(tokenURL, params.toString(), {headers: { 'Content-Type': 'application/x-www-form-urlencoded' },});@@ -826,7 +837,9 @@ async function getClientCredentialToken({ clientID, clientSecret, tokenURL }) {params: { expires_in },};} catch (error) {- throw new Error(`Failed to get token: ${error.response?.statusText || error.message}`);+ const providerErrorMsg = JSON.stringify(error?.response?.data);+ console.error('Error in getClientCredentialToken:', providerErrorMsg, error?.message);+ throw new Error(`Failed to get token: ${providerErrorMsg || error.response?.statusText || error.message}`);}}router.post('/client_credentials', includeTeamDetails, async (req, res) => {diff --git a/packages/app/src/builder-ui/components/APICall.class.ts b/packages/app/src/builder-ui/components/APICall.class.tsindex 9b85d30a..fb2c88d3 100644--- a/packages/app/src/builder-ui/components/APICall.class.ts+++ b/packages/app/src/builder-ui/components/APICall.class.ts@@ -508,12 +508,12 @@ export class APICall extends Component {OAuthServicesRegistry.isClientCredentialsService(selectedValue);let fieldsToUse = isOAuth2 ? [...oauth2Fields] : oauth1Fields; // Use a copy of oauth2Fields to prevent modifying the original arrayif (OAuthServicesRegistry.isClientCredentialsService(selectedValue)) {- // if value is 'OAuth2 Client Credentials',Remove 'authorizationURL', 'oauth2CallbackURL', and 'scope' from fieldsToUse, also hide oauth1Fields+ // if value is 'OAuth2 Client Credentials',Remove 'authorizationURL' and 'oauth2CallbackURL' from fieldsToUse, but keep 'scope'fieldsToUse = fieldsToUse.filter(- (field) => !['authorizationURL', 'oauth2CallbackURL', 'scope'].includes(field),+ (field) => !['authorizationURL', 'oauth2CallbackURL'].includes(field),);oauth2Fields = fieldsToUse;- oauth1Fields = ['authorizationURL', 'oauth2CallbackURL', 'scope', ...oauth1Fields];+ oauth1Fields = ['authorizationURL', 'oauth2CallbackURL', ...oauth1Fields];}const isNewSelection = this.data.oauthService !== selectedValue; // Determine if it's a new selectionif (isNewSelection) {@@ -1852,10 +1852,15 @@ export class APICall extends Component {newOauthInfo.tokenURL = formData.tokenURL || '';newOauthInfo.clientID = formData.clientID || '';newOauthInfo.clientSecret = formData.clientSecret || '';+ // Scope is supported for both OAuth2 and Client Credentials+ newOauthInfo.scope = formData.scope || '';+ // Audience is typically used for Client Credentials (e.g., Auth0)+ if (type === 'oauth2_client_credentials') {+ newOauthInfo.audience = formData.audience || '';+ }if (type === 'oauth2') {// Only for full OAuth2newOauthInfo.authorizationURL = formData.authorizationURL || '';- newOauthInfo.scope = formData.scope || '';}} else if (type === 'oauth') {newOauthInfo.requestTokenURL = formData.requestTokenURL || '';@@ -2248,10 +2253,16 @@ export class APICall extends Component {// Toggle specific fields within OAuth2const scopeGroup = dialog.querySelector('[data-oauth-field="scope"]');+ const audienceGroup = dialog.querySelector('[data-oauth-field="audience"]');const authURLGroup = dialog.querySelector('#authorizationURL')?.closest('.form-group');+ // Show scope for both OAuth2 and Client Credentials, but hide auth URL for Client Credentialsif (scopeGroup) {- scopeGroup.classList.toggle('hidden', isClientCreds || !isOAuth2);+ scopeGroup.classList.toggle('hidden', !isOAuth2 && !isClientCreds);+ }+ // Show audience only for Client Credentials+ if (audienceGroup) {+ audienceGroup.classList.toggle('hidden', !isClientCreds);}if (authURLGroup) {authURLGroup.classList.toggle('hidden', isClientCreds || !isOAuth2);diff --git a/packages/app/src/builder-ui/helpers/oauth/oauth-modal.helper.ts b/packages/app/src/builder-ui/helpers/oauth/oauth-modal.helper.tsindex a32d5cf4..2ab6c8ce 100644--- a/packages/app/src/builder-ui/helpers/oauth/oauth-modal.helper.ts+++ b/packages/app/src/builder-ui/helpers/oauth/oauth-modal.helper.ts@@ -101,6 +101,17 @@ export function generateOAuthModalHTML(<div class="grid grid-cols-4 items-center gap-4 form-group"><label for="clientSecret" class="text-sm font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-70">Client Secret</label><div class="col-span-3"><input type="password" id="clientSecret" name="clientSecret" value="${currentOauthInfo.clientSecret || ''}" class="input bg-white border border-gray-300 text-gray-900 rounded block w-full h-9 px-3 py-2 text-sm outline-none focus:outline-none focus:ring-0 focus:border-b-2 focus:border-b-blue-500" /></div>+ </div>+ <div class="grid grid-cols-4 items-center gap-4 form-group" data-oauth-field="audience">+ <label id="audience-label" for="audience" class="w-fit text-sm font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-70 flex items-center">+ Audience+ <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 ml-2 cursor-help" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">+ <circle cx="12" cy="12" r="10"></circle>+ <path d="M12 16v-4"></path>+ <path d="M12 8h.01"></path>+ </svg>+ </label>+ <div class="col-span-3"><input type="text" id="audience" name="audience" value="${currentOauthInfo.audience || ''}" placeholder="e.g., https://api.example.com or https://your-api.auth0.com" class="input bg-white border border-gray-300 text-gray-900 rounded block w-full h-9 px-3 py-2 text-sm outline-none focus:outline-none focus:ring-0 focus:border-b-2 focus:border-b-blue-500" /></div></div><div class="grid grid-cols-4 items-center gap-4 form-group" data-oauth-field="scope"><label id="scope-label" for="scope" class="w-fit text-sm font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-70 flex items-center">@@ -195,10 +206,16 @@ export function updateOAuthFieldVisibility(// Toggle specific fields within OAuth2const scopeGroup = dialog.querySelector('[data-oauth-field="scope"]');+ const audienceGroup = dialog.querySelector('[data-oauth-field="audience"]');const authURLGroup = dialog.querySelector('#authorizationURL')?.closest('.form-group');+ // Show scope for both OAuth2 and Client Credentials, but hide auth URL for Client Credentialsif (scopeGroup) {- scopeGroup.classList.toggle('hidden', isClientCreds || !isOAuth2);+ scopeGroup.classList.toggle('hidden', !isOAuth2 && !isClientCreds);+ }+ // Show audience only for Client Credentials+ if (audienceGroup) {+ audienceGroup.classList.toggle('hidden', !isClientCreds);}if (authURLGroup) {authURLGroup.classList.toggle('hidden', isClientCreds || !isOAuth2);diff --git a/packages/app/src/builder-ui/helpers/oauth/oauth.service.ts b/packages/app/src/builder-ui/helpers/oauth/oauth.service.tsindex 724d5cc0..c0b6d5ef 100644--- a/packages/app/src/builder-ui/helpers/oauth/oauth.service.ts+++ b/packages/app/src/builder-ui/helpers/oauth/oauth.service.ts@@ -263,10 +263,15 @@ export class OAuthService {oauthInfo.tokenURL = formData.tokenURL || '';oauthInfo.clientID = formData.clientID || '';oauthInfo.clientSecret = formData.clientSecret || '';+ // Scope is supported for both OAuth2 and Client Credentials+ oauthInfo.scope = formData.scope || '';+ // Audience is typically used for Client Credentials (e.g., Auth0)+ if (type === 'oauth2_client_credentials') {+ oauthInfo.audience = formData.audience || '';+ }if (type === 'oauth2') {oauthInfo.authorizationURL = formData.authorizationURL || '';- oauthInfo.scope = formData.scope || '';}} else if (type === 'oauth') {oauthInfo.requestTokenURL = formData.requestTokenURL || '';diff --git a/packages/app/src/builder-ui/helpers/oauth/oauth.types.ts b/packages/app/src/builder-ui/helpers/oauth/oauth.types.tsindex d9d4fc06..1cf96dfd 100644--- a/packages/app/src/builder-ui/helpers/oauth/oauth.types.ts+++ b/packages/app/src/builder-ui/helpers/oauth/oauth.types.ts@@ -15,6 +15,7 @@ export interface OAuthInfo {clientSecret?: string;authorizationURL?: string;scope?: string;+ audience?: string; // Required by some providers like Auth0 for Client Credentialsoauth2CallbackURL?: string;// OAuth1requestTokenURL?: string;diff --git a/packages/app/src/builder-ui/helpers/oauth/ui.helper.ts b/packages/app/src/builder-ui/helpers/oauth/ui.helper.tsindex 7b7f47e3..704ebc6e 100644--- a/packages/app/src/builder-ui/helpers/oauth/ui.helper.ts+++ b/packages/app/src/builder-ui/helpers/oauth/ui.helper.ts@@ -261,9 +261,13 @@ export class UIHelper {oauth2Container?.classList.toggle('hidden', !(isOAuth2 || isClientCreds));const scopeGroup = dialog.querySelector('[data-oauth-field="scope"]');+ const audienceGroup = dialog.querySelector('[data-oauth-field="audience"]');const authURLGroup = dialog.querySelector('#authorizationURL')?.closest('.form-group');- scopeGroup?.classList.toggle('hidden', isClientCreds || !isOAuth2);+ // Show scope for both OAuth2 and Client Credentials, but hide auth URL for Client Credentials+ scopeGroup?.classList.toggle('hidden', !isOAuth2 && !isClientCreds);+ // Show audience only for Client Credentials+ audienceGroup?.classList.toggle('hidden', !isClientCreds);authURLGroup?.classList.toggle('hidden', isClientCreds || !isOAuth2);this.updateCallbackDisplay(@@ -292,6 +296,7 @@ export class UIHelper {{ id: '#clientSecret', value: currentOauthInfo.clientSecret },{ id: '#tokenURL', value: currentOauthInfo.tokenURL },{ id: '#authorizationURL', value: currentOauthInfo.authorizationURL },+ { id: '#audience', value: currentOauthInfo.audience },{ id: '#scope', value: currentOauthInfo.scope },];diff --git a/packages/app/src/react/features/vault/components/create-oauth-connection-modal.tsx b/packages/app/src/react/features/vault/components/create-oauth-connection-modal.tsxindex 5ac4f5d4..0f3c2f22 100644--- a/packages/app/src/react/features/vault/components/create-oauth-connection-modal.tsx+++ b/packages/app/src/react/features/vault/components/create-oauth-connection-modal.tsx@@ -63,6 +63,7 @@ export function CreateOAuthConnectionModal({platform: resolvedOAuthInfo.platform,oauthService: serviceName,scope: resolvedOAuthInfo.scope,+ audience: resolvedOAuthInfo.audience,authorizationURL: resolvedOAuthInfo.authorizationURL,tokenURL: resolvedOAuthInfo.tokenURL,clientID: resolvedOAuthInfo.clientID,@@ -83,6 +84,7 @@ export function CreateOAuthConnectionModal({platform: editConnection.oauth_info.platform,oauthService: serviceName,scope: editConnection.oauth_info.scope,+ audience: editConnection.oauth_info.audience,authorizationURL: editConnection.oauth_info.authorizationURL,tokenURL: editConnection.oauth_info.tokenURL,clientID: editConnection.oauth_info.clientID,@@ -190,10 +192,9 @@ export function CreateOAuthConnectionModal({const showScopeField = useMemo(() =>!OAuthServicesRegistry.isOAuth1Service(selectedService) &&- !OAuthServicesRegistry.isClientCredentialsService(selectedService) &&selectedService !== 'None',[selectedService],- ); // Scope not typically used in 1.0a or Client Credentials+ ); // Scope is supported for OAuth2 and Client Credentials, but not for OAuth1.0a// Pre-fill URLs for known providers using centralized configurationuseEffect(() => {diff --git a/packages/app/src/react/features/vault/components/oauth-form-fields.tsx b/packages/app/src/react/features/vault/components/oauth-form-fields.tsxindex 292c4840..1d09bdee 100644--- a/packages/app/src/react/features/vault/components/oauth-form-fields.tsx+++ b/packages/app/src/react/features/vault/components/oauth-form-fields.tsx@@ -239,6 +239,32 @@ export function OAuthFormFields({/></div></div>+ {showClientCredentialsFields && (+ <div className="grid grid-cols-4 items-center gap-4">+ <div className="flex items-center">+ <Label htmlFor="audience">Audience</Label>+ <Tooltip>+ <TooltipTrigger asChild>+ <Info className="w-4 h-4 cursor-help ml-2" />+ </TooltipTrigger>+ <TooltipContent className="w-64 text-center" side="right">+ <p>API identifier (required by Auth0 and some providers). Usually the API URL or identifier.</p>+ </TooltipContent>+ </Tooltip>+ </div>+ <div className="col-span-3">+ <Input+ id="audience"+ name="audience"+ value={formData.audience || ''}+ onChange={handleChange}+ placeholder="e.g., https://api.example.com or https://your-api.auth0.com"+ disabled={isDisabled}+ fullWidth+ />+ </div>+ </div>+ )}{showOAuth2Fields && oauth2CallbackURL && (<div className="grid grid-cols-4 items-center gap-4"><Label>Callback URL</Label>diff --git a/packages/app/src/react/features/vault/components/use-vault-oauth.ts b/packages/app/src/react/features/vault/components/use-vault-oauth.tsindex 8af8b1a0..d87a07c9 100644--- a/packages/app/src/react/features/vault/components/use-vault-oauth.ts+++ b/packages/app/src/react/features/vault/components/use-vault-oauth.ts@@ -168,6 +168,7 @@ const fetchOAuthConnections = async (): Promise<OAuthSettings> => {'service','platform','scope',+ 'audience','authorizationURL','tokenURL','clientID',@@ -351,7 +352,7 @@ const getRelevantOAuthInfoFields = (// oauth2CallbackURL is derived, not directly from form data passed here} else if (type === 'oauth2_client_credentials') {// Client Credentials specific config fields from the form- ['tokenURL', 'clientID', 'clientSecret'].forEach((key) => {+ ['tokenURL', 'clientID', 'clientSecret', 'audience'].forEach((key) => {if (formData[key] !== undefined) relevantInfo[key] = formData[key];});} else if (type === 'oauth') {@@ -491,10 +492,17 @@ export function useUpdateOAuthConnection() {updatedOAuthInfo.scope = updatedFields.scope;}}- // For client credentials, ensure auth URL and scope are removed+ // For client credentials, ensure auth URL is removed but keep scope and audienceif (finalType === 'oauth2_client_credentials') {delete updatedOAuthInfo.authorizationURL;- delete updatedOAuthInfo.scope;+ // Scope is supported for Client Credentials+ if ('scope' in updatedFields) {+ updatedOAuthInfo.scope = updatedFields.scope;+ }+ // Audience is supported for Client Credentials (e.g., Auth0)+ if ('audience' in updatedFields) {+ updatedOAuthInfo.audience = updatedFields.audience;+ }}} else if (finalType === 'oauth') {// Update OAuth1 fields only if explicitly provided in updatedFieldsdiff --git a/packages/app/src/react/features/vault/types/oauth-connection.ts b/packages/app/src/react/features/vault/types/oauth-connection.tsindex 6a346a29..27aaf97f 100644--- a/packages/app/src/react/features/vault/types/oauth-connection.ts+++ b/packages/app/src/react/features/vault/types/oauth-connection.ts@@ -8,6 +8,7 @@ export interface OAuthInfo {name: string; // User-defined friendly name for the connectionplatform: string; // *** ADDED: The platform name (e.g., 'Google Mail', 'HubSpot') ***scope?: string;+ audience?: string; // Required by some providers like Auth0 for Client CredentialsauthorizationURL?: string;tokenURL?: string;clientID?: string;@@ -80,6 +81,7 @@ export interface OAuthConnectionFormData {platform: string; // *** ADDED: Platform field for the form ***oauthService: string; // Maps to oauth_info.service, e.g., 'Google', 'Custom OAuth2.0'scope?: string;+ audience?: string; // Required by some providers like Auth0 for Client CredentialsauthorizationURL?: string;tokenURL?: string;clientID?: string;diff --git a/packages/app/src/shared/helpers/oauth/oauth-api.helper.ts b/packages/app/src/shared/helpers/oauth/oauth-api.helper.tsindex cbfe6d47..b89a7c8f 100644--- a/packages/app/src/shared/helpers/oauth/oauth-api.helper.ts+++ b/packages/app/src/shared/helpers/oauth/oauth-api.helper.ts@@ -28,6 +28,7 @@ export function getConnectionOauthInfo(connection: any, connectionId?: string):'service','platform','scope',+ 'audience','authorizationURL','tokenURL','clientID',@@ -66,6 +67,7 @@ export function getConnectionOauthInfo(connection: any, connectionId?: string):'service','platform','scope',+ 'audience','authorizationURL','tokenURL','clientID',