-
Notifications
You must be signed in to change notification settings - Fork 451
/
documentation.php
42 lines (36 loc) · 1.23 KB
/
documentation.php
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
<?php
namespace Concrete\Controller\Api;
use Concrete\Controller\Backend\UserInterface as BackendInterfaceController;
use Concrete\Core\Api\Documentation\RedirectUriFactory;
use Concrete\Core\Entity\OAuth\ClientRepository;
use Concrete\Core\Permission\Checker;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
class Documentation extends BackendInterfaceController
{
protected $viewPath = '/api/documentation';
/**
* @return bool
*/
protected function canAccess()
{
$checker = new Checker();
return $checker->canAccessApi(); // `access_api` custom task permission
}
public function view($clientId)
{
/**
* @var $clientRepository ClientRepository
*/
$clientRepository = $this->app->make(ClientRepositoryInterface::class);
$client = $clientRepository->findOneByIdentifier($clientId);
if ($client) {
$this->set('clientKey', $client->getClientKey());
$this->set(
'oauth2RedirectUrl',
$this->app->make(RedirectUriFactory::class)->createDocumentationRedirectUri($client)
);
} else {
throw new \Exception(t('Invalid API client.'));
}
}
}