SSO token caching and retrieval in CachePool (#4931)

* feat: Implement SSO token caching and retrieval in CachePool

This implementation improves the authentication process by securely caching SSO tokens and managing user sessions.

* Removed commented code

* feat: add deleteSSOTokenCache in ssoSuccess

---------

Co-authored-by: Ong Chung Yau <33013947+chungyau97@users.noreply.github.com>
Co-authored-by: chungyau97 <chungyau97@gmail.com>
This commit is contained in:
Vinod Kiran
2025-07-25 00:44:46 +05:30
committed by GitHub
parent 00342bde88
commit d272683a98
6 changed files with 96 additions and 16 deletions
+41
View File
@@ -9,6 +9,7 @@ export class CachePool {
activeLLMCache: IActiveCache = {}
activeEmbeddingCache: IActiveCache = {}
activeMCPCache: { [key: string]: any } = {}
ssoTokenCache: { [key: string]: any } = {}
constructor() {
if (process.env.MODE === MODE.QUEUE) {
@@ -42,6 +43,46 @@ export class CachePool {
}
}
/**
* Add to the sso token cache pool
* @param {string} ssoToken
* @param {any} value
*/
async addSSOTokenCache(ssoToken: string, value: any) {
if (process.env.MODE === MODE.QUEUE) {
if (this.redisClient) {
const serializedValue = JSON.stringify(value)
await this.redisClient.set(`ssoTokenCache:${ssoToken}`, serializedValue, 'EX', 120)
}
} else {
this.ssoTokenCache[ssoToken] = value
}
}
async getSSOTokenCache(ssoToken: string): Promise<any | undefined> {
if (process.env.MODE === MODE.QUEUE) {
if (this.redisClient) {
const serializedValue = await this.redisClient.get(`ssoTokenCache:${ssoToken}`)
if (serializedValue) {
return JSON.parse(serializedValue)
}
}
} else {
return this.ssoTokenCache[ssoToken]
}
return undefined
}
async deleteSSOTokenCache(ssoToken: string) {
if (process.env.MODE === MODE.QUEUE) {
if (this.redisClient) {
await this.redisClient.del(`ssoTokenCache:${ssoToken}`)
}
} else {
delete this.ssoTokenCache[ssoToken]
}
}
/**
* Add to the llm cache pool
* @param {string} chatflowid