payload-zitadel-plugin 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  [![NPM](https://nodei.co/npm/payload-zitadel-plugin.png)](https://npmjs.org/package/payload-zitadel-plugin)
4
4
 
5
- plugin for [Payload CMS](https://payloadcms.com), which enables authentication via Zitadel IdP. It uses [NextAuth.js](https://next-auth.js.org) under the hood.
5
+ plugin for [Payload CMS](https://payloadcms.com), which enables authentication via Zitadel IdP. It
6
+ uses [NextAuth.js](https://next-auth.js.org) under the hood.
6
7
 
7
8
  :boom: :boom: :boom:   works :100: with PayloadCMS version :three:   :boom: :boom: :boom:
8
9
 
@@ -23,24 +24,35 @@ import {buildConfig} from 'payload/config'
23
24
  import {ZitadelPluginProvider} from 'payload-zitadel-plugin'
24
25
 
25
26
  export const {zitadelPlugin, nextauthHandler} = ZitadelPluginProvider({
26
- // interpolation text for the Login Button
27
- externalProviderName: 'Test-IdP',
28
-
29
- // set to true if you want users to only be able to sign in via Zitadel
30
- disableLocalStrategy: true,
31
-
32
27
  // in Zitadel create a new App->Web->PKCE
33
28
  issuerUrl: process.env.ZITADEL_URL,
34
29
  clientId: process.env.ZITADEL_CLIENT_ID,
35
-
30
+
31
+ // interpolation text for the Login Button - "sign in with ..."
32
+ // externalProviderName: 'ZITADEL',
33
+
34
+ // set to true if you want to use your own custom login button
35
+ // disableDefaultLoginButton: true
36
+
37
+ // set to true if you want users to only be able to sign in via Zitadel
38
+ // disableLocalStrategy: true,
39
+
40
+ // if you want to specify the users collection slug
41
+ // authSlug: 'users',
42
+
43
+ // if you want to specify the field name for the IdP Id in the users collection
44
+ // associatedIdFieldName: 'idp_id'
45
+
46
+ // change the internal name, only if you know what you are doing!!!
47
+ // internalProviderName = 'zitadel',
48
+
36
49
  // following properties are only needed if you want to authenticate clients for the API
37
50
  // if you are just using the CMS you can ignore all of them
38
-
39
51
  // in Zitadel create a new App->API->JWT
40
- enableAPI: true,
41
- apiClientId: process.env.ZITADEL_API_CLIENT_ID,
42
- apiKeyId: process.env.ZITADEL_API_KEY_ID,
43
- apiKey: process.env.ZITADEL_API_KEY
52
+ // enableAPI: true,
53
+ // apiClientId: process.env.ZITADEL_API_CLIENT_ID,
54
+ // apiKeyId: process.env.ZITADEL_API_KEY_ID,
55
+ // apiKey: process.env.ZITADEL_API_KEY
44
56
  })
45
57
 
46
58
  export default buildConfig({
@@ -53,19 +65,48 @@ export default buildConfig({
53
65
  ```
54
66
 
55
67
  Optionally you could use an `.env.local` file for parameters:
68
+
56
69
  #### .env.local
70
+
57
71
  ```dotenv
58
- ZITADEL_URL: 'https://idp.zitadel.url',
59
- ZITADEL_CLIENT_ID: '123456789012345678@project_name',
60
- ZITADEL_API_CLIENT_ID: '123456789123456789@project_name',
61
- ZITADEL_API_KEY_ID: '123456789012345678',
62
- ZITADEL_API_KEY: '-----BEGIN RSA PRIVATE KEY----- ... ----END RSA PRIVATE KEY-----'
72
+ NEXTAUTH_URL=http://localhost
73
+ NEXTAUTH_SECRET=pMvElMzVrLvGL4tHyqtDlVP/90wQdxGBy94ISifi62I=
74
+ ZITADEL_URL=https://idp.zitadel.url
75
+ ZITADEL_CLIENT_ID=123456789012345678@project_name
76
+ ZITADEL_API_CLIENT_ID=123456789123456789@project_name
77
+ ZITADEL_API_KEY_ID=123456789012345678
78
+ ZITADEL_API_KEY='-----BEGIN RSA PRIVATE KEY----- ... ----END RSA PRIVATE KEY-----'
79
+ ```
80
+
81
+ or use the Next.js Config file:
82
+
83
+ #### next.config.mjs
84
+
85
+ ```typescript
86
+ import {withPayload} from '@payloadcms/next/withPayload'
87
+
88
+ /** @type {import('next').NextConfig} */
89
+ const nextConfig = {
90
+ env: {
91
+ NEXTAUTH_URL: 'http://localhost',
92
+ NEXTAUTH_SECRET: 'mQ46qpFwfE1BHuqMC+qlm19qBAD9fVPgh28werwe3ASFlAfnKjM=',
93
+ ZITADEL_URL: 'https://idp.zitadel.url',
94
+ ZITADEL_CLIENT_ID: '123456789012345678@project_name',
95
+ ZITADEL_API_CLIENT_ID: '123456789123456789@project_name',
96
+ ZITADEL_API_KEY_ID: '123456789012345678',
97
+ ZITADEL_API_KEY: '-----BEGIN RSA PRIVATE KEY----- ... ----END RSA PRIVATE KEY-----'
98
+ }
99
+ }
100
+
101
+ export default withPayload(nextConfig)
63
102
  ```
64
103
 
65
104
  ### create route
105
+
66
106
  Unfortunately you need to manually create the following NextAuth.js route in your Next.js App (using App Router):
67
107
 
68
108
  ### (nextauth)/api/auth/[...nextauth]/route.ts
109
+
69
110
  ```typescript
70
111
  import {nextauthHandler} from '@payload-config'
71
112
 
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,YAAY,CAAA;AAEjD,eAAO,MAAM,WAAW,EAAE,sBAuCxB,CAAA"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,YAAY,CAAA;AAEjD,eAAO,MAAM,WAAW,EAAE,sBA4CxB,CAAA"}
package/dist/options.js CHANGED
@@ -28,6 +28,11 @@ export const authOptions = ({ internalProviderName, issuerUrl, clientId })=>({
28
28
  loginName: profile.preferred_username,
29
29
  image: profile.picture
30
30
  }),
31
+ userinfo: {
32
+ async request (context) {
33
+ return await context.client.userinfo(context.tokens.access_token);
34
+ }
35
+ },
31
36
  clientId
32
37
  }
33
38
  ],
@@ -35,8 +40,8 @@ export const authOptions = ({ internalProviderName, issuerUrl, clientId })=>({
35
40
  session: async ({ session, token })=>({
36
41
  ...session,
37
42
  user: {
38
- ...session.user,
39
- id: token.sub
43
+ id: token.sub,
44
+ ...session.user
40
45
  }
41
46
  })
42
47
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/options.ts"],"sourcesContent":["import {ZitadelAuthOptionsType} from './types.js'\n\nexport const authOptions: ZitadelAuthOptionsType = ({internalProviderName, issuerUrl, clientId}) => ({\n providers: [\n {\n id: internalProviderName,\n name: internalProviderName,\n type: 'oauth',\n version: '2',\n wellKnown: issuerUrl,\n authorization: {\n params: {\n scope: 'openid email profile'\n }\n },\n idToken: true,\n checks: ['pkce', 'state'],\n client: {\n token_endpoint_auth_method: 'none'\n },\n profile: async (profile) => ({\n id: profile.sub,\n name: profile.name,\n firstName: profile.given_name,\n lastName: profile.family_name,\n email: profile.email,\n loginName: profile.preferred_username,\n image: profile.picture\n }),\n clientId\n }\n ],\n callbacks: {\n session: async ({session, token}) => ({\n ...session,\n user: {\n ...session.user,\n id: token.sub\n }\n })\n }\n})"],"names":["authOptions","internalProviderName","issuerUrl","clientId","providers","id","name","type","version","wellKnown","authorization","params","scope","idToken","checks","client","token_endpoint_auth_method","profile","sub","firstName","given_name","lastName","family_name","email","loginName","preferred_username","image","picture","callbacks","session","token","user"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,cAAsC,CAAC,EAACC,oBAAoB,EAAEC,SAAS,EAAEC,QAAQ,EAAC,GAAM,CAAA;QACjGC,WAAW;YACP;gBACIC,IAAIJ;gBACJK,MAAML;gBACNM,MAAM;gBACNC,SAAS;gBACTC,WAAWP;gBACXQ,eAAe;oBACXC,QAAQ;wBACJC,OAAO;oBACX;gBACJ;gBACAC,SAAS;gBACTC,QAAQ;oBAAC;oBAAQ;iBAAQ;gBACzBC,QAAQ;oBACJC,4BAA4B;gBAChC;gBACAC,SAAS,OAAOA,UAAa,CAAA;wBACzBZ,IAAIY,QAAQC,GAAG;wBACfZ,MAAMW,QAAQX,IAAI;wBAClBa,WAAWF,QAAQG,UAAU;wBAC7BC,UAAUJ,QAAQK,WAAW;wBAC7BC,OAAON,QAAQM,KAAK;wBACpBC,WAAWP,QAAQQ,kBAAkB;wBACrCC,OAAOT,QAAQU,OAAO;oBAC1B,CAAA;gBACAxB;YACJ;SACH;QACDyB,WAAW;YACPC,SAAS,OAAO,EAACA,OAAO,EAAEC,KAAK,EAAC,GAAM,CAAA;oBAClC,GAAGD,OAAO;oBACVE,MAAM;wBACF,GAAGF,QAAQE,IAAI;wBACf1B,IAAIyB,MAAMZ,GAAG;oBACjB;gBACJ,CAAA;QACJ;IACJ,CAAA,EAAE"}
1
+ {"version":3,"sources":["../src/options.ts"],"sourcesContent":["import {ZitadelAuthOptionsType} from './types.js'\n\nexport const authOptions: ZitadelAuthOptionsType = ({internalProviderName, issuerUrl, clientId}) => ({\n providers: [\n {\n id: internalProviderName,\n name: internalProviderName,\n type: 'oauth',\n version: '2',\n wellKnown: issuerUrl,\n authorization: {\n params: {\n scope: 'openid email profile'\n }\n },\n idToken: true,\n checks: ['pkce', 'state'],\n client: {\n token_endpoint_auth_method: 'none'\n },\n profile: async (profile) => ({\n id: profile.sub,\n name: profile.name,\n firstName: profile.given_name,\n lastName: profile.family_name,\n email: profile.email,\n loginName: profile.preferred_username,\n image: profile.picture\n }),\n userinfo: {\n async request(context) {\n return await context.client.userinfo(context.tokens.access_token!)\n }\n },\n clientId\n }\n ],\n callbacks: {\n session: async ({session, token}) => ({\n ...session,\n user: {\n id: token.sub,\n ...session.user\n }\n })\n }\n})"],"names":["authOptions","internalProviderName","issuerUrl","clientId","providers","id","name","type","version","wellKnown","authorization","params","scope","idToken","checks","client","token_endpoint_auth_method","profile","sub","firstName","given_name","lastName","family_name","email","loginName","preferred_username","image","picture","userinfo","request","context","tokens","access_token","callbacks","session","token","user"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,cAAsC,CAAC,EAACC,oBAAoB,EAAEC,SAAS,EAAEC,QAAQ,EAAC,GAAM,CAAA;QACjGC,WAAW;YACP;gBACIC,IAAIJ;gBACJK,MAAML;gBACNM,MAAM;gBACNC,SAAS;gBACTC,WAAWP;gBACXQ,eAAe;oBACXC,QAAQ;wBACJC,OAAO;oBACX;gBACJ;gBACAC,SAAS;gBACTC,QAAQ;oBAAC;oBAAQ;iBAAQ;gBACzBC,QAAQ;oBACJC,4BAA4B;gBAChC;gBACAC,SAAS,OAAOA,UAAa,CAAA;wBACzBZ,IAAIY,QAAQC,GAAG;wBACfZ,MAAMW,QAAQX,IAAI;wBAClBa,WAAWF,QAAQG,UAAU;wBAC7BC,UAAUJ,QAAQK,WAAW;wBAC7BC,OAAON,QAAQM,KAAK;wBACpBC,WAAWP,QAAQQ,kBAAkB;wBACrCC,OAAOT,QAAQU,OAAO;oBAC1B,CAAA;gBACAC,UAAU;oBACN,MAAMC,SAAQC,OAAO;wBACjB,OAAO,MAAMA,QAAQf,MAAM,CAACa,QAAQ,CAACE,QAAQC,MAAM,CAACC,YAAY;oBACpE;gBACJ;gBACA7B;YACJ;SACH;QACD8B,WAAW;YACPC,SAAS,OAAO,EAACA,OAAO,EAAEC,KAAK,EAAC,GAAM,CAAA;oBAClC,GAAGD,OAAO;oBACVE,MAAM;wBACF/B,IAAI8B,MAAMjB,GAAG;wBACb,GAAGgB,QAAQE,IAAI;oBACnB;gBACJ,CAAA;QACJ;IACJ,CAAA,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload-zitadel-plugin",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "plugin for Payload CMS, which enables authentication via Zitadel IdP",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -42,18 +42,18 @@
42
42
  "next": "^15.0.0-rc.0",
43
43
  "next-auth": "^4.24.7",
44
44
  "payload": "3.0.0-beta.47",
45
- "react": "^19.0.0-rc-dfd30974ab-20240613",
46
- "react-dom": "^19.0.0-rc-dfd30974ab-20240613"
45
+ "react": "^19.0.0-rc-fb9a90fa48-20240614",
46
+ "react-dom": "^19.0.0-rc-fb9a90fa48-20240614"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@swc/cli": "^0.3.12",
50
- "@swc/core": "^1.5.29",
50
+ "@swc/core": "^1.6.1",
51
51
  "@types/jsonwebtoken": "^9.0.6",
52
52
  "@types/node": "^20.14.2",
53
53
  "@types/react": "^18.3.3",
54
54
  "@types/react-dom": "^18.3.0",
55
55
  "rimraf": "^5.0.7",
56
- "typescript": "^5.6.0-dev.20240614"
56
+ "typescript": "^5.6.0-dev.20240616"
57
57
  },
58
58
  "engines": {
59
59
  "node": "^22.3.0"