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