Authentication
Model auth schemes such as bearer, basic, custom headers, and oauth.
Configuring authentication schemes happens in the api.yml
file.
To add an authentication scheme, specify the authentication method under the auth-schemes
section.
To apply an authentication scheme across all endpoints, reference the auth-scheme
within the auth
section of your api.yml
file.
Bearer authentication
Start by defining a Bearer
authentication scheme in api.yml
:
This will generate an SDK where the user would have to provide
a mandatory argument called token
.
If you want to control variable naming and the environment variable to scan, use the configuration below:
The generated SDK would look like:
Basic authentication
Start by defining a Basic
authentication scheme in api.yml
:
This will generate an SDK where the user would have to provide
a mandatory arguments called username
and password
.
If you want to control variable naming and environment variables to scan, use the configuration below:
The generated SDK would look like:
Custom header (e.g. API key)
You can also create your own authentication scheme with customized headers.
This will generate an SDK where the user would have to provide
a mandatory argument called apiKey
.
If you want to control variable naming and environment variables to scan, use the configuration below:
The generated SDK would look like:
OAuth client credentials
If your API uses OAuth, you can specify an oauth scheme. Note that you’ll need to define a token retrieval endpoint.
If the expires-in
property is set, the generated OAuth token provider will automatically refresh the token when it expires.
Otherwise, it’s assumed that the access token is valid indefinitely.
With this, all of the OAuth logic happens automatically in the generated SDKs. As long as you configure these settings, your client will automatically retrieve an access token and refresh it as needed.
When using the docs playground, token-header
and token-prefix
can optionally be set to customize the header key name and
header value prefix, to match the expected format of the API auth scheme.
For example, the following would produce a header Fern-Authorization: Fern-Bearer <token>
: