Skip to content

Commit 901c775

Browse files
committed
add documentation
1 parent 3306c81 commit 901c775

File tree

3 files changed

+101
-15
lines changed

3 files changed

+101
-15
lines changed

Diff for: Controller/IntrospectionController.php

+23-15
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,7 @@ public function __construct(
7070

7171
public function introspectAction(Request $request): JsonResponse
7272
{
73-
$clientToken = $this->tokenStorage->getToken(); // → use in security
74-
75-
if (!$clientToken instanceof OAuthToken) {
76-
throw new AccessDeniedException('The introspect endpoint must be behind a secure firewall.');
77-
}
78-
79-
$callerToken = $this->accessTokenManager->findTokenByToken($clientToken->getToken());
80-
81-
if (!$callerToken) {
82-
throw new AccessDeniedException('The access token must have a valid token.');
83-
}
84-
85-
if (!in_array($callerToken->getClientId(), $this->allowedIntrospectionClients)) {
86-
throw new AccessDeniedException('This access token is not autorised to do introspection.');
87-
}
73+
$this->denyAccessIfNotAuthorizedClient();
8874

8975
$token = $this->getToken($request);
9076

@@ -106,6 +92,28 @@ public function introspectAction(Request $request): JsonResponse
10692
]);
10793
}
10894

95+
/**
96+
* Check that the caller has a token generated by an allowed client
97+
*/
98+
private function denyAccessIfNotAuthorizedClient(): void
99+
{
100+
$clientToken = $this->tokenStorage->getToken();
101+
102+
if (!$clientToken instanceof OAuthToken) {
103+
throw new AccessDeniedException('The introspect endpoint must be behind a secure firewall.');
104+
}
105+
106+
$callerToken = $this->accessTokenManager->findTokenByToken($clientToken->getToken());
107+
108+
if (!$callerToken) {
109+
throw new AccessDeniedException('The access token must have a valid token.');
110+
}
111+
112+
if (!in_array($callerToken->getClientId(), $this->allowedIntrospectionClients)) {
113+
throw new AccessDeniedException('This access token is not autorised to do introspection.');
114+
}
115+
}
116+
109117
/**
110118
* @return TokenInterface|null
111119
*/

Diff for: Resources/doc/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -624,3 +624,5 @@ The `authorize` endpoint is at `/oauth/v2/auth` by default (see `Resources/confi
624624
[Adding Grant Extensions](adding_grant_extensions.md)
625625

626626
[Custom DB Driver](custom_db_driver.md)
627+
628+
[Introspection endpoint](introspection_endpoint.md)

Diff for: Resources/doc/introspection_endpoint.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
Introspection endpoint
2+
=========================================
3+
4+
The OAuth 2.0 Token Introspection extension defines a protocol that returns information about an access token, intended to be used by resource servers or other internal servers.
5+
6+
For more information, see [this explaination](https://www.oauth.com/oauth2-servers/token-introspection-endpoint/) or [the RFC 7662](https://tools.ietf.org/html/rfc7662).
7+
8+
## Configuration
9+
10+
Import the routing.yml configuration file in `app/config/routing.yml`:
11+
12+
```yaml
13+
# app/config/routing.yml
14+
15+
fos_oauth_server_introspection:
16+
resource: "@FOSOAuthServerBundle/Resources/config/routing/introspection.xml"
17+
```
18+
19+
Add FOSOAuthServerBundle settings in `app/config/config.yml`:
20+
21+
```yaml
22+
fos_oauth_server:
23+
introspection:
24+
allowed_clients:
25+
- 1_wUS0gjHdHyC2qeBL3u7RuIrIXClt6irL # an oauth client used only for token introspection.
26+
```
27+
28+
The allowed clients MUST be clients as defined [here](index.md#creating-a-client) and SHOULD be used only for token introspection (otherwise a endpoint client might call the introspection endpoint with its valid token).
29+
30+
31+
The introspection endpoint must be behind a firewall defined like this:
32+
33+
```yaml
34+
# app/config/security.yml
35+
security:
36+
firewalls:
37+
oauth_introspect:
38+
host: "%domain.oauth2%"
39+
pattern: ^/oauth/v2/introspect
40+
fos_oauth: true
41+
stateless: true
42+
anonymous: false
43+
```
44+
45+
### Usage
46+
47+
Then you can call the introspection endpoint like this:
48+
49+
```
50+
POST /token_info
51+
Host: authorization-server.com
52+
Authorization: Bearer KvIu5v90GqgDctofFXP8npjC5DzMUkci
53+
54+
token=SON4N82oVuRFykExk0iGTghihgOcI6bm
55+
```
56+
57+
The JSON response will look like this if the token is inactive:
58+
59+
```json
60+
{
61+
"active": false
62+
}
63+
```
64+
65+
If the token is active, the response will look like this:
66+
67+
```json
68+
{
69+
"active": true,
70+
"scope": "scope1 scope2",
71+
"client_id": "2_HC1KF0UrawHx05AxgNEeKJF10giBUOHZ",
72+
"username": "foobar",
73+
"token_type": "access_token",
74+
"exp": 1534921182
75+
}
76+
```

0 commit comments

Comments
 (0)