Skip to content

Migrate OAuth state store from in-memory to Redis#24

Merged
slhmy merged 4 commits into
mainfrom
copilot/update-oauth-state-store-redis
Apr 15, 2026
Merged

Migrate OAuth state store from in-memory to Redis#24
slhmy merged 4 commits into
mainfrom
copilot/update-oauth-state-store-redis

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 15, 2026

  • Update StateStore interface in oauth/state_store.go to accept context.Context and return errors, update in-memory implementation accordingly
  • Create Redis-backed StateStore implementation in cache/redis_oauth_state_store.go
  • Update service.go to instantiate the Redis state store and update all call sites to pass ctx and handle errors
  • Address code review: align default TTL fallback (1 min) with in-memory store, document why ExpiresAt is not populated (Redis TTL handles expiry)
  • Apply gofmt formatting to oauth/state_store.go and cache/redis_oauth_state_store.go
  • Fix Lua script to return nil instead of false for missing keys

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Migrates OAuth state storage from an in-process sync.Map/map implementation to Redis so OAuth flows work correctly in multi-replica deployments and across restarts.

Changes:

  • Updated oauth.StateStore interface to accept context.Context and return errors.
  • Added a Redis-backed OAuth state store with TTL-based expiry and atomic consume semantics.
  • Wired the new Redis state store into Service and updated OAuth call sites to propagate ctx and handle errors.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
internal/infrastructure/oauth/state_store.go Extends the StateStore interface with context + error returns; adapts the in-memory store implementation.
internal/infrastructure/cache/redis_oauth_state_store.go Introduces Redis-backed StateStore using SET with TTL and Lua GET+DEL for atomic consume.
internal/application/identra/service.go Instantiates and uses the Redis OAuth state store (shared Redis client), updating call sites accordingly.

Comment on lines 3 to 7
import (
"sync"
"time"
"context"
"sync"
"time"
)
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

This file isn’t gofmt-formatted (imports and block indentation lost). Please run gofmt on this file so it matches the rest of the Go codebase and avoids noisy diffs/lint failures.

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +11
import (
"context"
"encoding/json"
"errors"
"time"

"github.com/poly-workshop/identra/internal/infrastructure/oauth"
goredis "github.com/redis/go-redis/v9"
)
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

This new file isn’t gofmt-formatted (imports and indentation). Please run gofmt so it matches existing Redis cache implementations (e.g., redis_email_code_store.go) and keeps diffs readable.

Copilot uses AI. Check for mistakes.
Comment thread internal/infrastructure/cache/redis_oauth_state_store.go Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@slhmy
Copy link
Copy Markdown
Contributor

slhmy commented Apr 15, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 15, 2026

@copilot apply changes based on the comments in this thread

Applied in 52c479d: ran gofmt on both oauth/state_store.go and cache/redis_oauth_state_store.go, and the Lua script already returns nil (not false) for missing keys.

Copilot AI requested a review from slhmy April 15, 2026 08:10
@slhmy slhmy merged commit b00d1cd into main Apr 15, 2026
2 checks passed
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.

3 participants