# API Gateways

How to use an API gateway with a FusionAuth token.

> For the index of this section of the site, see [llms.txt](https://fusionauth.io/docs/llms.txt)

FusionAuth is an OIDC and OAuth server, which means it integrates with a variety of third party systems out of the box. One of those systems is an API gateway. It is a common architectural pattern to have an authentication system generate a token which is then presented to other services. These services can sit behind an API Gateway, which offers throttling, billing and checks for authenticated requests.

## General Integration Guidance

In general, you'll want to do the following to perform an API gateway integration using OIDC.

In FusionAuth:

*   Create an Application in FusionAuth.
*   Record the **Client Id** and the **Client Secret**.
*   Provide the **Client Id** and the **Client Secret** to the web application which will complete the Authorization Code grant. This may be the API gateway or a custom application.
*   Add the configured redirect URL to the **Authorized redirect URLs** field. This may be the API gateway or a custom application.

You typically need to ensure that FusionAuth is signing the JWT with an asymmetric key. Do that by navigating to Settings -> Key Master to create or import the key pair. Then configure the Application to use the key by navigating to Applications -> Your Application -> JWT .

In the API gateway:

*   Provide the URL for FusionAuth, often called the `issuer`.
*   Configure the API gateway with the client Id, and sometimes the secret, from the Application.
*   Configure which claims of the JWT the API gateway should inspect.
*   Add routes in the API gateway to forward requests to services.

If the API gateway does not support token exchange, but instead expects a token:

*   Create a web application which can receive the one-time Authorization Code and exchange it for an access token. Provide this web application with the client secret.
*   Have the web application securely provide the client the token.

After this is configured, when the user tries to access a service, they'll be prompted to login. After they successfully do so, the API gateway will examine the token and allow access if applicable.

FusionAuth also supports SAML integrations. Learn more about [how FusionAuth can act as a SAML IdP](https://fusionauth.io/docs/authentication/act-as-an-idp/host-saml-idp.md).

## Sample Architecture

Here's a sequence diagram with an example API gateway protecting two services.

```mermaid
sequenceDiagram

participant u as User
participant f as FusionAuth
participant te as Token Exchanger
participant ag as API Gateway
participant sa as Service A
participant sb as Service B

u ->> ag : Requests Service A
ag ->> ag : Token validation failure (it doesn't exist)
ag -->> u  : Sends redirect to FusionAuth
u ->> f  : Authenticates
f ->> f  : Verifies credentials
f -->> u : Redirects user to exchanger
u ->> te : Requests token
te -->> u : Issues token
u ->> ag : Requests Service A and presents token
ag ->> ag : Validates token 
ag ->> sa : Forwards request for Service A
sa -->> ag : Data from Service A
ag -->> u : Data
u ->> ag : Requests Service B and presents token
ag ->> ag : Validates token 
ag ->> sb : Forwards request for Service B
sb -->> ag : Data
ag -->> u : Data from Service B
```

API gateway sample architecture.

## Token Location

The location of the token in the request is typically in one of two places:

*   The `Authorization` header
*   A secure, `HttpOnly` cookie

The former is compatible with a variety of API gateways and open source libraries.

The latter is more secure when used for browser based clients such as SPAs, since JavaScript doesn't have access to the token. It is also compatible with the [Hosted Backend APIs](https://fusionauth.io/docs/apis/hosted-backend.md), which use FusionAuth to perform the token exchange.

## Example Integrations

Here are some example API gateway integrations.

[Amazon API Gateway Learn about the Amazon API Gateway JWT integration.](https://fusionauth.io/docs/authorization/api-gateways/aws-api-gateway.md)

[Cloudflare Worker Functions (API Gateway) Learn about the Cloudflare Worker Functions and JWT integration.](https://fusionauth.io/docs/authorization/api-gateways/cloudflare-api-gateway.md)

[HAProxy API Gateway Learn about the HAProxy JWT integration.](https://fusionauth.io/docs/authorization/api-gateways/haproxy-api-gateway.md)

[Kong Gateway Learn about the Kong Gateway JWT integration.](https://fusionauth.io/docs/authorization/api-gateways/kong-gateway.md)

[ngrok Cloud Edge Learn about the ngrok Cloud Edge OIDC integration.](https://fusionauth.io/docs/authorization/api-gateways/ngrok-cloud-edge.md)

[Securing your APIs with FusionAuth Learn about how to use FusionAuth to control access to an API.](https://fusionauth.io/docs/authorization/api-gateways/api-authorization.md)

[Hasura](https://hasura.io/learn/graphql/hasura-authentication/integrations/fusion-auth/) also provides external documentation for integrating with FusionAuth.

Related

[Concepts Authorization Hub Integrate with third party platforms, using FusionAuth to safely store refresh tokens. apiconsents](https://fusionauth.io/docs/concepts/patterns/authorization-hub.md)

[SDKs Client Libraries and SDKs Learn about the FusionAuth client libraries and SDKs for each language and framework. api](https://fusionauth.io/docs/sdks.md)
---

## Other pages in Authorization

> For the full index of this section, see [Authorization](https://fusionauth.io/docs/llms-authorization.txt).

- [Fine-Grained Authorization](https://fusionauth.io/docs/authorization/fine-grained-authorization.md): Learn how to add fine-grained authorization to FusionAuth with Permify.
- [Control MCP Server Access](https://fusionauth.io/docs/authorization/mcp-server-access.md): Learn how to protect Model Context Protocol (MCP) servers with OAuth authentication using FusionAuth.
- [Access Control with OAuth Scopes](https://fusionauth.io/docs/authorization/oauth-scopes.md): Learn about OAuth scope policy configuration, managing custom scopes, and using scopes in an OAuth2 workflow.
- [Delegate Access With Token Exchange](https://fusionauth.io/docs/authorization/token-exchange-delegation.md): Configure FusionAuth so that one service can exchange a User's access token for a token that calls another service on that User's behalf.
- [OAuth Token Exchange](https://fusionauth.io/docs/authorization/token-exchange.md): Learn how FusionAuth implements OAuth 2.0 Token Exchange (RFC 8693) so that a service can call another service on behalf of a user.
