|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
|
9
|
|
|
* |
|
10
|
|
|
* This software may be modified and distributed under the terms |
|
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace OAuth2Framework\SecurityBundle\Tests\TestBundle\Controller; |
|
15
|
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Core\AccessToken\AccessToken; |
|
17
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
18
|
|
|
use OAuth2Framework\SecurityBundle\Annotation\OAuth2; |
|
19
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @Route("/api") |
|
25
|
|
|
*/ |
|
26
|
|
|
class ApiController extends Controller |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @param string $name |
|
30
|
|
|
* |
|
31
|
|
|
* @return Response |
|
32
|
|
|
* |
|
33
|
|
|
* @Route("/hello/{name}", name="api_hello") |
|
34
|
|
|
*/ |
|
35
|
|
|
public function serviceAction(string $name) |
|
36
|
|
|
{ |
|
37
|
|
|
return new JsonResponse(['name' => $name, 'message' => sprintf('Hello %s!', $name)]); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return Response |
|
42
|
|
|
* |
|
43
|
|
|
* @OAuth2(scope="profile openid") |
|
44
|
|
|
* @Route("/hello-profile", name="api_scope") |
|
45
|
|
|
*/ |
|
46
|
|
|
public function scopeProtectionAction() |
|
47
|
|
|
{ |
|
48
|
|
|
return new JsonResponse(['name' => 'I am protected by scope', 'message' => 'Hello!']); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return Response |
|
53
|
|
|
* |
|
54
|
|
|
* @OAuth2(token_type="MAC") |
|
55
|
|
|
* @Route("/hello-token", name="api_token") |
|
56
|
|
|
*/ |
|
57
|
|
|
public function tokenTypeProtectionAction() |
|
58
|
|
|
{ |
|
59
|
|
|
return new JsonResponse(['name' => 'I am protected by scope', 'message' => 'Hello!']); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @Route("/hello-resolver", name="api_resolver") |
|
64
|
|
|
* |
|
65
|
|
|
* @param AccessToken $accessToken |
|
66
|
|
|
* |
|
67
|
|
|
* @return Response |
|
68
|
|
|
*/ |
|
69
|
|
|
public function accessTokenResolverAction(AccessToken $accessToken) |
|
70
|
|
|
{ |
|
71
|
|
|
return new JsonResponse($accessToken); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|