/access
, /authorize
) to your API’s ignored_paths
list for direct access if required./oauth/authorize/
) with the Client ID, prompting Tyk to check that the request follows OAuth standards and that the Client ID is active and valid./authorize-client/
), sending the Client ID and user permissions. Tyk then generates an Authorization Code for your app./oauth/token
). This token lets the app access the user’s data per the permissions granted.name
: Specifies the name of the API, in this case, “OAuth Test API.”use_oauth2
: Enables OAuth 2.0 authentication for this API (true
indicates OAuth 2.0 is used).oauth_meta
: Contains OAuth 2.0-specific configuration options:
allowed_access_types
: Defines which OAuth 2.0 access types are allowed, such as authorization_code
and refresh_token
.allowed_authorize_types
: Defines which OAuth 2.0 authorization methods are permitted, like code
(authorization code) and token
(implicit flow).auth_login_redirect
: Specifies the URL to which users are redirected after successful login, typically the login page of your application.notifications
: Manages notifications for OAuth events:
shared_secret
: A secret key shared between Tyk and your app, used to secure notifications.oauth_on_keychange_url
: The URL to which Tyk sends a notification when an OAuth key changes (e.g., token revocation or regeneration)./tyk/oauth/authorize-client/
endpoint with the key_rules
parameter to define key rules for tokens generated during the OAuth flow. These rules encompass rate limits, quotas, expiry times, and access rights:
key_rules
parameter when authorizing a client, Tyk can now have an API policy that manages access rules bound to the Client ID doing the accessing, if a bound policy ID is used when generating the OAuth client, when a token is generated for the client then Tyk will generate a token based on the policy data. This is especially useful in generative contexts such as the client_credentials
grant.notifications
section in your API definition:
oauth_on_keychange_url
: Set the URL where Tyk will send notifications.shared_secret
: Use this secret for secure communication between Tyk and your application; the secret is sent as a header (X-Tyk-Shared-Secret
) with every notification.Parameter | Value |
---|---|
Method | POST |
URL | Uses the special OAuth endpoint /oauth/authorize appended to the API URI, e.g., https://<your-gateway-host>/<your-api-listen-path>/oauth/authorize . |
Content-Type | application/x-www-form-urlencoded |
Parameter | Value |
---|---|
response_type | code |
client_id | The OAuth client ID, e.g., ed59158fa2344e94b3e6278e8ab85142 . |
redirect_uri | The OAuth client redirect URI, e.g., http://example.com/client-redirect-uri , URL encoded as http%3A%2F%2Fexample.com%2Fclient-redirect-uri . |
307 Temporary Redirect
to the OAuth client redirect URI. The user is redirected to authenticate and authorize the client, and the data forwarded will be used to request an authorization code.
Parameter | Value |
---|---|
Method | POST |
URL | Uses the Dashboard API client authorization endpoint /authorize-client/ . |
Authorization | The Dashboard user credentials, e.g., 70c3d834d46a4d6076e1585b0ef2e93e . |
Content-Type | application/x-www-form-urlencoded |
Parameter | Value |
---|---|
response_type | code |
client_id | The OAuth client ID, e.g., ed59158fa2344e94b3e6278e8ab85142 . |
redirect_uri | The OAuth client redirect URI, e.g., http://example.com/client-redirect-uri , URL encoded as http%3A%2F%2Fexample.com%2Fclient-redirect-uri . |
code
and the redirect URL as redirect_to
. The client application will use this information to obtain an access token.
Parameter | Value |
---|---|
Method | POST |
URL | Uses the special OAuth endpoint /oauth/token appended to the API URI, e.g., https://<your-gateway-host>/<your-api-listen-path>/oauth/token . |
Authorization | Basic authorization, using the client ID and client secret of the OAuth client base64 encoded with a colon separator. |
Content-Type | application/x-www-form-urlencoded |
Parameter | Value |
---|---|
grant_type | authorization_code |
client_id | The OAuth client ID, e.g., ed59158fa2344e94b3e6278e8ab85142 . |
code | The authorization code (code ) provided in the response to the previous request, e.g., EaG1MK7LS8GbbwCAUwDo6Q . |
redirect_uri | The OAuth client redirect URI, e.g., http://example.com/client-redirect-uri , URL encoded as http%3A%2F%2Fexample.com%2Fclient-redirect-uri . |
access_token
in the returned JSON, which can then be used to access the API:
username
and password
used in the API token request.
Request | Value |
---|---|
Method | POST |
URL | Uses the special OAuth endpoint /oauth/token appended to the API URI e.g. https://<your-gateway-host>/<your-api-listen-path>/oauth/token . |
Header | Value |
---|---|
Authorization | Basic authorization, using the client id and client secret of the OAuth client base64 encoded with colon separator. E.g. <oauth-client-id>:<oauth-client-secret> , in this case ed59158fa2344e94b3e6278e8ab85142:MGQ3NzE2MGQtYTUyZC00ZTVlLWJjMTItMjE2MTM1MmE3N2M1 , which base64 encoded is ZWQ1OTE1OGZhMjM0NGU5NGIzZTYyNzhlOGFiODUxNDI6TUdRM056RTJNR1F0WVRVeVpDMDBaVFZsTFdKak1USXRNakUyTVRNMU1tRTNOMk0x . |
Content-Type | application/x-www-form-urlencoded |
Data | Value |
---|---|
grant_type | password |
client_id | The OAuth client id, in this case ed59158fa2344e94b3e6278e8ab85142 . |
username | The basic username, in this case oauthapiusername . |
password | The basic password, in this case oauthapipassword . |
access_token
in the returned JSON which can then be used to access the API:
Request | Value |
---|---|
Method | POST |
URL | Uses the special OAuth endpoint /oauth/token appended to the API URI e.g. https://<your-gateway-host>/<your-api-listen-path>/oauth/token . |
Header | Value |
---|---|
Authorization | Basic authorization, using the client id and client secret of the OAuth client base64 encoded with colon separator. E.g. <oauth-client-id>:<oauth-client-secret> , in this case ed59158fa2344e94b3e6278e8ab85142:MGQ3NzE2MGQtYTUyZC00ZTVlLWJjMTItMjE2MTM1MmE3N2M1 , which base64 encoded is ZWQ1OTE1OGZhMjM0NGU5NGIzZTYyNzhlOGFiODUxNDI6TUdRM056RTJNR1F0WVRVeVpDMDBaVFZsTFdKak1USXRNakUyTVRNMU1tRTNOMk0x . |
Content-Type | application/x-www-form-urlencoded |
Data | Value |
---|---|
grant_type | refresh_token |
client_id | The OAuth client id, in this case ed59158fa2344e94b3e6278e8ab85142 . |
client_secret | The OAuth client secret, in this case MGQ3NzE2MGQtYTUyZC00ZTVlLWJjMTItMjE2MTM1MmE3N2M1 . |
refresh_token | The refresh token (refresh_token ) provided in response to the original token request, in this case YjdhOWFmZTAtNmExZi00ZTVlLWIwZTUtOGFhNmIwMWI3MzJj . |
access_token
and a new refresh token as refresh_token
in the returned JSON:
Request | Value |
---|---|
Method | POST |
URL | Uses the special OAuth endpoint /oauth/token appended to the API URI e.g. https://<your-gateway-host>/<your-api-listen-path>/oauth/token . |
Header | Value |
---|---|
Authorization | Basic authorization, using the client id and client secret of the OAuth client base64 encoded with colon separator. E.g. <oauth-client-id>:<oauth-client-secret> , in this case ed59158fa2344e94b3e6278e8ab85142:MGQ3NzE2MGQtYTUyZC00ZTVlLWJjMTItMjE2MTM1MmE3N2M1 , which base64 encoded is ZWQ1OTE1OGZhMjM0NGU5NGIzZTYyNzhlOGFiODUxNDI6TUdRM056RTJNR1F0WVRVeVpDMDBaVFZsTFdKak1USXRNakUyTVRNMU1tRTNOMk0x . |
Content-Type | application/x-www-form-urlencoded |
Data | Value |
---|---|
grant_type | client_credentials |
client_id | The OAuth client id, in this case ed59158fa2344e94b3e6278e8ab85142 . |
client_secret | The OAuth client secret, in this case MGQ3NzE2MGQtYTUyZC00ZTVlLWJjMTItMjE2MTM1MmE3N2M1 . |
access_token
in the returned JSON which can then be used to access the API:
Any party in possession of a bearer token (a “bearer”) can use it to get access to the associated resources (without demonstrating possession of a cryptographic key). To prevent misuse, bearer tokens need to be protected from disclosure in storage and in transport.Tyk provides bearer token access as one of the most convenient building blocks for managing security to your API. In a Tyk setup, this is called “Access Tokens” and is the default mode of any API Definition created for Tyk. Bearer tokens are added to a request as a header or as a query parameter. If added as a header, they may be preceded by the word “Bearer” to indicate their type, though this is optional. Traditionally these tokens are used as part of the
Authorization
header.
Authorization
header, but you can change this by setting the Auth Key Header name value/api/widgets/12345
that uses access tokens will require the addition of a header field, traditionally this is the Authorization
header.
The name of the key can be defined as part of the API definition under the auth
section of an API Definition file:
auth.use_param
setting in your API definition to true
.
use_cookie
parameter to true
. Cookie names are also case sensitive.
Signature validation
If you are migrating from platforms like Mashery, which use request signing, you can enable signature validation like this:
validate_signature
: boolean value to tell Tyk whether to enable signature validation or not
signature.algorithm
: the algorithm you wish to validate the signature against. Currently supported
MasherySHA256
MasheryMD5
signature.header
: header key of attempted signature
signature.secret
: the shared secret which was used to sign the request
$tyk_meta
or $tyk_context
variables."secret": "$tyk_meta.individual_secret"
. Which effectively means that you have created/imported the api key into Tyk, and have stored the shared secret in the field individual_secret
of the session token’s meta-data.signature.allowed_clock_skew
: allowed deviation in seconds between UNIX timestamp of Tyk & UNIX timestamp used to generate the signed request
Custom tokens
It is possible to provide Tyk with your own custom tokens, this can be achieved using the Tyk Gateway REST API. This is very useful if you have your own identity provider and don’t want Tyk to create and manage tokens for you, and instead just mirror those tokens within Tyk to off-load access control, quotas and rate limiting from your own application.
access_token
or refresh_token
) or you can revoke all OAuth Client tokens.
You can revoke OAuth tokens via the following methods:
Parameter | Value |
---|---|
Method | POST |
URL | The revocation endpoint of the authorization server. |
Authorization | Basic authorization, using the client ID and client secret of the OAuth client base64 encoded with colon separator. |
Content-Type | application/x-www-form-urlencoded |
Parameter | Value |
---|---|
token | The access token to revoke, e.g., ACCESS_TOKEN . |
token_type_hint | The type of token being revoked, typically access_token . |
client_id | The OAuth client ID, e.g., CLIENT_ID . |
client_secret | The client secret, e.g., CLIENT_SECRET . |
Authorization
header that contains the API key.
The value of the Authorization
header will be in the form:
[email protected]
and the password is 1234567
(see base64encode.org)
Authorization
header, but you can change this by setting the Auth Key Header name valueuse_basic_auth
to true:
Authorization
header.
testuser
and password mickey-mouse
by sending a POST
command to the /tyk/keys/
endpoint of Tyk Gateway API:
POST
to create a new user and PUT
to update an existing entry.Be careful to ensure that the org_id
is set correctly and consistently so that the Basic Authentication user is created in the correct organization.testuser2
and password minnie-mouse
by sending a POST
command to the /tyk/keys/
endpoint of Tyk Dashboard API:
POST
to create a new user and PUT
to update an existing entry.Be careful to ensure that the org_id
is set correctly and consistently so that the Basic Authentication user is created in the correct organization.externalOAuthServer
set enabled
to true
to enable the middleware.
providers
is an array of multiple IDP configurations, with each IDP config being an element in the providers
array.
jwt
or use introspection via instropection
in the providers
section .
providers
to have only one element, ie one IDP configured.enabled
- enables JWT validation.signingMethod
- specifies the signing method used to sign the JWT.source
- the secret source, it can be one of:
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 to sub
.provider.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 to sub
.enabled
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:
Authorization
header, and uses set, stripped comma-delimited fields to identify the user, from the draft proposal:
hmac_allowed_algorithms
field in API definition, like this: "hmac_allowed_algorithms": ["hmac-sha256", "hmac-sha512"]
.
The date format for an encoded string is:
Authorization
header, and retrieved from Redis. If the key exists then Tyk will generate its own signature based on the requests “date” header, if this generated signature matches the signature in the Authorization
header the request is passed.
headers
HMAC signature field. This includes the request method and path using the(request-target)
value. For body signature verification, HTTP Digest headers should be included in the request and in the header field value.
x-aux-date
header, it will use this to replace the Date header.
hmac_allowed_clock_skew
value in your API definition. This value will default to 0, which deactivates clock skew checks.
Authorization
header, but you can change this by setting the Auth Key Header name valuehmac_enabled
flag to true
, Tyk will generate a secret key for the key owner (which should not be modified), but will be returned by the API so you can store and report it to your end-user.
(request-target)
and all the headers of the request will be used for generating signature string.
If the request doesn’t contain a Date
header, middleware will add one as it is required according to above draft.
A config option request_signing
can be added in an API Definition to enable/disable the request signing. It has following format:
hmac-sha1
hmac-sha256
hmac-sha384
hmac-sha512
HMAC (shared)
and the public secret as tyk123
pol
claim, it will apply this Default Policy. Select a policy that gives access to this API we are protecting, or go create one first if it doesn’t exist.
Make sure to save the changes to the API Definition.
tyk123
in the VERIFY SIGNATURE section. Your screen should look similar to this:
Parameter | Value |
---|---|
Method | GET |
URL | The API endpoint for the protected resource. |
Authorization | Bearer token, e.g., Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... . |
jwks_uri
end point https://<<your-auth0-domain>>/.well-known/jwks.json
jwks_uri
in to the Public Key field.sub
and pol
are fine.curl
. This is the token you will use to access your services through the Tyk Gateway. You can generate your JWT using either of the following methods. Make sure to replace the KEYCLOAK
prefixed parameters with the appropriate values.
Password Grant Type:
http://httpbin.org
upstream URL is fine).
https://KEYCLOAK_URL/realms/KEYCLOAK_REALM/protocol/openid-connect/certs
.
sub
and pol
are fine.
TOKEN
with the JWT you received from the curl earlier.
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJlbWFpbCI6ImhlbGxvQHdvcmxkLmNvbSJ9
EwIaRgq4go4R2M2z7AADywZ2ToxG4gDMoG4SQ1X3GJ0
kid
header field is included in the JWT for validation.
kid
header is missing, Tyk will check the sub
field. This is not recommended but supported.sub
) for rate-limiting and quota counting.kid
header, matching the kid
in the JWK payload for verification.jwt_issued_at_validation_skew
jwt_expires_at_validation_skew
jwt_not_before_validation_skew
0
.
"jwt_scope_to_policy_mapping"
provides mapping of scopes (read from claim) to actual policy ID. I.e. in this example we specify that scope “admin” will apply policy "59672779fa4387000129507d"
to a key"jwt_scope_claim_name"
identifies the JWT claim name which contains scopes. This API Spec field is optional with default value "scope"
. This claim value could be any of the following:
"jwt_scope_claim_name"
in dot notation. For eg. "scope1.scope2"
, "scope2"
will be having the list of values nested inside "scope1"
"jwt_scope_claim_name"
in dot notation. For eg. "scope1.scope2"
, "scope2"
will be having a slice of strings nested inside "scope1"
scope
):
"per_api"
set to true
and shouldn’t have the same API ID
in access rights. I.e. if claim with scopes contains value "admin developer"
then two policies "59672779fa4387000129507d"
and "53222349fa4387004324324e"
will be applied to a key (with using our example config above).Parameter | Value |
---|---|
Method | GET |
URL | The API endpoint for the public resource. |
Parameter | Value |
---|---|
Method | GET |
URL | The API endpoint for the protected resource. |
Authorization | Bearer token, e.g., Bearer ID_TOKEN . |
base_identity_provided_by
field in your API Definitions to one of the supported chained enums below:
AuthToken
HMACKey
BasicAuthUser
JWTClaim
OIDCUser
OAuthKey
UnsetAuth
use_standard_auth
to true
.
HTTP 401 Key has expired, please renew
.HTTP 400 Access to this API has been disallowed
.expires
field. This is a UNIX timestamp and, when this date/time is reached, the key will automatically expire; any subsequent API request made using the key will be rejected.
session_lifetime
field in your API Definition and keys created for that API will automatically be deleted when that period (in seconds) has passed.
The default value for session_lifetime
is 0, this is interpreted as an infinite lifetime which means that keys will not be deleted from Redis.
For example, to have keys live in Redis for only 24 hours (and be deleted 24 hours after their creation) set:
session_lifetime
is applied regardless of whether the key is active or expired. To protect against this, you can configure the session_lifetime_respects_key_expiration parameter in your tyk.conf
, so that keys that have exceeded their lifetime will not be deleted from Redis until they have expired.session_lifetime
, otherwise the user might try to use the key after it has already been removed from Redis.
tyk.conf
file; this parameter is an integer value in seconds.
To enable this global lifetime, you must also set the force_global_session_lifetime parameter in the tyk.conf
file.
force_global_session_lifetime
and session_lifetime_respects_key_expiration
configuration parameters.
force_global_session_lifetime | session_lifetime_respects_key_expiration | Assigned lifetime |
---|---|---|
true | true | global_session_lifetime |
true | false | global_session_lifetime |
false | true | larger of session_lifetime or expires |
false | false | session_lifetime |
0
in session_lifetime
or global_session_lifetime
is interpreted as infinity (i.e. key will not be deleted if that control is in use) - and if a field is not set, this is treated as 0
.expires
within the key to control deletion) then you must set a non-zero value in session_lifetime
and configure both session_lifetime_respects_key_expiration:true
and force_global_session_lifetime:false
.In cryptography, a public key certificate, also known as a digital certificate or identity certificate, is an electronic document used to prove the ownership of a public key. The certificate includes information about the key, information about the identity of its owner (called the subject), and the digital signature of an entity that has verified the certificate’s contents (called the issuer). If the signature is valid, and the software examining the certificate trusts the issuer, then it can use that key to communicate securely with the certificate’s subject.When it comes to authorization, it is enough for the server that has a public client certificate in its trusted certificate storage to trust it. However, if you need to send a request to the server protected by mutual TLS, or need to configure the TLS server itself, you also need to have a private key, used while generating the certificate, to sign the request. Using Tyk, you have two main certificate use cases:
openssl
command to generate certificates, it should use PEM by default. A nice bonus of the PEM format is that it allows having multiple entries inside the same file. So in cases where a certificate also requires a private key, you can just concatenate the two files together.
POST /tyk/certs
with PEM body. Returns {"id": "<cert-id>", ... }
DELETE /tyk/certs/<cert-id>
GET /tyk/certs/<cert-id>
. Returns meta info about the certificate, something similar to:GET /tyk/certs/<cert-id1>,<cert-id2>,<cert-id3>
.
Returns array of meta info objects, similar to above.GET /tyk/certs
. Returns something similar to:/api
instead of /tyk
, e.g. /api/certs
, /api/certs/<cert-id>
, etc.security.private_certificate_encoding_secret
secret, defined in tyk.conf
file. Otherwise, the certificate will use the secret value in tyk.conf
.
security.private_certificate_encoding_secret
in the MDCB configuration file to the same value as specified in your management Gateway configuration file. By knowing the original secret, MDCB will be able to decode private keys, and
send them to client without password. Using a secure connection between Data Plane Gateways and MDCB is required in this case. See MDCB setup page for use_ssl usage.
use_mutual_tls_auth
to true
, and client_certificates
as an array of strings - certificate IDs.
From the Tyk Dashboard, to do the same from the API Designer Core settings section you need to select Mutual TLS authentication mode from the Authentication section, and allow the certificates using the built-in widget, as below:
security.certificates.apis
key - string array of certificate IDs or paths.
Select Strip Authorization Data to strip any authorization data from your API requests.
Be aware that mutual TLS authorization has special treatment because it is not “authentication” and does not provide any identifying functionality, like keys, so you need to mix it with another authentication modes options like Auth Key or Keyless. On the dashboard, you need to choose Use multiple auth mechanism in the Authentication mode drop-down, where you should select Mutual TLS and another option which suits your use-case.
upstream_certificates
field to the following format:
{"example.com": "<cert-id>"}
. Defining on a global level looks the same, but should be specified via the security.certificates.upstream
field in your Gateway configuration file.
https://api.production.myupstream.com
api.production.myupstream.com
.*
instead of domain name: {"*": "<cert-id>"}
You may use wild cards in combination with text to match the domain, but it only works one level deep.
Meaning, if your domain is api.production.myupstream.com
the only wildcard value accepted would be *.production.myupstream.com
. The value *.myupstream.com
will NOT work.
Setting through the Dashboard
To do the same via the Tyk Dashboard, go to the API Designer > Advanced Options panel > Upstream certificates section.
common name
specify a domain, or just pass -subj "/CN=localhost"
to OpenSSL command. Then follow our TLS and SSL Guide.
To get certificate SHA256 fingerprint use the following command:
Use Case | Static | Dynamic |
---|---|---|
Let developers upload their own public certificates through the Developer Portal | ❌ | ✅ |
Combine client mTLS with another authentication method | ✅ | ✅ |
Allow certs at the API level (one or more APIs per cert) | ✅ | ❌ |
Allow certs at an individual level (one or more APIs per cert) | ❌ | ✅ |
httpbin-client-mtls
.
client_certificate_refs
field references the Kubernetes secret created in the previous step.
TykOasApiDefinition
CRD. You can reference Kubernetes secrets that store client certificates in your API definitions.
Example of Referencing Client Certificates in Tyk OAS
In this example, the clientCertificate
section allows you to enable client certificate management and specify a list of Kubernetes secrets (tls-cert
) that store allowed client certificates.
auth.use_certificate
set to true
.
upstream_certificates
field in the following format:
security.certificates.upstream
field in your Gateway configuration file.
upstream_certificate_refs
field can be used to configure certificates for different domains. References can be held to multiple secrets which are used for the domain mentioned in the key. Currently ”*” is used as a wildcard for all the domains
The example listed below shows that the certificate in the secret, my-test-tls, is used for all domains.
upstream_certificates
field allows certificates uploaded to the certificate store in Tyk Dashboard to be referenced in the Api Definition:
mutualTLS
field in TykOasApiDefinition
object:
https://
). Including the protocol will prevent Tyk from matching the certificates to the correct domain.
Incorrect: https://api.production.myupstream.com
Correct: api.production.myupstream.com
If the request is made via a non-standard HTTP port, you need to include the port in the domain:
Correct: api.production.myupstream.com:8443
api.production.myupstream.com
:
Correct: *.production.myupstream.com
Incorrect: *.myupstream.com
*
instead of a domain name: