Introduction
Tyk Gateway sits between your clients and your services, securely routing requests and responses. For each API proxy that you expose on Tyk, you can configure a range of different methods that clients must use to identify (authenticate) themselves to Tyk Gateway when making a request to access the API. Authentication and Authorization are the processes that you use to control access to your APIs and protect your upstream services. Each serves a distinct purpose:- Authentication (or AuthN) is the process of confirming the identity of the user or system making the API request. This step validates “who” is attempting to access the API, commonly using credentials such as tokens, passwords, or certificates.
- Authorization (or AuthZ) is the process that determines if the user or system has the right permissions to perform the requested action. This step defines “what” they are allowed to do based on assigned roles, scopes, or policies.
How does Tyk Implement Authentication and Authorization?
The API request processing flow within Tyk Gateway consists of a chain of middleware that perform different checks and transformations on the request (headers, parameters and payload). Several dedicated authentication middleware are provided and there is also support for user-provided custom authentication plugins. Multiple authentication middleware can be chained together if required by the API’s access security needs. Note that it is not possible to set the order of chained auth methods. The OpenAPI description can contain a list of securitySchemes which define the authentication methods to be used for the API; the detailed configuration of the Tyk authentication middleware is set in the server.authentication section of the Tyk Vendor Extension. You must enable client authentication using theserver.authentication.enabled
flag and then configure the appropriate authentication method as indicated in the relevant section of this document. When creating a Tyk OAS API from an OpenAPI description, Tyk can automatically enable authentication based upon the content of the OpenAPI description as described here.
When using Tyk Classic APIs, each authentication middleware has its own fields within the API definition
Managing authorization data
The data that the client provides with the API request used to authenticate with Tyk and confirm that it is authorized to access the API is often of no use to the upstream service and, depending on your security governance, may even be prohibited from being made available to the upstream. Tyk offers a simple option, separately configurable for each API to remove, or “strip”, the authentication/authorization date from the incoming request before proxying to the upstream. This is controlled using the server.authentication.stripAuthorizationData field in the Tyk Vendor Extension (Tyk Classic:strip_auth_data
).
What does Tyk Support?
Tyk includes support for various industry-standard methods to secure your APIs. This page provides an overview of the options available, helping you to choose and implement what works best for you. Use Ctrl+F or the sidebar to find specific topics, for example “JWT” for JSON Web Tokens or “mTLS” for mutual TLS. You can also use the links below to jump directly to the appropriate sections to learn how to secure your APIs using Tyk.OAuth 2.0
Delegate authentication using one of the most widely used open standard protocols
JWT
Securely transmit information between parties.
Basic Auth
Secure APIs with username and password credentials.
Auth Tokens
Implement token-based authentication for API access.
mTLS
Establish secure channels with two-way certificate verification.
HMAC
Verify message integrity using shared secret keys.
Custom Authentication
Create custom plugins to implement specific authentication requirements.
Open Access
Allow unrestricted access for public APIs.
Other Authentication Methods
Integrate with External Authorization Server (deprecated)
Tyk has previously offered two types of OAuth authentication flow; Tyk as the authorization server and Tyk connecting to an external auth server via a dedicated External OAuth option. The dedicated external auth server option was deprecated in Tyk 5.7.0.
For third-party OAuth integration we recommend using the JSON Web Token (JWT) middleware which is described above, which offers the same functionality with a more streamlined setup and reduced risk of misconfiguration.
The remainder of this section is left for reference and is not maintained.
For third-party OAuth integration we recommend using the JSON Web Token (JWT) middleware which is described above, which offers the same functionality with a more streamlined setup and reduced risk of misconfiguration.
The remainder of this section is left for reference and is not maintained.
OAS contract
Tyk Classic API definition contract
-
externalOAuthServer
setenabled
totrue
to enable the middleware. -
providers
is an array of multiple IDP configurations, with each IDP config being an element in theproviders
array. -
You can use this config to use JWT self validation using
jwt
or use introspection viainstropection
in theproviders
section .For now, you’ll be limitingproviders
to have only one element, ie one IDP configured.
JWT
There could be cases when you don’t need to introspect a JWT access token from a third party IDP, and instead you can just validate the JWT. This is similar to existing JWT middleware, adding it in External OAuth middleware for semantic reasons.enabled
- enables JWT validation.signingMethod
- specifies the signing method used to sign the JWT.source
- the secret source, it can be one of:- a base64 encoded static secret
- a valid JWK url in plain text
- a valid JWK url in base64 encoded format
issuedAtValidationSkew
,notBeforeValidationSkew
,expiresAtValidationSkew
can be used to configure clock skew for json web token validation.identityBaseField
- the identity key name for claims. If empty it will default tosub
.
Example: Tyk OAS API definition with JWT validation enabled
Example: Tyk Classic API definition with JWT validation enabled
Introspection
For cases where you need to introspect the OAuth access token, Tyk uses the information in theprovider.introspection
section of the contract. This makes a network call to the configured introspection endpoint with the provided clientID
and clientSecret
to introspect the access token.
enabled
- enables OAuth introspectionclientID
- clientID used for OAuth introspection, available from IDPclientSecret
- secret used to authenticate introspection call, available from IDPurl
- endpoint URL to make the introspection callidentityBaseField
- the identity key name for claims. If empty it will default tosub
.
Caching
Introspection via a third party IdP is a network call. Sometimes it may be inefficient to call the introspection endpoint every time an API is called. Caching is the solution for this situation. Tyk caches the introspection response whenenabled
is set to true
inside the cache
configuration of introspection
. Then it retrieves the value from the cache until the timeout
value finishes. However, there is a trade-off here. When the timeout is long, it may result in accessing the upstream with a revoked access token. When it is short, the cache is not used as much resulting in more network calls.
The recommended way to handle this balance is to never set the timeout
value beyond the expiration time of the token, which would have been returned in the exp
parameter of the introspection response.
See the example introspection cache configuration:
Example: Tyk OAS API definition external OAuth introspection enabled
Example: Tyk Classic API definition with external OAuth introspection enabled
Integrate with OpenID Connect (deprecated)
Tyk has previously offered a dedicated OpenID Connect option for client authentication, but this was not straightforward to use and was deprecated in Tyk 5.7.0.
For integration with a third-party OIDC provider we recommend using the JSON Web Token (JWT) middleware which is described above, which offers the same functionality with a more streamlined setup and reduced risk of misconfiguration.
The remainder of this section is left for reference and is not maintained.
For integration with a third-party OIDC provider we recommend using the JSON Web Token (JWT) middleware which is described above, which offers the same functionality with a more streamlined setup and reduced risk of misconfiguration.
The remainder of this section is left for reference and is not maintained.