-
Notifications
You must be signed in to change notification settings - Fork 42
Feat: Added MCD Support #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
tanya732
wants to merge
2
commits into
master
Choose a base branch
from
feat/mcd-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # Copilot Instructions for auth0-java-mvc-common | ||
|
|
||
| ## Overview | ||
|
|
||
| This is an Auth0 SDK for Java Servlet applications that simplifies OAuth2/OpenID Connect authentication flows. The library provides secure cookie-based state/nonce management and handles both Authorization Code and Implicit Grant flows. | ||
|
|
||
| ## Core Architecture | ||
|
|
||
| ### Main Components | ||
|
|
||
| - **`AuthenticationController`**: Primary entry point with Builder pattern for configuration | ||
| - **`RequestProcessor`**: Internal handler for OAuth callbacks and token processing | ||
| - **`AuthorizeUrl`**: Fluent builder for constructing OAuth authorization URLs | ||
| - **Cookie Management**: Custom `AuthCookie`/`TransientCookieStore` for SameSite cookie support | ||
|
|
||
| ### Key Design Patterns | ||
|
|
||
| - **Non-reusable builders**: `AuthenticationController.Builder` throws `IllegalStateException` if `build()` called twice | ||
| - **One-time URL builders**: `AuthorizeUrl` instances cannot be reused (throws on second `build()`) | ||
| - **Fallback authentication storage**: State/nonce stored in both cookies AND session for compatibility | ||
|
|
||
| ## Critical Cookie Handling | ||
|
|
||
| The library implements sophisticated cookie management for browser compatibility: | ||
|
|
||
| ### SameSite Cookie Strategy | ||
|
|
||
| - **Code flow**: Uses `SameSite=Lax` (single cookie) | ||
| - **ID token flows**: Uses `SameSite=None; Secure` with legacy fallback cookie (prefixed with `_`) | ||
| - **Legacy fallback**: Automatically creates fallback cookies for browsers that don't support `SameSite=None` | ||
|
|
||
| ### Cookie Configuration | ||
|
|
||
| ```java | ||
| // Configure cookie behavior | ||
| .withLegacySameSiteCookie(false) // Disable fallback cookies | ||
| .withSecureCookie(true) // Force Secure attribute | ||
| .withCookiePath("/custom") // Set cookie Path attribute | ||
| ``` | ||
|
|
||
| ## Builder Pattern Usage | ||
|
|
||
| ### Standard Authentication Controller Setup | ||
|
|
||
| ```java | ||
| AuthenticationController controller = AuthenticationController.newBuilder(domain, clientId, clientSecret) | ||
| .withJwkProvider(jwkProvider) // Required for RS256 | ||
| .withResponseType("code") // Default: "code" | ||
| .withClockSkew(120) // Default: 60 seconds | ||
| .withOrganization("org_id") // For organization login | ||
| .build(); | ||
| ``` | ||
|
|
||
| ### URL Building (Modern Pattern) | ||
|
|
||
| ```java | ||
| // CORRECT: Use request + response for cookie storage | ||
| String url = controller.buildAuthorizeUrl(request, response, redirectUri) | ||
| .withState("custom-state") | ||
| .withAudience("https://api.example.com") | ||
| .withParameter("custom", "value") | ||
| .build(); | ||
| ``` | ||
|
|
||
| ## Response Type Behavior | ||
|
|
||
| - **`code`**: Authorization Code flow, uses `SameSite=Lax` cookies | ||
| - **`id_token`** or **`token`**: Implicit Grant, requires `SameSite=None; Secure` + fallback cookies | ||
| - **Mixed**: `id_token code` combinations follow implicit grant cookie rules | ||
|
|
||
| ## Testing Patterns | ||
|
|
||
| ### Mock Setup | ||
|
|
||
| ```java | ||
| // Standard test setup pattern | ||
| @Mock private AuthAPI client; | ||
| @Mock private IdTokenVerifier.Options verificationOptions; | ||
| @Captor private ArgumentCaptor<SignatureVerifier> signatureVerifierCaptor; | ||
|
|
||
| AuthenticationController.Builder builderSpy = spy(AuthenticationController.newBuilder(...)); | ||
| doReturn(client).when(builderSpy).createAPIClient(...); | ||
| ``` | ||
|
|
||
| ### Cookie Assertions | ||
|
|
||
| ```java | ||
| // Verify cookie headers in tests | ||
| List<String> headers = response.getHeaders("Set-Cookie"); | ||
| assertThat(headers, hasItem("com.auth0.state=value; HttpOnly; Max-Age=600; SameSite=Lax")); | ||
| ``` | ||
|
|
||
| ## Development Workflow | ||
|
|
||
| ### Build & Test | ||
|
|
||
| ```bash | ||
| ./gradlew build # Build with Gradle wrapper | ||
| ./gradlew test # Run tests | ||
| ./gradlew jacocoTestReport # Generate coverage | ||
| ``` | ||
|
|
||
| ### Key Dependencies | ||
|
|
||
| - **Auth0 Java SDK**: Core Auth0 API client (`com.auth0:auth0`) | ||
| - **java-jwt**: JWT token handling (`com.auth0:java-jwt`) | ||
| - **jwks-rsa**: RS256 signature verification (`com.auth0:jwks-rsa`) | ||
| - **Servlet API**: `javax.servlet-api` (compile-only) | ||
|
|
||
| ## Migration Considerations | ||
|
|
||
| ### Deprecated Methods | ||
|
|
||
| - `handle(HttpServletRequest)`: Session-based, incompatible with SameSite restrictions | ||
| - `buildAuthorizeUrl(HttpServletRequest, String)`: Session-only storage | ||
|
|
||
| ### Modern Alternatives | ||
|
|
||
| - Use `handle(HttpServletRequest, HttpServletResponse)` for cookie-based auth | ||
| - Use `buildAuthorizeUrl(HttpServletRequest, HttpServletResponse, String)` for proper cookie storage | ||
|
|
||
| ## Common Integration Points | ||
|
|
||
| - Organizations: Use `.withOrganization()` and validate `org_id` claims manually | ||
| - Custom parameters: Use `.withParameter()` on AuthorizeUrl (but not for `state`, `nonce`, `response_type`) | ||
| - Error handling: Catch `IdentityVerificationException` from `.handle()` calls | ||
| - HTTP customization: Use `.withHttpOptions()` for timeouts/proxy configuration |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| FROM gradle:6.9.2-jdk8 | ||
|
|
||
| WORKDIR /home/gradle | ||
| # Copy your project files | ||
| COPY . . | ||
|
|
||
| # Ensure the Gradle wrapper is executable | ||
| RUN chmod +x ./gradlew | ||
|
|
||
| # Expose both ports for your MCD test | ||
| EXPOSE 3000 | ||
| EXPOSE 8080 | ||
| EXPOSE 5005 | ||
|
|
||
| # Use --no-daemon to keep the container process alive | ||
| # We use the wrapper (./gradlew) to ensure consistency | ||
| #CMD ["./gradlew", "appRun", "--no-daemon", "-Pgretty.managed=false"] | ||
| ENV GRADLE_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005" | ||
| CMD ["gradle", "appRun", "--no-daemon"] |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.auth0; | ||
|
|
||
| import javax.servlet.http.HttpServletRequest; | ||
|
|
||
| public interface DomainProvider { | ||
| String getDomain(HttpServletRequest request); | ||
|
|
||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.auth0; | ||
|
|
||
| import javax.servlet.http.HttpServletRequest; | ||
|
|
||
| public interface DomainResolver { | ||
| /** | ||
| * Resolves the domain to be used for the current request. | ||
| * @param request the current HttpServletRequest | ||
| * @return a single domain string (e.g., "tenant.auth0.com") | ||
| */ | ||
| String resolve(HttpServletRequest request); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Check notice
Code scanning / CodeQL
Useless parameter Note
Copilot Autofix
AI 5 days ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.