Skip to content

Commit 98e0a8f

Browse files
committed
Adding an endpoint that looks up a user by an external id.
1 parent 05c68fa commit 98e0a8f

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

app/V1Module/presenters/UsersPresenter.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,29 @@ public function actionDetail(string $id)
214214
$this->sendSuccessResponse($this->userViewFactory->getUser($user));
215215
}
216216

217+
public function checkFindByExternalLogin(string $service, string $externalId)
218+
{
219+
$user = $this->externalLogins->getUser($service, $externalId);
220+
if (!$user) {
221+
throw new NotFoundException("User with given external login not found.");
222+
}
223+
if (!$this->userAcl->canViewPublicData($user)) {
224+
throw new ForbiddenRequestException();
225+
}
226+
}
227+
228+
/**
229+
* Get details of a user identified via external login.
230+
* @GET
231+
*/
232+
#[Path("service", new VString(1), "External authentication service name", required: true)]
233+
#[Path("externalId", new VString(1), "External user identifier", required: true)]
234+
public function actionFindByExternalLogin(string $service, string $externalId)
235+
{
236+
$user = $this->externalLogins->getUser($service, $externalId);
237+
$this->sendSuccessResponse($user ? $this->userViewFactory->getUser($user) : null);
238+
}
239+
217240
public function checkDelete(string $id)
218241
{
219242
$user = $this->users->findOrThrow($id);

app/V1Module/router/RouterFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ private static function createUsersRoutes(string $prefix): RouteList
506506
$router[] = new PostRoute("$prefix/accept-invitation", "Registration:acceptInvitation");
507507

508508
$router[] = new GetRoute("$prefix/<id>", "Users:detail");
509+
$router[] = new GetRoute("$prefix/external-login/<service>/<externalId>", "Users:findByExternalLogin");
509510
$router[] = new PostRoute("$prefix/<id>/invalidate-tokens", "Users:invalidateTokens");
510511
$router[] = new DeleteRoute("$prefix/<id>", "Users:delete");
511512
$router[] = new GetRoute("$prefix/<id>/groups", "Users:groups");

0 commit comments

Comments
 (0)