Store ticketing OAuth state in Redis#3
Merged
Conversation
Signed-off-by: zebbern <185730623+zebbern@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR makes Jira ticketing OAuth state multi-instance safe by persisting the OAuth state in Redis with a 5-minute TTL, while retaining the existing in-memory map as a fallback when Redis isn’t configured/usable.
Changes:
- Add a dedicated Redis client token (
TICKETING_OAUTH_REDIS) and wire it intoTicketingModule. - Update
TicketingServiceto store/consume OAuth state via Redis first, then fall back to the in-memory cache. - Add a unit test proving OAuth state can be started on one service instance and consumed on another via Redis.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| backend/src/ticketing/ticketing.service.ts | Switches OAuth state cache to Redis-backed storage with local fallback and updates the flow to be async. |
| backend/src/ticketing/ticketing.module.ts | Provides a dedicated Redis client for ticketing OAuth state via DI token. |
| backend/src/ticketing/tests/ticketing.service.spec.ts | Adds Redis-backed cross-instance OAuth state consumption test and updates existing tests for async flow. |
| backend/src/common/redis/redis.tokens.ts | Adds TICKETING_OAUTH_REDIS DI token. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+521
to
+534
| if (this.oauthStateRedis) { | ||
| try { | ||
| const key = this.oauthStateKey(state); | ||
| const raw = await this.oauthStateRedis.get(key); | ||
| if (raw) { | ||
| await this.oauthStateRedis.del(key); | ||
| const parsed = JSON.parse(raw) as OAuthStateCacheEntry; | ||
| if (parsed.expiresAt < Date.now()) return null; | ||
| return parsed; | ||
| } | ||
| } catch (error) { | ||
| this.logger.warn(`Failed to consume Jira OAuth state from Redis: ${error}`); | ||
| } | ||
| } |
| ); | ||
| return; | ||
| } catch (error) { | ||
| this.logger.warn(`Failed to store Jira OAuth state in Redis: ${error}`); |
| const redis = configService.get<RedisConfig>('redis'); | ||
| const url = redis?.url ?? redis?.terminalUrl; | ||
| if (!url) { | ||
| new Logger('TicketingModule').warn('Redis URL not set; ticketing OAuth state disabled'); |
| new Logger('TicketingModule').warn('Redis URL not set; ticketing OAuth state disabled'); | ||
| return null; | ||
| } | ||
| const client = new Redis(url); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Verification