Skip to content

Commit 93acae2

Browse files
committed
Autolink authentik accounts to existing phabricator users
1 parent a511987 commit 93acae2

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

extensions/PhabricatorPhabricatorAuthProvider.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)