Skip to content
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

fix well known endpoint. #136

Merged
merged 1 commit into from
Feb 8, 2025
Merged

fix well known endpoint. #136

merged 1 commit into from
Feb 8, 2025

Conversation

uakihir0
Copy link
Owner

@uakihir0 uakihir0 commented Feb 8, 2025

fix #135

Summary by CodeRabbit

  • Bug Fixes
    • Corrected the formatting of OAuth endpoint URLs to ensure that authentication and authorization flows redirect users properly.
    • Improved callback handling for a more consistent and reliable sign-in experience.

Copy link

coderabbitai bot commented Feb 8, 2025

Walkthrough

This pull request modifies the URL construction for OAuth well-known endpoints by adding a forward slash (/) before the “.well-known” segment in two methods within the internal resource. Additionally, test files are updated: a hardcoded callback URL is replaced with a placeholder and a test method is renamed while updating its endpoint reference. No changes were made to exported or public declarations.

Changes

File(s) Change Summary
auth/src/commonMain/kotlin/.../_WellKnownResource.kt Added a '/' before the “.well-known” segment in both the oAuthProtectedResource and oAuthAuthorizationServer method URL constructions.
auth/src/jvmTest/kotlin/.../OAuthTest.kt
auth/src/jvmTest/kotlin/.../WellKnownTest.kt
OAuthTest: Replaced hardcoded callback URL with a placeholder.
WellKnownTest: Updated the resource reference from BSKY_SOCIAL.uri to OYSTER_US_EAST.uri and renamed a test method for clarity.

Assessment against linked issues

Objective Addressed Explanation
Fix URL formatting for well-known endpoints to resolve UnknownHostException [#135]

Possibly related PRs

Poem

I'm a hopping rabbit in a code-filled glen,
Adding slashes to URLs again and again.
No more UnknownHost, the endpoints shine bright,
Tests now dance with placeholders just right.
Carrots and code — a happy sight! 🥕🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
auth/src/jvmTest/kotlin/work/socialhub/kbsky/auth/OAuthTest.kt (1)

53-53: Add null safety checks for required URL parameters.

The code assumes the 'code' parameter will always be present and uses a non-null assertion (!!) which could cause runtime failures.

Add proper null checking:

-    val code = Url(callback).parameters["code"].also { println(it) }
+    val code = Url(callback).parameters["code"]
+        ?: throw IllegalArgumentException("Missing required 'code' parameter in callback URL")
+    println(code)

     val response = AuthFactory
         .instance(BSKY_SOCIAL.uri)
         .oauth()
         .authorizationCodeTokenRequest(oAuthContext,
             OAuthAuthorizationCodeTokenRequest().also {
-                it.code = code!!
+                it.code = code
             }
         )

Also applies to: 60-60

🧹 Nitpick comments (2)
auth/src/jvmTest/kotlin/work/socialhub/kbsky/auth/OAuthTest.kt (1)

47-47: Document the expected callback URL format and required parameters.

The placeholder {{CALLBACK_URL}} makes the test more flexible, but it needs documentation to ensure proper usage.

Add a comment explaining:

  • The expected format of the callback URL
  • Required URL parameters (especially 'code' which is used in the test)
  • Example of a valid callback URL
+    /**
+     * Example callback URL format:
+     * http://example.com/callback?code=auth_code&state=state_value&iss=issuer
+     * Required parameters:
+     * - code: OAuth authorization code
+     * Optional parameters:
+     * - iss: Issuer (currently commented out)
+     * - state: State parameter (currently commented out)
+     */
     val callback = """
         {{CALLBACK_URL}}
         """
auth/src/commonMain/kotlin/work/socialhub/kbsky/auth/internal/_WellKnownResource.kt (1)

40-40: LGTM! Consider extracting the well-known path segment to a constant.

The URL path is now correctly formatted. However, since both methods use the .well-known path segment, consider extracting it to avoid duplication.

 class _WellKnownResource(
     private val config: AuthConfig
 ) : WellKnownResource {
+    companion object {
+        private const val WELL_KNOWN_PATH = "/.well-known"
+        private const val OAUTH_PROTECTED_RESOURCE_PATH = "$WELL_KNOWN_PATH/oauth-protected-resource"
+        private const val OAUTH_AUTHORIZATION_SERVER_PATH = "$WELL_KNOWN_PATH/oauth-authorization-server"
+    }

     override fun oAuthProtectedResource()
             : Response<WellKnownOAuthProtectedResourceResponse> {
         return proceed<WellKnownOAuthProtectedResourceResponse> {
             runBlocking {
                 HttpRequest()
-                    .url("${config.pdsServer}/.well-known/oauth-protected-resource")
+                    .url("${config.pdsServer}$OAUTH_PROTECTED_RESOURCE_PATH")
                     .accept(MediaType.JSON)
                     .get()
             }
         }
     }

     override fun oAuthAuthorizationServer()
             : Response<WellKnownOAuthAuthorizationServerResponse> {
         return proceed<WellKnownOAuthAuthorizationServerResponse> {
             runBlocking {
                 HttpRequest()
-                    .url("${config.authorizationServer}/.well-known/oauth-authorization-server")
+                    .url("${config.authorizationServer}$OAUTH_AUTHORIZATION_SERVER_PATH")
                     .accept(MediaType.JSON)
                     .get()
             }
         }
     }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a170a71 and 7a934d7.

📒 Files selected for processing (3)
  • auth/src/commonMain/kotlin/work/socialhub/kbsky/auth/internal/_WellKnownResource.kt (2 hunks)
  • auth/src/jvmTest/kotlin/work/socialhub/kbsky/auth/OAuthTest.kt (1 hunks)
  • auth/src/jvmTest/kotlin/work/socialhub/kbsky/auth/WellKnownTest.kt (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (5)
auth/src/jvmTest/kotlin/work/socialhub/kbsky/auth/WellKnownTest.kt (3)

4-4: LGTM!

The import statement for OYSTER_US_EAST follows the existing pattern and is required for the test method update.


12-12: Verify the endpoint change rationale.

The test now uses OYSTER_US_EAST.uri instead of BSKY_SOCIAL.uri. While this change might be intentional for testing against different endpoints, please confirm if this is part of the fix for the well-known endpoint issue (#135).


19-19: LGTM! Great improvement in method naming.

The renamed method testWellKnownOAuthAuthorizationServer is more descriptive and clearly indicates its purpose, improving code readability.

auth/src/jvmTest/kotlin/work/socialhub/kbsky/auth/OAuthTest.kt (1)

46-50: Verify test functionality with the placeholder.

The test now uses a placeholder for the callback URL. Ensure there's a mechanism in place to replace this placeholder with actual values during test execution.

Please confirm:

  1. How is the placeholder replaced with actual values during testing?
  2. Are there any test setup methods or test data providers that handle this?
  3. Does this change affect CI/CD pipeline execution?
auth/src/commonMain/kotlin/work/socialhub/kbsky/auth/internal/_WellKnownResource.kt (1)

22-22: LGTM! The URL path now correctly follows RFC 8615.

The addition of the forward slash before .well-known ensures proper URL construction and compliance with the well-known URI standard.

✅ Verification successful

🌐 Web query:

What is the correct path format for well-known URIs according to RFC 8615?

💡 Result:

The correct path format for well-known URIs as defined in **RFC 8615** begins with the reserved prefix `/.well-known/`, followed by a registered suffix specific to the application or protocol. For example:

```
http://example.com/.well-known/<registered-suffix>
```

Key details of this format include:

1. **Path prefix**:  
   All well-known URIs **must** start with `/.well-known/` in their path component[1][5][7]. This standardized prefix ensures consistency across implementations.

2. **Supported URI schemes**:  
   The specification applies to HTTP, HTTPS, WebSocket (WS), and Secure WebSocket (WSS) URIs by default[5][7]. Other schemes may adopt it only if explicitly defined[7].

3. **Registered suffixes**:  
   Suffixes like `acme-challenge` (for Let's Encrypt domain validation) or `security.txt` (for security policies) must be formally registered with IETF[2][7]. Example:
   ```
   https://example.com/.well-known/acme-challenge/xyz123
   ```

4. **Collision avoidance**:  
   The registry system prevents conflicts between different uses of the same suffix[2][7]. Developers proposing new suffixes must submit them for review via IETF’s process[2].

RFC 8615 obsoletes RFC 5785 and updates earlier standards like HTTP/1.1 (RFC 7230) to reserve this URI space[1][5]. Well-known URIs are widely used for domain validation, security policies, and service discovery[2][10].

Citations:

- 1: https://www.rfc-editor.org/info/rfc8615
- 2: https://www.keycdn.com/support/well-known
- 3: https://tex2e.github.io/rfc-translater/html/rfc8615.html
- 4: https://dl.acm.org/doi/10.17487/RFC8615
- 5: https://www.rfc-editor.org/rfc/rfc8615.html
- 6: https://datatracker.ietf.org/doc/html/rfc5785
- 7: https://datatracker.ietf.org/doc/html/rfc8615
- 8: https://en.wikipedia.org/wiki/Well-known_URI
- 9: https://en.wikipedia.org/wiki/Uniform_Resource_Locator
- 10: https://blog.devgenius.io/well-known-locations-a-reserved-uri-path-prefix-5277b2f37db7?gi=8d00a1ca3654

LGTM – The URL construction correctly uses the required "/.well-known/" prefix per RFC 8615.

The updated code now ensures that the pdsServer value is appropriately combined with the reserved URI path, maintaining proper format regardless of trailing slashes. This change aligns with the specification detailed in RFC 8615.

@uakihir0 uakihir0 merged commit 2881819 into main Feb 8, 2025
1 check 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.

UnknownHostException: Unable to resolve host "bsky.social.well-known"
1 participant