@@ -222,14 +222,52 @@ func (s *Usersynchronizer) zitadelUserSync(ctx context.Context, googleUsers []*g
222
222
offset += uint64 (limit )
223
223
}
224
224
for _ , gu := range googleUsers {
225
- // TODO: Add support for updating email / name of existing users
226
- if _ , exists := existingUsers [gu .ID ]; exists {
225
+ if u , exists := existingUsers [gu .ID ]; exists {
226
+ name := u .GetHuman ().GetProfile ().GetDisplayName ()
227
+ guName := gu .Name .GivenName + " " + gu .Name .FamilyName
228
+ email := u .GetHuman ().GetEmail ().GetEmail ()
229
+
230
+ if name != guName || email != gu .Email {
231
+ log := s .log .WithFields (logrus.Fields {
232
+ "name" : guName ,
233
+ "email" : gu .Email ,
234
+ "old_name" : name ,
235
+ "old_email" : email ,
236
+ })
237
+ log .Debugf ("update user in Zitadel" )
238
+ _ , err := s .zitadelClient .UpdateHumanUser (ctx , & zitadelgrpcuser.UpdateHumanUserRequest {
239
+ UserId : gu .ID ,
240
+ Username : & gu .Email ,
241
+ Profile : & zitadelgrpcuser.SetHumanProfile {
242
+ GivenName : gu .Name .GivenName ,
243
+ FamilyName : gu .Name .FamilyName ,
244
+ DisplayName : & guName ,
245
+ },
246
+ Email : & zitadelgrpcuser.SetHumanEmail {
247
+ Email : gu .Email ,
248
+ Verification : & zitadelgrpcuser.SetHumanEmail_IsVerified {
249
+ IsVerified : true ,
250
+ },
251
+ },
252
+ })
253
+ if err != nil {
254
+ log .WithError (err ).Errorf ("update user in Zitadel" )
255
+ }
256
+ }
257
+
227
258
delete (existingUsers , gu .ID )
228
259
continue
229
260
}
230
261
262
+ log := s .log .WithFields (logrus.Fields {
263
+ "given_name" : gu .Name .GivenName ,
264
+ "family_name" : gu .Name .FamilyName ,
265
+ "email" : gu .Email ,
266
+ })
267
+ log .Debugf ("add user to Zitadel" )
231
268
_ , err := s .zitadelClient .AddHumanUser (ctx , & zitadelgrpcuser.AddHumanUserRequest {
232
- UserId : ptr .To (gu .ID ),
269
+ UserId : & gu .ID ,
270
+ Username : & gu .Email ,
233
271
Email : & zitadelgrpcuser.SetHumanEmail {
234
272
Email : gu .Email ,
235
273
Verification : & zitadelgrpcuser.SetHumanEmail_IsVerified {
@@ -242,8 +280,9 @@ func (s *Usersynchronizer) zitadelUserSync(ctx context.Context, googleUsers []*g
242
280
},
243
281
},
244
282
Profile : & zitadelgrpcuser.SetHumanProfile {
245
- GivenName : gu .Name .GivenName ,
246
- FamilyName : gu .Name .FamilyName ,
283
+ GivenName : gu .Name .GivenName ,
284
+ FamilyName : gu .Name .FamilyName ,
285
+ DisplayName : ptr .To (gu .Name .GivenName + " " + gu .Name .FamilyName ),
247
286
},
248
287
IdpLinks : []* zitadelgrpcuser.IDPLink {
249
288
{
@@ -254,14 +293,20 @@ func (s *Usersynchronizer) zitadelUserSync(ctx context.Context, googleUsers []*g
254
293
},
255
294
})
256
295
if err != nil {
257
- s .log .WithError (err ).Errorf ("add user in Zitadel" )
296
+ log .WithError (err ).Errorf ("add user to Zitadel" )
297
+ continue
258
298
}
259
299
}
260
300
261
- for userID := range existingUsers {
262
- s .log .WithField ("user_id" , userID ).Debugf ("delete Zitadel user" )
301
+ for userID , user := range existingUsers {
302
+ log := s .log .WithFields (logrus.Fields {
303
+ "user_id" : userID ,
304
+ "name" : user .GetHuman ().GetProfile ().GetDisplayName (),
305
+ "email" : user .GetHuman ().GetEmail ().GetEmail (),
306
+ })
307
+ log .Debugf ("delete user from Zitadel" )
263
308
if _ , err := s .zitadelClient .DeleteUser (ctx , & zitadelgrpcuser.DeleteUserRequest {UserId : userID }); err != nil {
264
- s . log .WithError (err ).Errorf ("delete user in Zitadel" )
309
+ log .WithError (err ).Errorf ("delete user from Zitadel" )
265
310
}
266
311
}
267
312
}
0 commit comments