Skip to content

fix(oidc): remove trailling / needed but add by User & Missing Oauth on /auth #736

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

Merged
merged 2 commits into from
May 12, 2025

Conversation

DrummyFloyd
Copy link
Contributor

@DrummyFloyd DrummyFloyd commented May 12, 2025

depends on provider keycloack != authentik# What kind of change does this PR introduce?

  • Issue on / OIDC env config
    need to be set manually by user, each provider set this differently (keycloack != Authentik)

  • add OIDC button on /auth

Why was this change needed?

discuss with @egelhaus

Other information:

can be tested with image from docker.hub => drummyfloyd/postiz:fix-oidc

Checklist:

Put a "X" in the boxes below to indicate you have followed the checklist;

  • I have read the CONTRIBUTING guide.
  • I checked that there were not similar issues or PRs already open for this.
  • This PR fixes just ONE issue (do not include multiple issues or types of change in the same PR) For example, don't try and fix a UI issue and include new dependencies in the same PR.

Summary by CodeRabbit

  • New Features

    • Introduced conditional display of a new OAuth provider option during registration, allowing for a more flexible authentication experience based on available provider settings.
  • Bug Fixes

    • Improved OAuth authentication reliability by correcting URL formatting in backend provider requests.

Copy link

vercel bot commented May 12, 2025

@DrummyFloyd is attempting to deploy a commit to the Listinai Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented May 12, 2025

Walkthrough

The changes update OAuth provider handling in both backend and frontend components. The backend removes trailing slashes from OAuth-related URLs in service calls, while the frontend introduces conditional rendering of a generic OAuth provider during registration, based on new variable flags, replacing the previous unconditional Google provider rendering.

Changes

File(s) Change Summary
apps/backend/src/services/auth/providers/oauth.provider.ts Removed trailing slashes from token and user info URLs in fetch calls within OauthProvider service methods.
apps/frontend/src/components/auth/register.tsx Added OauthProvider import, updated useVariables to include genericOauth, and conditionally rendered OAuth providers in registration UI based on new flags.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant RegisterAfter (Frontend)
    participant OauthProvider (Frontend)
    participant GoogleProvider (Frontend)

    User->>RegisterAfter (Frontend): Access registration
    RegisterAfter (Frontend)->>RegisterAfter (Frontend): Check variables (genericOauth, isGeneral)
    alt genericOauth and isGeneral are true
        RegisterAfter (Frontend)->>OauthProvider (Frontend): Render generic OAuth option
    else
        RegisterAfter (Frontend)->>GoogleProvider (Frontend): Render Google OAuth option
    end
Loading

Poem

In the warren of code, a gentle tweak,
URLs trimmed, no trailing streak.
Now on the frontend, bunnies decide,
Which OAuth provider will hop inside.
A flag is set, the choice is clear,
New options bloom—registration cheer!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/frontend/src/components/auth/register.tsx

Oops! Something went wrong! :(

ESLint: 8.57.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@eslint/eslintrc' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

apps/backend/src/services/auth/providers/oauth.provider.ts

Oops! Something went wrong! :(

ESLint: 8.57.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@eslint/eslintrc' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ 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.
    • 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.

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.

@DrummyFloyd DrummyFloyd changed the title fix(oidc): remove trailling / needed but add manually fix(oidc): remove trailling / needed but add by User & Missing Oauth on /auth May 12, 2025
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: 1

🧹 Nitpick comments (2)
apps/backend/src/services/auth/providers/oauth.provider.ts (1)

51-60: Consider adding clear documentation about URL formatting requirements

The URL formatting changes are subtle but impactful. Consider adding a comment in the constructor or by the environment variable validation to explain that users need to manually include the trailing slash if their OIDC provider requires it.

  this.tokenUrl = POSTIZ_OAUTH_TOKEN_URL;
  this.userInfoUrl = POSTIZ_OAUTH_USERINFO_URL;
+ // Note: Some OIDC providers (e.g., Keycloak) require trailing slashes in URLs, 
+ // while others (e.g., Authentik) do not. Please add trailing slashes manually
+ // to the environment variables if your provider requires them.
}
apps/frontend/src/components/auth/register.tsx (1)

168-175: Consider adding aria-label to improve accessibility

For better accessibility, consider adding descriptive aria-labels to the provider buttons to ensure screen readers can properly identify the authentication options.

<div className="gap-[5px] flex flex-col">
  {genericOauth && isGeneral ? (
-   <OauthProvider />
+   <OauthProvider aria-label="Continue with Single Sign-On" />
  ) : (
-   <GoogleProvider />
+   <GoogleProvider aria-label="Continue with Google" />
  )}
  {!!neynarClientId && <FarcasterProvider />}
  {billingEnabled && <WalletProvider />}
</div>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8e982f0 and cbc7d2b.

📒 Files selected for processing (2)
  • apps/backend/src/services/auth/providers/oauth.provider.ts (2 hunks)
  • apps/frontend/src/components/auth/register.tsx (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/backend/src/services/auth/providers/oauth.provider.ts (1)
libraries/nestjs-libraries/src/integrations/social.abstract.ts (1)
  • fetch (23-65)
apps/frontend/src/components/auth/register.tsx (2)
libraries/react-shared-libraries/src/helpers/variable.context.tsx (1)
  • useVariables (59-61)
apps/frontend/src/components/auth/providers/google.provider.tsx (1)
  • GoogleProvider (5-45)
🔇 Additional comments (5)
apps/backend/src/services/auth/providers/oauth.provider.ts (2)

63-63: Trailing slash removed to allow provider-specific URL formatting

This change aligns with the PR objective of allowing manual trailing slash control for different OIDC providers like Keycloak and Authentik that handle URL formats differently.


88-88: Trailing slash removed from userInfoUrl for consistent provider handling

Similar to the tokenUrl change, this ensures the OIDC userInfo endpoint URL formatting is determined by the environment variable value set by the user, improving flexibility across different providers.

apps/frontend/src/components/auth/register.tsx (3)

17-17: Added import for generic OAuth provider

This import enables the new OIDC login option mentioned in the PR objectives.


95-96: Added genericOauth variable to configuration

Correctly updated the variables destructuring to include the new genericOauth flag required for conditional OAuth provider rendering.


168-172: Implemented conditional rendering of OAuth providers

This change successfully adds the OIDC button on the /auth route as required by the PR objectives, showing either the generic OAuth provider or Google provider based on configuration.

Comment on lines +168 to +172
{genericOauth && isGeneral ? (
<OauthProvider />
) : (
<GoogleProvider />
)}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify OauthProvider component implementation

Make sure the OauthProvider component follows the same pattern as GoogleProvider with proper error handling and UI consistency.


🏁 Script executed:

#!/bin/bash
# Find and display the OauthProvider component implementation
fd "oauth.provider.tsx" --exec cat {}

Length of output: 1329


🏁 Script executed:

#!/bin/bash
# Find and display the GoogleProvider component implementation
rg -A20 "export const GoogleProvider" --glob "*.tsx"

Length of output: 2016


Align error handling and UI between OauthProvider and GoogleProvider

The OauthProvider implementation correctly adds a try/catch and checks response.ok, but the GoogleProvider still uses a “bare” fetch call and renders a smaller icon. To keep both providers consistent:

• apps/frontend/src/components/auth/providers/google.provider.tsx

  • Wrap the fetch in try/catch and check response.ok before reading text, mirroring OauthProvider.
  • Example diff:
     export const GoogleProvider = () => {
       const fetch = useFetch();
  •  const gotoLogin = useCallback(async () => {
    
  •    const link = await (await fetch('/auth/oauth/GOOGLE')).text();
    
  •    window.location.href = link;
    
  •  }, []);
    
  •  const gotoLogin = useCallback(async () => {
    
  •    try {
    
  •      const response = await fetch('/auth/oauth/GOOGLE');
    
  •      if (!response.ok) {
    
  •        throw new Error(`Login link request failed with status ${response.status}`);
    
  •      }
    
  •      const link = await response.text();
    
  •      window.location.href = link;
    
  •    } catch (error) {
    
  •      console.error('Failed to get Google login link:', error);
    
  •    }
    
  •  }, []);
    

• Icon sizing & accessibility

  • OauthProvider uses a 40×40 Image; GoogleProvider’s SVG is 21×21. Pick one size (e.g. 40×40) and apply it to both for visual parity.
  • Ensure both have meaningful alt text for screen readers.

Once these changes are in place, both components will share identical fetch patterns, error handling and UI styling.

Committable suggestion skipped: line range outside the PR's diff.

@egelhaus egelhaus merged commit d384d81 into gitroomhq:main May 12, 2025
2 of 3 checks passed
arampersand pushed a commit to arampersand/flowsupply that referenced this pull request Jun 14, 2025
fix(oidc): remove trailling / needed but add by User & Missing Oauth on  /auth
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