Skip to content

feat: add support for logging in to a basic auth protected app#203

Merged
steveiliop56 merged 1 commit into
mainfrom
feat/app-basic-auth
Jun 20, 2025
Merged

feat: add support for logging in to a basic auth protected app#203
steveiliop56 merged 1 commit into
mainfrom
feat/app-basic-auth

Conversation

@steveiliop56

@steveiliop56 steveiliop56 commented Jun 20, 2025

Copy link
Copy Markdown
Member

Solves #185

Summary by CodeRabbit

  • New Features

    • Added support for storing and handling basic authentication credentials.
    • Automatically sets an Authorization header with a Basic auth token when credentials are provided.
  • Bug Fixes

    • Improved header handling by removing unnecessary sanitization and limiting debug log output to header keys only.

@coderabbitai

coderabbitai Bot commented Jun 20, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce support for basic authentication credentials within the application's configuration and request handling. A new struct for basic auth labels is added, the labels parsing logic is updated to handle these credentials, and the HTTP handler now sets an Authorization header using a new utility function to generate the Basic auth token. Header sanitization is removed, and logging is simplified.

Changes

File(s) Change Summary
internal/types/config.go Added BasicLabels struct with User and Password fields; extended Labels struct with Basic field.
internal/utils/utils.go Updated label parsing to include basic auth; added GetBasicAuth function for base64 encoding credentials.
internal/handlers/handlers.go Modified header setting: removed sanitization, simplified logging, added Authorization header with Basic auth when credentials are present.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant AuthHandler
    participant Utils

    Client->>AuthHandler: Send request
    AuthHandler->>Utils: Parse labels (including Basic)
    alt Basic auth credentials present
        AuthHandler->>Utils: GetBasicAuth(user, password)
        Utils-->>AuthHandler: base64(user:password)
        AuthHandler->>Client: Set Authorization header (Basic)
    end
    AuthHandler->>Client: Set other headers and respond
Loading

Poem

In the warren of code, a secret we keep,
Now bunnies can guard while you peacefully sleep.
With headers set plainly, and credentials in tow,
Basic auth hops in, as the carrots now grow.
No more sanitizing—just clean, simple cheer,
🥕 The rabbit secures, so you’ve nothing to fear!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
internal/types/config.go (1)

102-106: Consider security implications of plaintext credential storage.

The BasicLabels struct stores username and password as plain strings. While this is likely intended for configuration purposes, ensure that:

  1. These credentials are not logged or exposed in debug output
  2. The values are properly validated when parsed from labels
  3. Consider if any additional security measures are needed for credential handling
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b5799da and 1bcae61.

📒 Files selected for processing (3)
  • internal/handlers/handlers.go (2 hunks)
  • internal/types/config.go (1 hunks)
  • internal/utils/utils.go (3 hunks)
🔇 Additional comments (3)
internal/types/config.go (1)

114-114: LGTM! Clean integration with existing Labels structure.

The addition of the Basic field to the Labels struct follows the existing pattern with the OAuth field and maintains consistency.

internal/utils/utils.go (2)

363-370: LGTM! Correct implementation of Basic auth header generation.

The GetBasicAuth function correctly implements RFC 7617 Basic authentication by:

  1. Concatenating username and password with a colon separator
  2. Base64 encoding the combined string
  3. Returning the encoded value for use in Authorization headers

205-205: ```shell
#!/bin/bash

Retrieve the BasicLabels struct definition to verify its field tags

echo "Looking for BasicLabels struct definition across the repo..."
rg -n -C3 "type BasicLabels" --type go

Locate the labelsParsed declaration around the parser.Decode call

echo "Locating labelsParsed declaration in internal/utils/utils.go..."
rg -n -C3 "labelsParsed" --type go internal/utils/utils.go


</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Comment thread internal/handlers/handlers.go
Comment thread internal/handlers/handlers.go
@steveiliop56 steveiliop56 merged commit f3ec4ba into main Jun 20, 2025
6 checks passed
@Rycochet Rycochet deleted the feat/app-basic-auth branch April 1, 2026 16:08
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.

1 participant