Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau committed Mar 23, 2021
1 parent 1159435 commit 9788ea6
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 15 deletions.
38 changes: 23 additions & 15 deletions Controller/IntrospectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,7 @@ public function __construct(

public function introspectAction(Request $request): JsonResponse
{
$clientToken = $this->tokenStorage->getToken(); // → use in security

if (!$clientToken instanceof OAuthToken) {
throw new AccessDeniedException('The introspect endpoint must be behind a secure firewall.');
}

$callerToken = $this->accessTokenManager->findTokenByToken($clientToken->getToken());

if (!$callerToken) {
throw new AccessDeniedException('The access token must have a valid token.');
}

if (!in_array($callerToken->getClientId(), $this->allowedIntrospectionClients)) {
throw new AccessDeniedException('This access token is not autorised to do introspection.');
}
$this->denyAccessIfNotAuthorizedClient();

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

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

/**
* Check that the caller has a token generated by an allowed client
*/
private function denyAccessIfNotAuthorizedClient(): void
{
$clientToken = $this->tokenStorage->getToken();

if (!$clientToken instanceof OAuthToken) {
throw new AccessDeniedException('The introspect endpoint must be behind a secure firewall.');
}

$callerToken = $this->accessTokenManager->findTokenByToken($clientToken->getToken());

if (!$callerToken) {
throw new AccessDeniedException('The access token must have a valid token.');
}

if (!in_array($callerToken->getClientId(), $this->allowedIntrospectionClients)) {
throw new AccessDeniedException('This access token is not autorised to do introspection.');
}
}

/**
* @return TokenInterface|null
*/
Expand Down
2 changes: 2 additions & 0 deletions Resources/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -624,3 +624,5 @@ The `authorize` endpoint is at `/oauth/v2/auth` by default (see `Resources/confi
[Adding Grant Extensions](adding_grant_extensions.md)

[Custom DB Driver](custom_db_driver.md)

[Introspection endpoint](introspection_endpoint.md)
76 changes: 76 additions & 0 deletions Resources/doc/introspection_endpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Introspection endpoint
=========================================

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.

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).

## Configuration

Import the routing.yml configuration file in `app/config/routing.yml`:

```yaml
# app/config/routing.yml

fos_oauth_server_introspection:
resource: "@FOSOAuthServerBundle/Resources/config/routing/introspection.xml"
```
Add FOSOAuthServerBundle settings in `app/config/config.yml`:

```yaml
fos_oauth_server:
introspection:
allowed_clients:
- 1_wUS0gjHdHyC2qeBL3u7RuIrIXClt6irL # an oauth client used only for token introspection.
```

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).


The introspection endpoint must be behind a firewall defined like this:

```yaml
# app/config/security.yml
security:
firewalls:
oauth_introspect:
host: "%domain.oauth2%"
pattern: ^/oauth/v2/introspect
fos_oauth: true
stateless: true
anonymous: false
```

### Usage

Then you can call the introspection endpoint like this:

```
POST /token_info
Host: authorization-server.com
Authorization: Bearer KvIu5v90GqgDctofFXP8npjC5DzMUkci
token=SON4N82oVuRFykExk0iGTghihgOcI6bm
```

The JSON response will look like this if the token is inactive:

```json
{
"active": false
}
```

If the token is active, the response will look like this:

```json
{
"active": true,
"scope": "scope1 scope2",
"client_id": "2_HC1KF0UrawHx05AxgNEeKJF10giBUOHZ",
"username": "foobar",
"token_type": "access_token",
"exp": 1534921182
}
```

0 comments on commit 9788ea6

Please sign in to comment.