@@ -18,7 +18,10 @@ export default buildConfig({
1818 baseDir : path . resolve ( dirname ) ,
1919 } ,
2020 components : {
21- afterLogin : [ "src/components/OAuthLoginButton#OAuthLoginButton" ] ,
21+ afterLogin : [
22+ "src/components/GoogleOAuthLoginButton#GoogleOAuthLoginButton" ,
23+ "src/components/ZitadelOAuthLoginButton#ZitadelOAuthLoginButton" ,
24+ ] ,
2225 } ,
2326 user : Users . slug ,
2427 } ,
@@ -44,6 +47,7 @@ export default buildConfig({
4447 clientId : process . env . GOOGLE_CLIENT_ID || "" ,
4548 clientSecret : process . env . GOOGLE_CLIENT_SECRET || "" ,
4649 authorizePath : "/oauth/google" ,
50+ callbackPath : "/oauth/google/callback" ,
4751 authCollection : "users" ,
4852 tokenEndpoint : "https://oauth2.googleapis.com/token" ,
4953 scopes : [
@@ -68,6 +72,51 @@ export default buildConfig({
6872 return "/admin/login" ;
6973 } ,
7074 } ) ,
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+ } ) ,
71120 ] ,
72121 sharp,
73122} ) ;
0 commit comments