-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathAuthenticatedGetClientFromRequestTrait.php
More file actions
58 lines (49 loc) · 1.9 KB
/
AuthenticatedGetClientFromRequestTrait.php
File metadata and controls
58 lines (49 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
/*
* This file is part of the simplesamlphp-module-oidc.
*
* Copyright (C) 2018 by the Spanish Research and Academic Network.
*
* This code was developed by Universidad de Córdoba (UCO https://www.uco.es)
* for the RedIRIS SIR service (SIR: http://www.rediris.es/sir)
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SimpleSAML\Module\oidc\Controllers\Traits;
use Psr\Http\Message\ServerRequestInterface;
use SimpleSAML\Error;
use SimpleSAML\Module\oidc\Entities\Interfaces\ClientEntityInterface;
use SimpleSAML\Module\oidc\Repositories\ClientRepository;
use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException;
use SimpleSAML\Module\oidc\Services\AuthContextService;
trait AuthenticatedGetClientFromRequestTrait
{
protected ClientRepository $clientRepository;
private AuthContextService $authContextService;
/**
* @throws \JsonException
* @throws \SimpleSAML\Error\BadRequest
* @throws \SimpleSAML\Error\Exception
* @throws \SimpleSAML\Error\NotFound
* @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
*/
protected function getClientFromRequest(ServerRequestInterface $request): ClientEntityInterface
{
$params = $request->getQueryParams();
$clientId = empty($params['client_id']) ? null : (string)$params['client_id'];
if (!is_string($clientId)) {
throw new Error\BadRequest('Client id is missing.');
}
$authedUser = null;
if (!$this->authContextService->isSspAdmin()) {
$authedUser = $this->authContextService->getAuthUserId();
}
$client = $this->clientRepository->findById($clientId, $authedUser);
if (!$client) {
throw OidcServerException::invalidClient($request);
}
return $client;
}
}