mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 21:00:58 +03:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user