Skip to content

Store ticketing OAuth state in Redis#3

Merged
zebbern merged 1 commit into
mainfrom
codex/ticketing-oauth-redis-state
Jun 20, 2026
Merged

Store ticketing OAuth state in Redis#3
zebbern merged 1 commit into
mainfrom
codex/ticketing-oauth-redis-state

Conversation

@zebbern

@zebbern zebbern commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • store Jira OAuth state in Redis with a 5 minute TTL for multi-instance callback handling
  • keep the in-memory OAuth state cache as a local fallback when Redis is unavailable
  • add service coverage for consuming OAuth state across separate service instances

Verification

  • bun --cwd backend test src/ticketing/tests/ticketing.service.spec.ts
  • bun run typecheck
  • bun run lint
  • bun test backend
  • git push pre-push hook ran the full test command successfully

Signed-off-by: zebbern <185730623+zebbern@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 20, 2026 13:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 into TicketingModule.
  • Update TicketingService to 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);
@zebbern zebbern merged commit 28f3f56 into main Jun 20, 2026
6 checks passed
@zebbern zebbern deleted the codex/ticketing-oauth-redis-state branch June 20, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants