File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -137,4 +137,30 @@ public function extendEditForm(
137137 public function hasSetupStep () {
138138 return true ;
139139 }
140+
141+ public function processLoginRequest ( PhabricatorAuthLoginController $ controller ) {
142+ list ($ account , $ response ) = parent ::processLoginRequest ($ controller );
143+
144+ // hack:
145+ // After logging in via authentik try to link the external account to an existing
146+ // phabricator user with the same username.
147+ // This prevents triggering account registration for old users who
148+ // had an account created with LDAP - before authentik was in use.
149+ if ($ account && !$ account ->getUserPHID ()) {
150+
151+ $ user = id (new PhabricatorUser ())->loadOneWhere (
152+ 'username = %s ' ,
153+ $ account ->getUsername ());
154+ if ($ user ) {
155+ $ account ->setUserPHID ($ user ->getPHID ());
156+ // Disable CSRF protection, we are coming back from authentik.
157+ // If we got here this means that the code flow was successful,
158+ // so there is no CSRF risk.
159+ AphrontWriteGuard::beginUnguardedWrites ();
160+ $ account ->save ();
161+ AphrontWriteGuard::endUnguardedWrites ();
162+ }
163+ }
164+ return array ($ account , $ response );
165+ }
140166}
You can’t perform that action at this time.
0 commit comments