@@ -343,20 +343,26 @@ public function onCallback(Request $request)
343
343
344
344
$ this ->debug ();
345
345
346
- $ userName = $ data ['preferred_username ' ];
346
+ $ usegroups = isset ($ this ->config ['usegroups ' ]) ? $ this ->config ['usegroups ' ] : false ;
347
+ $ idKey = isset ($ this ->config ['fieldmap ' ]['id ' ]) ? $ this ->config ['fieldmap ' ]['id ' ] : 'sub ' ;
348
+ $ loginKey = isset ($ this ->config ['fieldmap ' ]['login ' ]) ? $ this ->config ['fieldmap ' ]['login ' ] : 'email ' ;
349
+ $ firstnameKey = isset ($ this ->config ['fieldmap ' ]['firstname ' ]) ? $ this ->config ['fieldmap ' ]['firstname ' ] : 'given_name ' ;
350
+ $ lastnameKey = isset ($ this ->config ['fieldmap ' ]['lastname ' ]) ? $ this ->config ['fieldmap ' ]['lastname ' ] : 'family_name ' ;
351
+ $ emailKey = isset ($ this ->config ['fieldmap ' ]['email ' ]) ? $ this ->config ['fieldmap ' ]['email ' ] : 'email ' ;
352
+ $ groupsKey = isset ($ this ->config ['fieldmap ' ]['groups ' ]) ? $ this ->config ['fieldmap ' ]['groups ' ] : 'groups ' ;
353
+ $ distantUserId = $ data ['sub ' ];
347
354
348
- if (!\Swift_Validate::email ($ userName ) && isset ($ data ['email ' ])) {
349
- $ userName = $ data [ 'email ' ] ;// login to be an email
355
+ if (!\Swift_Validate::email ($ data [ $ loginKey ] ) && isset ($ data ['email ' ])) {
356
+ $ loginKey = 'email ' ;// login to be an email
350
357
}
351
358
352
- $ usegroups = isset ($ this ->config ['usegroups ' ]) ? $ this ->config ['usegroups ' ] : false ;
353
359
$ userUA = $ this ->CreateUser ([
354
- 'id ' => $ distantUserId = $ data [' sub ' ],
355
- 'login ' => $ userName ,
356
- 'firstname ' => isset ($ data [' given_name ' ]) ? $ data [' given_name ' ] : '' ,
357
- 'lastname ' => isset ($ data [' family_name ' ]) ? $ data [' family_name ' ] : '' ,
358
- 'email ' => isset ($ data [' email ' ]) ? $ data [' email ' ] : '' ,
359
- '_groups ' => isset ($ data [' groups ' ]) && $ usegroups ? $ data [' groups ' ] : ''
360
+ 'id ' => $ data [$ idKey ],
361
+ 'login ' => $ userName = $ data [ $ loginKey ] ,
362
+ 'firstname ' => isset ($ data [$ firstnameKey ]) ? $ data [$ firstnameKey ] : '' ,
363
+ 'lastname ' => isset ($ data [$ lastnameKey ]) ? $ data [$ lastnameKey ] : '' ,
364
+ 'email ' => isset ($ data [$ emailKey ]) ? $ data [$ emailKey ] : '' ,
365
+ '_groups ' => isset ($ data [$ groupsKey ]) && $ usegroups ? $ this -> filterGroups ( $ data [$ groupsKey ]) : ''
360
366
]);
361
367
362
368
$ userAuthProviderRepository = $ this ->getUsrAuthProviderRepository ();
@@ -715,6 +721,36 @@ private function CreateUser(Array $data)
715
721
return $ ret ;
716
722
}
717
723
724
+ private function filterGroups ($ groups )
725
+ {
726
+ $ this ->debug (sprintf ("filtering openid groups : \n%s " , print_r ($ groups , true )));
727
+
728
+ $ ret = [];
729
+ if ($ this ->config ['groupmask ' ]) {
730
+ $ this ->debug (sprintf ("filtering groups with regexp : \"%s \"" , $ this ->config ['groupmask ' ]));
731
+ foreach ($ groups as $ grp ) {
732
+ $ matches = [];
733
+ $ retpreg = preg_match_all ($ this ->config ['groupmask ' ], $ grp , $ matches , PREG_SET_ORDER );
734
+
735
+ $ this ->debug (sprintf ("preg_match('%s', '%s', ...) \n - returned %s \n - matches = %s "
736
+ , $ this ->config ['groupmask ' ], $ grp
737
+ , print_r ($ retpreg , true ), print_r ($ matches , true )));
738
+
739
+ foreach ($ matches as $ match ) {
740
+ if (count ($ match )>0 && isset ($ match [1 ]) && !array_key_exists ($ match [1 ], $ ret )) {
741
+ $ ret [] = $ match [1 ];
742
+ }
743
+ }
744
+ }
745
+ } else {
746
+ $ this ->debug (sprintf ("no groupmask defined, openid groups ignored " ));
747
+ }
748
+
749
+ $ this ->debug (sprintf ("filtered groups : \n%s " , print_r ($ ret , true )));
750
+
751
+ return empty ($ ret ) ? '' : $ ret ;
752
+ }
753
+
718
754
719
755
720
756
/**
0 commit comments