@@ -4,7 +4,8 @@ import path from "path";
44import { buildConfig } from "payload" ;
55import sharp from "sharp" ;
66import { fileURLToPath } from "url" ;
7- import { OAuth2Plugin } from "../../src/plugin" ;
7+ import { googleOAuth } from "../../examples/google" ;
8+ import { zitadelOAuth } from "../../examples/zitadel" ;
89import Users from "./collections/Users" ;
910import { migrations } from "./migrations" ;
1011
@@ -33,90 +34,6 @@ export default buildConfig({
3334 editor : lexicalEditor ( { } ) ,
3435 collections : [ Users ] ,
3536 typescript : { outputFile : path . resolve ( dirname , "payload-types.ts" ) } ,
36- plugins : [
37- ////////////////////////////////////////////////////////////////////////////
38- // Google OAuth
39- ////////////////////////////////////////////////////////////////////////////
40- OAuth2Plugin ( {
41- enabled :
42- typeof process . env . GOOGLE_CLIENT_ID === "string" &&
43- typeof process . env . GOOGLE_CLIENT_SECRET === "string" ,
44- strategyName : "google" ,
45- useEmailAsIdentity : true ,
46- serverURL : process . env . NEXT_PUBLIC_URL || "http://localhost:3000" ,
47- clientId : process . env . GOOGLE_CLIENT_ID || "" ,
48- clientSecret : process . env . GOOGLE_CLIENT_SECRET || "" ,
49- authorizePath : "/oauth/google" ,
50- callbackPath : "/oauth/google/callback" ,
51- authCollection : "users" ,
52- tokenEndpoint : "https://oauth2.googleapis.com/token" ,
53- scopes : [
54- "openid" ,
55- "https://www.googleapis.com/auth/userinfo.email" ,
56- "https://www.googleapis.com/auth/userinfo.profile" ,
57- ] ,
58- providerAuthorizationUrl : "https://accounts.google.com/o/oauth2/v2/auth" ,
59- getUserInfo : async ( accessToken : string ) => {
60- const response = await fetch (
61- "https://www.googleapis.com/oauth2/v3/userinfo" ,
62- { headers : { Authorization : `Bearer ${ accessToken } ` } } ,
63- ) ;
64- const user = await response . json ( ) ;
65- return { email : user . email , sub : user . sub } ;
66- } ,
67- successRedirect : ( req ) => {
68- return "/admin" ;
69- } ,
70- failureRedirect : ( req , err ) => {
71- req . payload . logger . error ( err ) ;
72- return "/admin/login" ;
73- } ,
74- } ) ,
75- ////////////////////////////////////////////////////////////////////////////
76- // Zitadel OAuth
77- ////////////////////////////////////////////////////////////////////////////
78- OAuth2Plugin ( {
79- enabled :
80- typeof process . env . ZITADEL_CLIENT_ID === "string" &&
81- typeof process . env . ZITADEL_CLIENT_SECRET === "string" &&
82- typeof process . env . ZITADEL_TOKEN_ENDPOINT === "string" &&
83- typeof process . env . ZITADEL_AUTHORIZATION_URL === "string" &&
84- typeof process . env . ZITADEL_USERINFO_ENDPOINT === "string" ,
85- strategyName : "zitadel" ,
86- useEmailAsIdentity : true ,
87- serverURL : process . env . NEXT_PUBLIC_URL || "http://localhost:3000" ,
88- clientId : process . env . ZITADEL_CLIENT_ID || "" ,
89- clientSecret : process . env . ZITADEL_CLIENT_SECRET || "" ,
90- authorizePath : "/oauth/zitadel" ,
91- callbackPath : "/oauth/zitadel/callback" ,
92- authCollection : "users" ,
93- tokenEndpoint : process . env . ZITADEL_TOKEN_ENDPOINT || "" ,
94- scopes : [
95- "openid" ,
96- "profile" ,
97- "email" ,
98- "offline_access" ,
99- "urn:zitadel:iam:user:metadata" ,
100- ] ,
101- providerAuthorizationUrl : process . env . ZITADEL_AUTHORIZATION_URL || "" ,
102- getUserInfo : async ( accessToken : string ) => {
103- const response = await fetch (
104- process . env . ZITADEL_USERINFO_ENDPOINT || "" ,
105- {
106- headers : { Authorization : `Bearer ${ accessToken } ` } ,
107- } ,
108- ) ;
109- const user = await response . json ( ) ;
110- return { email : user . email , sub : user . sub } ;
111- } ,
112- successRedirect : ( req ) => {
113- return "/admin" ;
114- } ,
115- failureRedirect : ( req , err ) => {
116- req . payload . logger . error ( err ) ;
117- return "/admin/login" ;
118- } ,
119- } ) ,
120- ] ,
37+ plugins : [ googleOAuth , zitadelOAuth ] ,
12138 sharp,
12239} ) ;
0 commit comments