Validate access tokens sent by developers using a third-party OAuth 2.0 Authorization Server, by leveraging its Introspection Endpoint (RFC 7662). This plugin assumes that the Consumer already has an access token that will be validated against a third-party OAuth 2.0 server.
Configuration Reference
Enable the plugin on a service
Enable the plugin on a route
Enable the plugin globally
A plugin which is not associated to any service, route, or consumer is considered global, and will be run on every request. Read the Plugin Reference and the Plugin Precedence sections for more information.
Parameters
Here's a list of all the parameters which can be used in this plugin's configuration:
Form Parameter | Description |
---|---|
name
required Type: string |
The name of the plugin, in this case oauth2-introspection . |
service.id
Type: string |
The ID of the Service the plugin targets. |
route.id
Type: string |
The ID of the Route the plugin targets. |
enabled
required Type: boolean Default value: true |
Whether this plugin will be applied. |
api_id
Type: string |
The ID of the API the plugin targets.
Note: The API Entity is deprecated in favor of Services since CE 0.13.0 and EE 0.32. |
config.introspection_url
|
The full URL to the third-party introspection endpoint |
config.authorization_value
|
The value to append to the Authorization header when requesting the introspection endpoint |
config.token_type_hint
optional |
The token_type_hint value to associate to introspection requests |
config.ttl
optional Default value: 60
|
The TTL in seconds for the introspection response - set to 0 to disable the expiration |
config.hide_credentials
optional |
An optional boolean value telling the plugin to hide the credential to the upstream API server. It will be removed by Kong before proxying the request. |
config.timeout
optional Default value: 10000
|
An optional timeout in milliseconds when sending data to the upstream server |
config.keepalive
optional Default value: 60000
|
An optional value in milliseconds that defines for how long an idle connection will live before being closed |
config.anonymous
optional |
An optional string (consumer uuid) value to use as an “anonymous” consumer if authentication fails. If empty (default), the request will fail with an authentication failure 4xx. |
config.run_on_preflight
optional Default value: true
|
A boolean value that indicates whether the plugin should run (and try to authenticate) on |
config.consumer_by
optional Default value: username
|
A string indicating whether to associate oauth2 |
config.introspect_request
optional Default value: false
|
A boolean indicating whether to forward information about the current
downstream request to the introspect endpoint. If true, headers
|
config.custom_introspection_headers
optional |
A list of custom headers to be added in the introspection request |
config.custom_claims_forward
optional |
A list of custom claims to be forwarded from the introspection response
to the upstream request. Claims are forwarded in headers with prefix
|
Flow
Associate the response to a Consumer
To associate the introspection response resolution to a Kong Consumer, you will have to provision a Kong Consumer with the same username
returned by the Introspection Endpoint response.
Upstream Headers
When a client has been authenticated, the plugin will append some headers to the request before proxying it to the upstream API/Microservice, so that you can identify the consumer in your code:
X-Consumer-ID
, the ID of the Consumer on Kong (if matched)X-Consumer-Custom-ID
, thecustom_id
of the Consumer (if matched and if existing)X-Consumer-Username
, theusername of
the Consumer (if matched and if existing)X-Anonymous-Consumer
, will be set to true when authentication failed, and the ‘anonymous’ consumer was set instead.X-Credential-Scope
, as returned by the Introspection response (if any)X-Credential-Client-ID
, as returned by the Introspection response (if any)X-Credential-Username
, as returned by the Introspection response (if any)X-Credential-Token-Type
, as returned by the Introspection response (if any)X-Credential-Exp
, as returned by the Introspection response (if any)X-Credential-Iat
, as returned by the Introspection response (if any)X-Credential-Nbf
, as returned by the Introspection response (if any)X-Credential-Sub
, as returned by the Introspection response (if any)X-Credential-Aud
, as returned by the Introspection response (if any)X-Credential-Iss
, as returned by the Introspection response (if any)X-Credential-Jti
, as returned by the Introspection response (if any)
Additionally, any claims specified in config.custom_claims_forward
will also be forwarded with the X-Credential-
prefix.
Note: Aforementioned X-Credential-*
headers are not set when authentication failed, and the ‘anonymous’ consumer was set instead.