Authentication

Model auth schemes such as bearer, basic, and api key.

Configuring authentication schemes happens in the components.securitySchemes section of OpenAPI.

openapi.yml
1components:
2 securitySchemes:
3 ...

To apply a security scheme across all endpoints, reference the securityScheme within the security section of your OpenAPI Specification.

openapi.yml
1components:
2 securitySchemes:
3 AuthScheme:
4 ...
5security:
6 - AuthScheme: []

Bearer security scheme

Start by defining a bearer security scheme in your openapi.yml:

openapi.yml
1components:
2 securitySchemes:
3 BearerAuth:
4 type: http
5 scheme: bearer

This will generate an SDK where the user would have to provide a mandatory argument called token.

index.ts
1const client = new Client({
2 token: "ey34..."
3})

If you want to control variable naming and the environment variable to scan, use the configuration below:

openapi.yml
1components:
2 securitySchemes:
3 BearerAuth:
4 type: http
5 scheme: bearer
6 x-fern-bearer:
7 name: apiKey
8 env: PLANTSTORE_API_KEY

The generated SDK would look like:

index.ts
1// Uses process.env.PLANTSTORE_API_KEY
2let client = new Client();
3
4// token has been renamed to apiKey
5client = new Client({
6 apiKey: "ey34..."
7})

Basic security scheme

Start by defining a basic security scheme in your openapi.yml:

openapi.yml
1components:
2 securitySchemes:
3 BasicAuth:
4 type: http
5 scheme: basic

This will generate an SDK where the user would have to provide a mandatory arguments called username and password.

index.ts
1const client = new Client({
2 username: "joeschmoe"
3 password: "ey34..."
4})

If you want to control variable naming and environment variables to scan, use the configuration below:

openapi.yml
1components:
2 securitySchemes:
3 BasicAuth:
4 type: http
5 scheme: basic
6 x-fern-basic:
7 username:
8 name: clientId
9 env: PLANTSTORE_CLIENT_ID
10 password:
11 name: clientSecret
12 env: PLANTSTORE_CLIENT_SECRET

The generated SDK would look like:

index.ts
1// Uses process.env.PLANTSTORE_CLIENT_ID and process.env.PLANTSTORE_CLIENT_SECRET
2let client = new Client();
3
4// parameters have been renamed
5client = new Client({
6 clientId: "joeschmoe",
7 clientSecret: "ey34..."
8})

ApiKey security scheme

Start by defining an apiKey security scheme in your openapi.yml:

openapi.yml
1components:
2 securitySchemes:
3 ApiKey:
4 type: apiKey
5 in: header
6 name: X_API_KEY

This will generate an SDK where the user would have to provide a mandatory argument called apiKey.

index.ts
1const client = new Client({
2 apiKey: "ey34..."
3})

If you want to control variable naming and environment variables to scan, use the configuration below:

openapi.yml
1components:
2 securitySchemes:
3 ApiKey:
4 type: apiKey
5 in: header
6 name: X_API_KEY
7 x-fern-header:
8 name: apiToken
9 env: PLANTSTORE_API_KEY
10 prefix: "Token " # Optional

The generated SDK would look like:

index.ts
1// Uses process.env.PLANTSTORE_API_KEY
2let client = new Client();
3
4// parameters have been renamed
5client = new Client({
6 apiToken: "ey34..."
7})

Multiple security schemes

If you would like to define multiple security schemes, simply list them under components.securitySchemes. For example, if you wanted to support basic and apiKey security schemes, see the example below:

openapi.yml
1components:
2 securitySchemes:
3 BearerAuth:
4 type: http
5 scheme: bearer
6 ApiKey:
7 type: apiKey
8 in: header
9 name: X_API_KEY