Skip to content

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.

remove oauth info stored in sessions

ahmedcoder01d83d6a621e42
diff --git a/packages/app/src/backend/middlewares/oauthStrategy.mw.ts b/packages/app/src/backend/middlewares/oauthStrategy.mw.ts
index 5f5baeb1..bc06a021 100644
--- a/packages/app/src/backend/middlewares/oauthStrategy.mw.ts
+++ b/packages/app/src/backend/middlewares/oauthStrategy.mw.ts
@@ -5,12 +5,10 @@ import { strategyConfig } from '../routes/oauth/helper/strategyConfig';
export const oauthStrategyInitialization = async (req, res, next) => {
const { service, scope } = req.body;
- //console.log(service,callbackURL)
if (!service) {
return res.status(400).send({ error: 'Service is required.' });
}
try {
- // Determine if the strategy is OAuth1.0 or OAuth2.0 based on the service using centralized configuration
const isOAuth2 = OAuthServicesRegistry.isOAuth2Service(service);
const isOAuth1 = OAuthServicesRegistry.isOAuth1Service(service);
const strategy = isOAuth2 ? 'oauth2' : 'oauth';
@@ -18,82 +16,29 @@ export const oauthStrategyInitialization = async (req, res, next) => {
req.session.scopes = scope ?? '';
req.session.oauth_info = req.body;
req.session.team = req._team;
- // Log for debugging
if (!isOAuth2 && !isOAuth1) {
return res.status(400).send({ error: 'Invalid or unsupported service.' });
}
- // Select the appropriate strategy and configuration based on the service
let strategyDetails = isOAuth2 ? strategyConfig['oauth2'] : strategyConfig['oauth1'];
let { Strategy, config: defaultConfig, processStrategy } = strategyDetails;
- // Prepare the configuration
- let config: any = { ...defaultConfig }; // Spread operator for shallow clone
+ let config: any = { ...defaultConfig };
- // Use session-stored configuration instead of URL parameters
- if (isOAuth2 && req.session.oauth2Config) {
- const oauth2Config = req.session.oauth2Config;
+ // Always resolve template variables from the current request body
+ const updatedReqBody = await replaceTemplateVariablesOptimized(req).catch((error) => {
+ console.log('Template processing error:', error);
+ return req.body;
+ });
- // Handle template variables in session-stored config
- const configToProcess = { ...oauth2Config };
- const templateReq = Object.create(req, {
- body: { value: configToProcess, writable: true, enumerable: true },
- });
-
- const processedConfig = await replaceTemplateVariablesOptimized(templateReq).catch(
- (error) => {
- console.log('Template processing error for OAuth2:', error);
- return configToProcess;
- },
- );
-
- config.clientID = processedConfig.clientID;
- config.clientSecret = processedConfig.clientSecret; // Safe from session + templates resolved
- config.callbackURL = processedConfig.callbackURL;
- if (processedConfig.authorizationURL)
- config.authorizationURL = processedConfig.authorizationURL;
- if (processedConfig.tokenURL) config.tokenURL = processedConfig.tokenURL;
- } else if (isOAuth1 && req.session.oauth1Config) {
- const oauth1Config = req.session.oauth1Config;
-
- // Handle template variables in session-stored config
- const configToProcess = { ...oauth1Config };
- const templateReq = Object.create(req, {
- body: { value: configToProcess, writable: true, enumerable: true },
- });
-
- //TODO : do we really need to handle template variables for oauth
- const processedConfig = await replaceTemplateVariablesOptimized(templateReq).catch(
- (error) => {
- console.log('Template processing error for OAuth1:', error);
- return configToProcess;
- },
- );
-
- config.consumerKey = processedConfig.consumerKey;
- config.consumerSecret = processedConfig.consumerSecret; // Safe from session + templates resolved
- config.callbackURL = processedConfig.callbackURL;
- if (processedConfig.requestTokenURL) config.requestTokenURL = processedConfig.requestTokenURL;
- if (processedConfig.accessTokenURL) config.accessTokenURL = processedConfig.accessTokenURL;
- if (processedConfig.userAuthorizationURL)
- config.userAuthorizationURL = processedConfig.userAuthorizationURL;
- } else {
- // Fallback to legacy URL parameter method (for backward compatibility)
- //TODO : do we really need to handle template variables for oauth
- const updatedReqBody = await replaceTemplateVariablesOptimized(req).catch((error) => {
- console.log('error', error);
- return { error };
- });
-
- Object.entries(updatedReqBody).forEach(([key, value]) => {
- if (key === 'oauth1CallbackURL' || key === 'oauth2CallbackURL') {
- config['callbackURL'] = value;
- } else if (key in config) {
- config[key] = value;
- }
- });
- }
+ Object.entries(updatedReqBody).forEach(([key, value]) => {
+ if (key === 'oauth1CallbackURL' || key === 'oauth2CallbackURL') {
+ config['callbackURL'] = value;
+ } else if (key in config) {
+ config[key] = value;
+ }
+ });
// Derive callback URL when missing
if (!config['callbackURL']) {
@@ -101,9 +46,9 @@ export const oauthStrategyInitialization = async (req, res, next) => {
const origin = req.headers?.origin || `${req.protocol}://${req.get('host')}`;
const internalService = String(service).toLowerCase();
- const isOAuth2 = OAuthServicesRegistry.isOAuth2Service(internalService);
+ const isOAuth2Check = OAuthServicesRegistry.isOAuth2Service(internalService);
- const provider = isOAuth2
+ const provider = isOAuth2Check
? internalService === 'oauth2'
? 'oauth2'
: internalService
diff --git a/packages/app/src/backend/routes/oauth/router.ts b/packages/app/src/backend/routes/oauth/router.ts
index 4848f9bd..17a8edaa 100644
--- a/packages/app/src/backend/routes/oauth/router.ts
+++ b/packages/app/src/backend/routes/oauth/router.ts
@@ -195,8 +195,6 @@ router.post(
}
if (OAuthServicesRegistry.isOAuth2Service(service) || service === 'oauth2') {
- // OAuth2 flow - Store sensitive data in session, return clean URL
-
// Validate required OAuth2 fields
if (!clientID || !clientSecret) {
return res
@@ -204,26 +202,9 @@ router.post(
.json({ error: 'clientID and clientSecret are required for OAuth2' });
}
- // Store OAuth2 configuration in session (server-side only)
- req.session.oauth2Config = {
- service,
- clientID,
- //TODO: Do we need a stronger protection for this?
- clientSecret, // Safe in session
- authorizationURL,
- tokenURL,
- scope,
- callbackURL: oauth2CallbackURL,
- };
-
- // Return internal URL that will trigger Passport (no secrets exposed)
- // Let Passport handle state management internally
const authUrl = `/oauth/${service}`;
-
return res.json({ authUrl });
} else if (OAuthServicesRegistry.isOAuth1Service(service) || service === 'oauth1') {
- // OAuth1 flow - Store sensitive data in session
-
// Validate required OAuth1 fields
if (!consumerKey || !consumerSecret) {
return res
@@ -231,23 +212,7 @@ router.post(
.json({ error: 'consumerKey and consumerSecret are required for OAuth1' });
}
- // Store OAuth1 configuration in session (server-side only)
- req.session.oauth1Config = {
- service,
- consumerKey,
- //TODO: Do we need a stronger protection for this?
- consumerSecret, //Safe in session
- requestTokenURL,
- accessTokenURL,
- userAuthorizationURL,
- callbackURL: oauth1CallbackURL,
- scope,
- };
-
- // Return internal URL that will trigger Passport (no secrets exposed)
- // Let Passport handle state management internally
const authUrl = `/oauth/${service}`;
-
return res.json({ authUrl });
} else {
// Unsupported service