1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMG\ManagerBundle\Controller; |
4
|
|
|
|
5
|
|
|
use FOS\RestBundle\Controller\Annotations; |
6
|
|
|
use FOS\RestBundle\Controller\FOSRestController; |
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
8
|
|
|
use SMG\OauthBundle\Entity\Client; |
9
|
|
|
|
10
|
|
|
class ClientsController extends FOSRestController |
11
|
|
|
{ |
12
|
|
|
use Traits\TokenFromHeaderTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* List all oauth clients created. |
16
|
|
|
*/ |
17
|
|
|
public function getClientsAction() |
18
|
|
|
{ |
19
|
|
|
$this->throwIfClientNot('backend'); |
20
|
|
|
$clientManager = $this->get( |
21
|
|
|
'fos_oauth_server.client_manager.default' |
22
|
|
|
); |
23
|
|
|
|
24
|
|
|
$class = $clientManager->getClass(); |
25
|
|
|
|
26
|
|
|
return $this->getDoctrine()->getRepository($class)->findAll(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Create a new oauth client. |
31
|
|
|
* |
32
|
|
|
* @param Client $client Client posted by the caller |
33
|
|
|
* |
34
|
|
|
* @Annotations\Post("/clients") |
35
|
|
|
* |
36
|
|
|
* @ParamConverter( |
37
|
|
|
* "client", |
38
|
|
|
* converter="fos_rest.request_body" |
39
|
|
|
* ) |
40
|
|
|
* |
41
|
|
|
* @return Client |
42
|
|
|
*/ |
43
|
|
|
public function postClientAction(Client $client) |
44
|
|
|
{ |
45
|
|
|
$this->throwIfClientNot('backend'); |
46
|
|
|
|
47
|
|
|
$clientManager = $this->get( |
48
|
|
|
'fos_oauth_server.client_manager.default' |
49
|
|
|
); |
50
|
|
|
$newClient = $clientManager->createClient(); |
51
|
|
|
|
52
|
|
|
$newClient->setType($client->getType()); |
53
|
|
|
$newClient->setMeta($client->getMeta()); |
54
|
|
|
if ($client->getAllowedGrantTypes() !== null) { |
55
|
|
|
$newClient->setAllowedGrantTypes($client->getAllowedGrantTypes()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$clientManager->updateClient($newClient); |
59
|
|
|
|
60
|
|
|
return $newClient; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|