> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fapost.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Credentials

> Save the secrets flows use to call outside systems once, and pick them in a Call block instead of typing a secret into the flow.

A credential is a secret a flow needs in order to call another system: a token, a
username and password, an API key. Save it here once, and a [Call](https://docs.fapost.in/using/node-catalogue.md#call)
block picks it by name. The secret is applied when the call runs; it is never written
into the flow, so it does not appear in a flow's definition, in an exported flow, or in
the builder.

The screen is **System** → **Credentials** in the admin panel. It needs the
**Manage credentials** permission. Picking a saved credential in a flow, and testing a call
with it, needs **Use credentials** instead: someone can build on a credential an
administrator created without seeing or changing it. The `content_manager` role has
**Use credentials** but not **Manage credentials**; see
[Roles and permissions](https://docs.fapost.in/using/roles-and-permissions.md).

## Creating a credential

Choose **New credential**, name it, choose a type, fill in the values the type asks for,
and list the hosts it may be sent to. The name is what people see when they pick it in a
flow. The type cannot be changed after the credential is saved.

| Type | Values | How it is sent |
| - | - | - |
| **Bearer token** | Token | `Authorization: Bearer <token>` header |
| **Basic authentication** | Username, password | `Authorization: Basic …` header |
| **API key in a header** | Header name, optional value prefix, key | The key in that header |
| **API key in the query string** | Parameter name, key | The key as a URL parameter |
| **OAuth 2.0 client credentials** | Token URL, client ID, scope, how to send the client credentials, client secret | A bearer token FaPost fetches from the token URL |
| **OAuth 2.0 authorization code (user consent)** | Authorization URL, token URL, client ID, scope, how to send the client credentials, extra authorization parameters, client secret | A bearer token a person grants at the provider; see [Connecting with user consent](#connecting-with-user-consent) |

> [!WARNING]
>
> A key in the URL is visible to proxies, the receiving server and its logs. Use
> **API key in the query string** only when the service offers nothing else.

A secret must be at least 8 characters. For OAuth 2.0, the token URL must be an `https`
address on one of the allowed hosts. FaPost fetches the token itself, keeps it encrypted
in Redis until shortly before it expires, and fetches a new one when needed.

### Connecting with user consent

Use **OAuth 2.0 authorization code** for APIs that act on behalf of a person who has to
agree first, such as Google, Microsoft or HubSpot.

1. Register an app at the provider. Put the callback URL,
   `https://<your workspace host>/admin/credentials/oauth/callback`, into the app's redirect
   URIs. Once the credential is created, its **Connection** section shows the same URL as
   **Callback URL**: it must match exactly.
2. Create the credential here with the app's client ID and secret, its authorization URL
   and token URL, and the scope. The token URL must be an `https` address on one of the
   allowed hosts; the authorization URL need not be.
3. Some providers issue a refresh token only when asked. Put that in **Extra authorization
   parameters** as a query string; Google, for example, needs
   `access_type=offline&prompt=consent`.
4. Save, then choose **Connect**. You go to the provider, agree, and come back to the
   credential. The person who connects is the one whose access flows will use.

The status is **Not connected**, **Connected**, or **Reconnect needed**. The last one means
the provider refused to renew access, for example because it was revoked or expired:
choose **Reconnect**. FaPost refreshes the access token when it expires, and a daily job
(`credentials:refresh-oauth2-grants`, scheduled at 02:30) keeps connections alive even when no flow
has used them for a while. **Disconnect** deletes the stored access; it does not revoke
it at the provider, so revoke it in the provider's settings too.

Changing the client ID, client secret, token URL, authorization URL, scope or extra
authorization parameters drops the connection, and you connect again. Changing the
name or narrowing the allowed hosts does not; adding a host drops it.

> [!WARNING]
>
> The callback URL contains the workspace host. If you change the workspace's slug, the
> callback URL changes: update the redirect URI at the provider and reconnect.

Two things to know about the callback. It needs the session cookie to come back with the
provider's redirect, so `SESSION_SAME_SITE=strict` breaks it; keep the default `lax`. And
the one-time authorization code travels in the callback URL's query string, so it can
appear in a web server or proxy access log. It can be used once and is protected by PKCE.

### Allowed hosts

A credential is sent only to the hosts you list, and at least one is required. Use an
exact name such as `api.example.com`, or `*.example.com` for every subdomain. The
wildcard does not match the bare domain: `*.example.com` allows `api.example.com` but not
`example.com`, so list both if you need both.

A call to any other host is not made, and the flow takes the failure outcome with
`error_code = credential_host_denied`. A credential is sent only over https: a call to an
`http://` address is not made either, and fails with `error_code = credential_insecure_target`
(a block whose address is written out as `http://` cannot be published). Redirects are not
followed when a credential is used, so a response cannot send the secret to a different host.

## Secrets are write-only

Secret values are encrypted with the application key and never shown again after saving.
When you edit a credential, a secret field shows that a value is saved; leave it empty to
keep it, or type a new value to replace it. The one exception: when you add an allowed host
that the old list did not cover (including a wildcard over hosts that were listed one by one),
or move the token URL to another host, every secret must be entered again, so a saved key
cannot be sent somewhere new by someone who never saw it. Removing hosts needs no secret. A secret is also hidden as `***` in a call's
result, in the variables a call saves and in the flow log.

Every create, change and delete is written to the [Activity log](https://docs.fapost.in/using/activity-log.md),
with the credential's name, type and hosts but never a secret value.

> [!WARNING]
>
> Saved credentials can be read only with the application key (`APP_KEY`). If the key is
> rotated without listing the old one in `APP_PREVIOUS_KEYS`, saved credentials become
> unreadable and the calls that use them fail with `credential_unavailable` until the
> secrets are entered again.

## Deleting a credential

Deleting a credential cannot be undone. A flow that still uses it ends its Call block
through the failure outcome with `error_code = credential_not_found`. Publishing a flow
that names a missing credential is refused.

## Using a credential in a flow

In a Call block, set **Authorization** to **Saved credential** and choose the credential.
See [Call](https://docs.fapost.in/using/node-catalogue.md#call) for what happens at run time.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.