Skip to content

Commit c527c4a

Browse files
docs: document omit option for basic auth credentials
Co-Authored-By: Devin Logan <devinannlogan@gmail.com>
1 parent d2369a8 commit c527c4a

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

fern/products/api-def/ferndef/auth.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,30 @@ client = new Client({
131131
})
132132
```
133133

134+
### Omit username or password
135+
136+
If your API only expects one half of a basic auth credential pair (for example, a token in the username and an empty password), set `omit: true` on the field you want to remove from the generated SDK:
137+
138+
```yaml title="api.yml" {8}
139+
auth: Basic
140+
auth-schemes:
141+
Basic:
142+
scheme: basic
143+
username:
144+
name: apiToken
145+
password:
146+
omit: true
147+
```
148+
149+
The omitted field is removed from the SDK's constructor entirely. Internally, an empty string is used to encode the `Authorization` header — omitting `password` produces `base64("apiToken:")`, and omitting `username` produces `base64(":password")`. If both fields are omitted, no `Authorization` header is sent.
150+
151+
```ts index.ts
152+
// Only the non-omitted field is exposed
153+
const client = new Client({
154+
apiToken: "ey34..."
155+
})
156+
```
157+
134158
## Custom header (e.g. API key)
135159

136160
You can also create your own authentication scheme with customized headers.

fern/products/api-def/openapi/auth.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,19 @@ auth-schemes:
218218
env: MY_CLIENT_SECRET
219219
```
220220

221+
To remove `username` or `password` from the generated SDK — for example, when your API expects a token in the username and ignores the password — set `omit: true` on the field. The omitted field is treated as an empty string when encoding the `Authorization` header, and is dropped from the SDK's public API. If both fields are omitted, no `Authorization` header is sent.
222+
223+
```yaml title="generators.yml" {8}
224+
auth-schemes:
225+
BasicAuth:
226+
scheme: basic
227+
username:
228+
name: apiToken
229+
env: MY_API_TOKEN
230+
password:
231+
omit: true
232+
```
233+
221234
</Accordion>
222235
<Accordion title="API key">
223236

fern/products/sdks/snippets/basic-auth-params.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ auth-schemes:
3030
</ParamField>
3131
<ParamField path="username.env, password.env" type="string" required={false}>
3232
Environment variable name that the SDK will automatically scan for the username or password value. When this environment variable is present, users don't need to explicitly provide the username parameter. Follow naming conventions like `YOUR_APP_USERNAME` or `SERVICE_CLIENT_ID`.
33+
</ParamField>
34+
<ParamField path="username.omit, password.omit" type="boolean" default="false">
35+
When `true`, the field is removed from the generated SDK's public API. The omitted field is treated as an empty string when encoding the `Authorization` header (omitting `password` produces `base64("username:")`; omitting `username` produces `base64(":password")`). When both are omitted, the `Authorization` header is skipped entirely. Use this when your API expects only one half of the basic auth credential pair.
3336
</ParamField>

0 commit comments

Comments
 (0)