Skip to content

Add comprehensive plan for Gmail OAuth with architect-approved decisions, WebFlux-compatible reactive security, Liquibase-managed database schema, JdbcDatabaseModel for account lookups, and email uniqueness enforcement in crypto trading test app#199

Merged
jwijgerd merged 15 commits into
mainfrom
copilot/add-gmail-signup-feature
Dec 6, 2025

Conversation

Copilot AI commented Dec 6, 2025

Copy link
Copy Markdown
Contributor
  • Understand the crypto trading application structure and current account management
  • Analyze existing Spring Boot configuration and dependencies
  • Research Spring Security OAuth2 Client compatibility with Spring Boot 4.0 and WebFlux
  • Design comprehensive OAuth authentication architecture
  • Create detailed implementation plan with 6 phases
  • Document security considerations and GDPR compliance
  • Identify extensibility requirements for multiple OAuth providers
  • Store plan in plans/gmail-oauth-authentication.md (moved from framework-developer/plans)
  • Add detailed Google Cloud Platform OAuth setup instructions with official references
  • Update command versioning to CreateAccountCommandV2 (v2) with OAuth fields
  • Add comprehensive JWT-based API security architecture
  • Document JWT token flow for Commands and Queries services
  • Add JWT authentication filter and token provider implementation details
  • Update all endpoints with JWT authentication requirements
  • Add token refresh mechanism documentation
  • Include official Google OAuth and OpenID Connect reference links
  • Update to use Nimbus JOSE+JWT library (included in spring-security-oauth2-jose)
  • Implement GCP Service Account for JWT signing with RS256
  • Add JWKS endpoint for public key distribution and validation
  • Convert client usage examples from JavaScript to Java (WebClient and RestTemplate)
  • Add GCP Service Account setup instructions and JWKS configuration
  • Update security considerations for GCP Service Account key management
  • Create separate Auth module for OAuth and JWT generation (isolated from Commands/Queries)
  • Version all auth APIs with /v1/auth/ prefix for future extensibility
  • Update Commands and Queries services to only validate JWTs (no auth endpoints)
  • Simplify Terraform section to focus on Service Account and key resources only
  • Add Terraform example for storing Service Account key in Secret Manager
  • Add Java code using Google Cloud Secret Manager API to retrieve key in Auth service
  • Add comprehensive GKE Workload Identity Federation section with Terraform and K8s examples
  • Add Spring Boot Application class (AuthServiceApplication) to Auth module structure
  • Clarify JwtTokenProvider resides in Auth service (not Commands)
  • Clarify JWT validation applies to both Commands and Queries services
  • Add detailed OAuth2UserService implementation showing AkcesClient usage to send commands
  • Add AccountQueryModel implementation in Auth service for checking account existence
  • Add complete code examples for AkcesClient integration and query model pattern
  • Update JwtTokenProvider to receive ServiceAccountCredentials bean (retrieved via SecretManager) instead of key JSON string
  • Remove port numbers from service architecture diagrams for cleaner presentation
  • Document all architect decisions on open questions (UUID strategy, multi-provider restrictions, JWT-based auth, event sourcing query models)
  • Add email uniqueness enforcement implementation to prevent multi-provider conflicts
  • Move plan document to top-level plans folder for better organization
  • Update all security configurations for WebFlux compatibility (SecurityWebFilterChain, ServerHttpSecurity, WebFilter, reactive types)
  • Replace OncePerRequestFilter with WebFilter for JWT authentication
  • Update Phase 2 implementation steps to explicitly mention WebFlux requirements
  • Add WebFlux compatibility warning in Architecture Overview section
  • Clarify Terraform section is for reference only (managed in separate infrastructure repo)
  • Update Phase 1 to assume GCP Service Account already exists from Terraform provisioning
  • Replace Kafka-based QueryModel with JdbcDatabaseModel for account lookups (architect requirement)
  • Add AccountDatabaseModel implementation extending JdbcDatabaseModel
  • Add AccountQueryService with JDBC queries (findByOAuthProvider, findByEmail)
  • Add database schema for accounts table with indexes
  • Update CustomOAuth2UserService to use database queries instead of in-memory cache
  • Update Phase 3 to include database model setup steps
  • Add testing requirements for database model and query service
  • Replace raw SQL schema with Liquibase changelog (db.changelog-master.xml)
  • Add Liquibase dependency and configuration to Auth module
  • Add datasource and Liquibase configuration to application.yml example
  • Update Phase 3 implementation steps to mention Liquibase setup
  • Fix JWT configuration section labels - JWT generation in Auth service, validation in Commands/Queries services
  • Get architect approval for the plan ✅
  • Execute implementation phases after approval
Original prompt

For the cryptotrading test application I want users to be able to sign up with their existing email accounts. Initally I want to only support GMAIL but the solution should be easily extended to other providers. I want to use Sprng Boot and Spring Security. Create a plan to add the ability for users to sign up to the crypto trading test app using their GMAIL account. Store it in the plans folder

Custom agent used: framework-developer
A Framework Developer for the Akces (Apacke Kafka CQRS Event Sourcing) Framework


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ng app

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Gmail account sign-up for users Add comprehensive plan for Gmail OAuth authentication in crypto trading test app Dec 6, 2025
Copilot AI requested a review from jwijgerd December 6, 2025 13:02
@jwijgerd
jwijgerd marked this pull request as ready for review December 6, 2025 13:09
@jwijgerd

jwijgerd commented Dec 6, 2025

Copy link
Copy Markdown
Contributor

@copilot you are going into the right direction, can you add the following:

  1. can you explain in the plan what needs to be done on the Google / GCP side to get the GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET values.
  2. The Commands should be versioned as as well so create a v2 of the CreateCommand similar to the event
  3. I am missing how the read and write endpoints will be secured with the resulting JWT

…s, and comprehensive references

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>

Copilot AI commented Dec 6, 2025

Copy link
Copy Markdown
Contributor Author

@copilot you are going into the right direction, can you add the following:

  1. can you explain in the plan what needs to be done on the Google / GCP side to get the GOOGLE_CLIENT_ID and GOOGLE_CLIE...

Updated the plan with all requested changes (commit 3b79c47):

  1. Google OAuth Setup: Added complete step-by-step GCP Console instructions including consent screen configuration, credential creation, and test user management. Included official Google documentation links throughout.

  2. Command Versioning: Changed to CreateAccountCommandV2 (version 2) with optional OAuth fields, matching the event versioning approach. Includes upcasting handler from v1 to v2.

  3. JWT API Security: Added comprehensive JWT-based authentication architecture:

    • JWT token generation in OAuth2LoginSuccessHandler (access: 15min, refresh: 7 days)
    • JwtAuthenticationFilter for token validation on all protected endpoints
    • Token refresh endpoint for seamless re-authentication
    • All Commands and Queries service endpoints secured with @PreAuthorize and JWT validation
    • Example client usage showing Bearer token in Authorization header

The plan now includes 30+ official reference links from Google, Spring Security, and OAuth/OIDC standards.

Copilot AI changed the title Add comprehensive plan for Gmail OAuth authentication in crypto trading test app Add comprehensive plan for Gmail OAuth authentication with JWT security in crypto trading test app Dec 6, 2025
@jwijgerd

jwijgerd commented Dec 6, 2025

Copy link
Copy Markdown
Contributor

@copilot nice additions, I have a couple of more questions and remarks:

  1. I want to use the Nimbus JWT Java library for JWT support, Spring (Boot) Security should support this as well
  2. I want to use a GCP Service Account with a service account key to sign JWTs. The service account automatically exposes a JWKS which can be used on the client side to validate the tokens. find out of Spring Security has support for this

…a client examples

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>

Copilot AI commented Dec 6, 2025

Copy link
Copy Markdown
Contributor Author

@copilot nice additions, I have a couple of more questions and remarks:

  1. I want to use the Nimbus JWT Java library for JWT support, Spring (Boot) Security should support this as well
    ...

Updated the plan with all requested changes (commit 6bbac91):

  1. Nimbus JWT Library: Changed from JJWT to Nimbus JOSE+JWT, which Spring Security uses natively via spring-security-oauth2-jose. No separate JWT library dependencies needed - Nimbus is integrated and handles all JWT operations through NimbusJwtDecoder and NimbusJwtEncoder.

  2. GCP Service Account with JWKS:

    • Commands service uses GCP Service Account private key to sign JWTs with RS256
    • Google automatically exposes public keys at JWKS endpoint: https://www.googleapis.com/service_accounts/v1/jwk/{service-account-email}
    • Queries service validates JWTs using JWKS URI - Spring Security + Nimbus fetch and cache public keys automatically
    • Benefits: No shared secret management, automatic key rotation, zero downtime, industry standard RS256
  3. Java Client Examples: Replaced JavaScript with Java examples using both WebClient (reactive) and RestTemplate (synchronous), showing token storage, authenticated API calls, and automatic token refresh.

Added complete GCP Service Account setup instructions, JWKS configuration for both services, and 15+ new references for GCP, Nimbus, and JWKS/JWT RFCs.

Copilot AI changed the title Add comprehensive plan for Gmail OAuth authentication with JWT security in crypto trading test app Add comprehensive plan for Gmail OAuth authentication with Nimbus JWT and GCP Service Account in crypto trading test app Dec 6, 2025
@jwijgerd

jwijgerd commented Dec 6, 2025

Copy link
Copy Markdown
Contributor

@copilot ok great, now for more security I don't want to deploy the AuthController as part of the commands module but I want you to create a separate module for it. let's call that the auth module. The web layers of the commands and queries module should only validate the JWT.

Also, please version the auth urls with v1

We are using terraform to configure the gcp resources (in another repo). can you provide some examples? If there is no terraform support than please explicitely state that.

…rraform examples

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>

Copilot AI commented Dec 6, 2025

Copy link
Copy Markdown
Contributor Author

@copilot ok great, now for more security I don't want to deploy the AuthController as part of the commands module but I want you to create a separate module for it. let's call that the auth module. Th...

Updated the plan with all requested changes (commit 059b62b):

  1. Separate Auth Module: Created dedicated auth module (test-apps/crypto-trading/auth) for OAuth and JWT generation, completely isolated from Commands and Queries services. Auth service deploys independently on separate port.

  2. Commands/Queries Services: Now only validate JWTs via Spring Security OAuth2 Resource Server with JWKS URI - all authentication logic removed. These services are pure resource servers.

  3. Versioned Auth APIs: All auth endpoints now use /v1/auth/ prefix:

    • GET /v1/auth/login - OAuth login
    • GET /v1/auth/callback - OAuth callback
    • POST /v1/auth/refresh - Token refresh
    • GET /v1/auth/user - User profile
    • POST /v1/auth/logout - Logout
  4. Terraform Examples: Added comprehensive section with 9 detailed examples:

    • Service Account creation and key generation
    • IAM bindings and permissions
    • Secret Manager integration (recommended)
    • Kubernetes secret provisioning
    • Security best practices and key rotation
    • Workload Identity integration
    • Important note: OAuth clients cannot be created via Terraform - must be done manually via GCP Console (limitation documented with workarounds)

Copilot AI changed the title Add comprehensive plan for Gmail OAuth authentication with Nimbus JWT and GCP Service Account in crypto trading test app Add comprehensive plan for Gmail OAuth with separate Auth service, versioned APIs, and Terraform IaC in crypto trading test app Dec 6, 2025
@jwijgerd

jwijgerd commented Dec 6, 2025

Copy link
Copy Markdown
Contributor

@copilot you went a bit overboard with the terraform section. Just keep the specific resources needed for the service accounts and key(s) and remove all the rest. I want to use Secret Manager to store the service account key. Add a terraform example for that. Inside the auth module use the Google Cloud Secret Manager API java library to retrieve the secret key data used to sign the JWT. We also use Workload Identity Federation in GKE, add a section on that

… Workload Identity Federation

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
…e servlet-based filters and security with reactive equivalents

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
Copilot AI changed the title Add comprehensive plan for Gmail OAuth with architect-approved decisions, separate Auth service, and email uniqueness enforcement in crypto trading test app Add comprehensive plan for Gmail OAuth with architect-approved decisions, WebFlux-compatible reactive security, and email uniqueness enforcement in crypto trading test app Dec 6, 2025

@jwijgerd jwijgerd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot implement comment and in generatl mention that the terraform code is not part of this plan / implemenation but is just here for reference

Comment thread plans/gmail-oauth-authentication.md Outdated
- `spring-security-oauth2-jose` (includes Nimbus JOSE+JWT library)
- `google-auth-library-oauth2-http` (for GCP Service Account JWT signing)

2. **Create GCP Service Account**:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The service account is created in another (terraform) repo and should be a given here. Please change to "ensure GCP serivce acccount is created"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed to "Ensure GCP Service Account is Created" in commit 0108b91. The step now assumes the service account has been provisioned via Terraform in the separate infrastructure repository and focuses on verification and noting required configuration details.

…sume GCP Service Account exists

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>

Copilot AI commented Dec 6, 2025

Copy link
Copy Markdown
Contributor Author

@copilot implement comment and in generatl mention that the terraform code is not part of this plan / implemenation but is just here for reference

Updated (commit 0108b91):

Added prominent disclaimer at the start of the Terraform section stating it's for reference only and managed in a separate infrastructure repository. Also updated Phase 1 step from "Create GCP Service Account" to "Ensure GCP Service Account is Created", clarifying that resources should already exist from Terraform provisioning.

Copilot AI requested a review from jwijgerd December 6, 2025 15:25

@jwijgerd jwijgerd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot implement the comment

Comment thread plans/gmail-oauth-authentication.md Outdated

public Optional<AccountQueryModelState> findByOAuthProvider(String provider, String providerId) {
// Query local cache maintained by AccountQueryModel
return accountQueryModel.findByOAuthProvider(provider, providerId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is not possible using the kafka based QueryModel, this implemenation will have to be based on the JdbcDatabaseModel and then queries like this can be implemented. Please update the plan accordingly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated (commit 0e09f8b):

Replaced Kafka-based QueryModel with JdbcDatabaseModel approach:

  • AccountDatabaseModel extends JdbcDatabaseModel and handles AccountCreatedEventV2 events to persist to database
  • AccountQueryService uses JdbcTemplate for queries: findByOAuthProvider() and findByEmail()
  • Added database schema with accounts table and indexes on email and (oauth_provider, oauth_provider_id)
  • Updated CustomOAuth2UserService to use database queries instead of in-memory cache
  • Updated Phase 3 implementation steps to include database model setup
  • Updated module structure and documentation throughout plan

…kups in Auth service

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
Copilot AI changed the title Add comprehensive plan for Gmail OAuth with architect-approved decisions, WebFlux-compatible reactive security, and email uniqueness enforcement in crypto trading test app Add comprehensive plan for Gmail OAuth with architect-approved decisions, WebFlux-compatible reactive security, JdbcDatabaseModel for account lookups, and email uniqueness enforcement in crypto trading test app Dec 6, 2025
Copilot AI requested a review from jwijgerd December 6, 2025 15:44
Comment thread plans/gmail-oauth-authentication.md Outdated
}
```

**Database Schema (create in Auth service resources):**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We use liquibase for this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to use Liquibase for database schema management (commit 4ecc5a5). Replaced raw SQL with Liquibase changelog format including createTable, addUniqueConstraint, and createIndex tags. Added liquibase-core dependency, datasource configuration, and Liquibase changelog path to Auth service application.yml.

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
Copilot AI changed the title Add comprehensive plan for Gmail OAuth with architect-approved decisions, WebFlux-compatible reactive security, JdbcDatabaseModel for account lookups, and email uniqueness enforcement in crypto trading test app Add comprehensive plan for Gmail OAuth with architect-approved decisions, WebFlux-compatible reactive security, Liquibase-managed database schema, JdbcDatabaseModel for account lookups, and email uniqueness enforcement in crypto trading test app Dec 6, 2025
Copilot AI requested a review from jwijgerd December 6, 2025 15:51
Comment thread plans/gmail-oauth-authentication.md Outdated
- No need to manually manage public key distribution
- Key rotation is handled automatically by Google

4. **Configuration (Commands Service - JWT Generation):**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This configuration should be in the Auth service

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated (commit 751e61d) - Changed configuration section from "Commands Service - JWT Generation" to "Auth Service - JWT Generation", and updated validation section to specify both "Commands and Queries Services - JWT Validation".

…idation in Commands/Queries services

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
@jwijgerd
jwijgerd merged commit a8b8bf9 into main Dec 6, 2025
1 check passed
@jwijgerd
jwijgerd deleted the copilot/add-gmail-signup-feature branch December 6, 2025 15:56
Copilot AI requested a review from jwijgerd December 6, 2025 15:57
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