postiz-app icon indicating copy to clipboard operation
postiz-app copied to clipboard

Add Generic sso/OIDC

Open DrummyFloyd opened this issue 1 year ago • 4 comments

What kind of change does this PR introduce?

Features

Reopen becasue https://github.com/gitroomhq/postiz-app/pull/550# was accidentally closed

Why was this change needed?

add new oidc features for self hosted stuff

Please link to related issues when possible, and explain WHY you changed things, not WHAT you changed.

Other information:

Related to https://github.com/gitroomhq/postiz-app/discussions/344

Checklist:

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

  • [x] I have read the CONTRIBUTING guide.
  • [x] I checked that there were not similar issues or PRs already open for this.
  • [x] 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.

TODO:

  • [x] test on my infra can be tested with following image drummyfloyd/postiz:gh-550 for authentik provider only
  • [x] make use of a genric OIDC instead => drummyfloyd/postiz:gh-550-generic
  • [ ] add documenation

Summary by CodeRabbit

  • New Features
    • Introduced a generic OAuth authentication option, offering more flexibility during sign-in.
    • Updated the login interface to support custom branding elements such as a logo and display name.
    • Enhanced the sign-in process with dynamic redirection based on new configuration settings.
    • Added new properties to manage OAuth-related information in the application context.
  • Bug Fixes
    • Improved error handling for OAuth authentication processes to ensure robustness.
  • Documentation
    • Updated environment variable declarations to reflect new OAuth configuration settings.

DrummyFloyd avatar Apr 12 '25 20:04 DrummyFloyd

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

A member of the Team first needs to authorize it.

vercel[bot] avatar Apr 12 '25 20:04 vercel[bot]

Walkthrough

The changes introduce a set of new OAuth configuration options and functionality across both backend and frontend. Environment variables related to OAuth have been added, and a new backend OauthProvider class has been implemented with methods for link generation, token exchange, and user retrieval. Enhancements in the frontend include updated layout and login components to support OAuth authentication via a new React component. Additionally, the providers factory, middleware logic, Prisma schema, and shared variable context have been updated to incorporate a generic OAuth provider option.

Changes

File(s) Change Summary
.env.example Added multiple OAuth-related environment variables and removed extraneous blank lines.
apps/backend/src/services/auth/providers/oauth.provider.ts
apps/backend/src/services/auth/providers/providers.factory.ts
Introduced a new OauthProvider class with methods for generating OAuth links, token exchange, and user info retrieval; updated the providers factory to instantiate OauthProvider for GENERIC provider.
apps/frontend/src/app/layout.tsx
libraries/react-shared-libraries/src/helpers/variable.context.tsx
Added new OAuth configuration properties (genericOauth, oauthLogoUrl, oauthDisplayName) to the layout component and variable context.
apps/frontend/src/components/auth/login.tsx
apps/frontend/src/components/auth/providers/oauth.provider.tsx
Updated login component to conditionally render the new <OauthProvider /> component based on the genericOauth flag; added a new React functional OauthProvider component to initiate the OAuth flow.
apps/frontend/src/middleware.ts Modified redirection logic to determine the provider (generic vs github) based on the presence of the POSTIZ_GENERIC_OAUTH environment variable.
libraries/nestjs-libraries/src/database/prisma/schema.prisma Expanded the Provider enum by adding a GENERIC option and applied minor formatting changes.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant LC as Login Component
    participant FP as Frontend OAuth Component
    participant BE as Backend OAuth Provider
    participant OS as External OAuth Service

    U->>LC: Click "Sign in"
    LC->>FP: Render OAuth Provider component
    FP->>BE: Request OAuth login link (/auth/oauth/GENERIC)
    BE->>BE: Generate link using OauthProvider.generateLink()
    BE-->>FP: Return OAuth URL
    FP->>U: Redirect to External OAuth Service
    U->>OS: Authenticate and authorize
    OS-->>U: Redirect back with auth code
    U->>BE: Submit auth code for token exchange
    BE->>BE: Invoke getToken() and getUser() methods
    BE-->>U: Return authenticated user info

Poem

I'm a little rabbit, hopping with delight,
New OAuth features make my code take flight.
Secrets and tokens now merrily align,
With links and logins working just fine.
In every line of code I cheer and play,
Celebrating changes in a bouncy, bright way! 🐰🎉

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

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[bot] avatar Apr 12 '25 20:04 coderabbitai[bot]

@nevo-david any chance this will be able to get merged in a version soon?

cchance27 avatar Apr 19 '25 00:04 cchance27

@nevo-david any chance this will be able to get merged in a version soon?

bump

Andyroid0 avatar Apr 23 '25 02:04 Andyroid0

Still nothing ? Been a bit frustrating.. to make some work upon a features ask by he community and still waiting some news from the maintener after several month (first PR included ) ..

DrummyFloyd avatar May 03 '25 20:05 DrummyFloyd

@nevo-david please review this!

egelhaus avatar May 03 '25 21:05 egelhaus

Alright, because Nevo doesnt seem to respond to this, im just going to merge it as it seems like a solid addition and it looks good to me. @DrummyFloyd Please also make an PR to the docs regarding setting up OAuth. And also please provide the Redirect URI to this channel here so we can all add it until you make the docs PR. Thank you

egelhaus avatar May 03 '25 22:05 egelhaus

Alright, because Nevo doesnt seem to respond to this, im just going to merge it as it seems like a solid addition and it looks good to me. @DrummyFloyd Please also make an PR to the docs regarding setting up OAuth. And also please provide the Redirect URI to this channel here so we can all add it until you make the docs PR. Thank you

thank you , will provide asap (today or tomorrow

what do you means by the Redirect URI to this channel

@egelhaus PR doc ready to be review =) => https://github.com/gitroomhq/postiz-docs/pull/98

DrummyFloyd avatar May 03 '25 23:05 DrummyFloyd

Hey, with Redirect URI I meant the URI to put in the OIDC Provider, and that you provide it here so we can use it as soon as you say it.

egelhaus avatar May 04 '25 15:05 egelhaus

Possible to disable user registration and only use sso/oidc?

creperozelot avatar May 06 '25 16:05 creperozelot

No, currently not, disabling User registration disables OIDC

egelhaus avatar May 06 '25 17:05 egelhaus

okay thanks

creperozelot avatar May 06 '25 20:05 creperozelot