npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

payload-zitadel-plugin

v0.2.42

Published

plugin for Payload CMS, which enables authentication via Zitadel IdP

Downloads

473

Readme

payload-zitadel-plugin

NPM

plugin for Payload CMS, which enables authentication via Zitadel IdP.

The default use case is to fully replace PayloadCMS Auth with Zitadel. Thus, the user collection in PayloadCMS becomes just a shadow of the information in Zitadel.

:boom: :boom: :boom:   works :100: with PayloadCMS version :three:   :boom: :boom: :boom:

Install

pnpm add [email protected]

Configuration

Initialize the plugin in Payload Config File. Change the parameters to connect to your Zitadel Instance.

payload.config.ts

import {buildConfig} from 'payload/config'
import {ZitadelPlugin} from 'payload-zitadel-plugin'


export default buildConfig({
    ...,
    plugins: [
        ZitadelPlugin({
            // URL of your Zitadel instance
            issuerUrl: process.env.ZITADEL_URL,

            // in Zitadel create a new App->Web->PKCE, then copy the Client ID
            clientId: process.env.ZITADEL_CLIENT_ID,

            // interpolation text for the Login Button - "sign in with ..."
            label: 'Zitadel',

            // change field names, field labels and alse hide them if wanted
            /* 
            fieldConfig: {
                image: {
                    name: 'idp_image',
                    label: 'some custom label'
                }
            }
             */

            // set the name of the CustomStrategy in PayloadCMS - usually not necessary
            // strategyName: 'zitadel'

            // set to true if you do not want to use the Zitadel Profile Picture as the Avatar
            // disableAvatar: true

            // set to true if you want to use your own custom login button
            // disableDefaultLoginButton: true

            // if you want to manually control what happen after a successful login
            // state contains all URLSearchParams that were send to /authorize
            // onSuccess: (state) => NextResponse.redirect([serverURL, state.get('redirect')].join(''))

            // following properties are only needed if you want to authenticate clients for the API
            // if you are just using the CMS you can ignore all of them
            // in Zitadel create a new App->API->JWT
            // enableAPI: true,
            // apiClientId: process.env.ZITADEL_API_CLIENT_ID,
            // apiKeyId: process.env.ZITADEL_API_KEY_ID,
            // apiKey: process.env.ZITADEL_API_KEY
        })
    ],
    ...
})

Optionally you could use an .env.local file for parameters:

.env.local

ZITADEL_URL=https://idp.zitadel.url
ZITADEL_CLIENT_ID=123456789012345678@project_name
ZITADEL_API_CLIENT_ID=123456789123456789@project_name
ZITADEL_API_KEY_ID=123456789012345678
ZITADEL_API_KEY='-----BEGIN RSA PRIVATE KEY----- ... ----END RSA PRIVATE KEY-----'

or use the Next.js Config file:

next.config.js

import {withPayload} from '@payloadcms/next/withPayload'

/** @type {import('next').NextConfig} */
const nextConfig = {
    env: {
        ZITADEL_URL: 'https://idp.zitadel.url',
        ZITADEL_CLIENT_ID: '123456789012345678@project_name',
        ZITADEL_API_CLIENT_ID: '123456789123456789@project_name',
        ZITADEL_API_KEY_ID: '123456789012345678',
        ZITADEL_API_KEY: '-----BEGIN RSA PRIVATE KEY----- ... ----END RSA PRIVATE KEY-----'
    }
}

export default withPayload(nextConfig)

further configuration

If you want to use the Zitadel profile picture as the avatar in PayloadCMS (disableAvatar != true), you have to manually add the asset URL to the Next.js config file.

Also if you want to automatically redirect to Zitadel without asking the user to click on the login button, you have to add the redirect manually to the Next.js config file.

next.config.js

import {withPayload} from '@payloadcms/next/withPayload'

/** @type {import('next').NextConfig} */
const nextConfig = {
    // if Avatar enabled:
    // allow loading assets like profile pictures from Zitadel
    images: {
        remotePatterns: [
            {
                //protocol: new URL(process.env.ZITADEL_URL).protocol,
                hostname: new URL(process.env.ZITADEL_URL).hostname,
                //port: new URL(process.env.ZITADEL_URL).port,
                pathname: '/assets/**'
            }
        ]
    },

    // optional: enable auto-redirect to Zitadel login page if not logged in
    async redirects() {
        return [
            {
                source: '/:path((?:admin|profile).*)',
                destination: '/api/users/authorize?redirect=/:path*',
                missing: [
                    {
                        type: 'cookie',
                        key: 'zitadel_id_token'
                    }
                ],
                permanent: false
            }
        ]
    }

}

export default withPayload(nextConfig)

For an example look in this repository at the dev directory!