Authorization
header that contains the client’s credentials in the form: Basic <credentials>
.
The <credentials>
are a base64 encoded concatenation of a client username and password, joined by a single colon :
.
Tyk supports Basic Authentication as a method for authenticating clients with the Gateway - you can use Tyk Gateway or Dashboard to create Basic Auth users, as explained in the documentation.
If your upstream service is protected using Basic Authentication then similarly, Tyk will need to provide user credentials, registered with the upstream, in the request.
Authorization
header, then Tyk will replace those with the basic auth credentials before proxying onwards to the upstream.
Sometimes a non-standard upstream server might require the authentication credentials to be provided in a different header (i.e. not Authorization
). With Tyk, you can easily configure a custom header to be used for the credentials if required.
Upstream Basic Authentication is only supported by Tyk OAS APIs. If you are using Tyk Classic APIs, you could create the client credential offline and add the Authorization
header using the Request Header Transform middleware.
x-tyk-api-gateway
) within the Tyk OAS API definition by adding the authentication
section within the upstream
section.
Set upstream.authentication.enabled
to true
to enable upstream authentication.
For Basic Authentication, you will need to add the basicAuth
section within upstream.authentication
.
This has the following parameters:
enabled
set this to true
to enable upstream basic authenticationusername
is the username to be used in the request credentialspassword
is the password to be used in the request credentialsheader.enabled
must be set to true
if your upstream expects the credentials to be in a custom header, otherwise it can be omitted to use Authorization
headerheader.name
is the custom header to be used if header.enabled
is set to true
header
parameter - even if you are using the default Authorization
value.
For example:
GET /basic-auth
endpoint at httpbin.org using the credentials in lines 46 and 47 (username: myUsername, password: mySecret). These credentials will be combined, base64 encoded and then provided in the Authorization
header, as required by the httpbin.org documentation.
The configuration above is a complete and valid Tyk OAS API Definition that you can import into Tyk to try out the Upstream Basic Authentication feature.