You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: fern/products/api-def/ferndef-pages/auth.mdx
+45-6Lines changed: 45 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -178,7 +178,7 @@ client = new Client({
178
178
179
179
## OAuth client credentials
180
180
181
-
If your API uses OAuth, you can specify an oauth scheme. Note that you'll need to define a token retrieval endpoint.
181
+
If your API uses OAuth, you can specify an oauth scheme in `api.yml` and define a token retrieval endpoint in a separate `auth.yml` file ([example](https://github.com/fern-api/fern/blob/3137938b70e058f3691ddef34d5c1cc29acc4b80/test-definitions/fern/apis/oauth-client-credentials/definition/api.yml)).
If the `expires-in` property is set, the generated OAuth token provider will automatically refresh the token when it expires.
205
-
Otherwise, it's assumed that the access token is valid indefinitely.
207
+
The `request-properties` and `response-properties` map OAuth standard parameters to your actual endpoint's request and response field names defined in `auth.yml`.
208
+
209
+
<Info>
210
+
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.
211
+
</Info>
212
+
213
+
The corresponding `auth.yml` file ([example](https://github.com/fern-api/fern/blob/3137938b70e058f3691ddef34d5c1cc29acc4b80/test-definitions/fern/apis/oauth-client-credentials/definition/auth.yml)) defines the token endpoint:
214
+
215
+
```yaml title="auth.yml"
216
+
types:
217
+
TokenResponse:
218
+
docs: |
219
+
An OAuth token response.
220
+
properties:
221
+
access_token: string
222
+
expires_in: integer
223
+
refresh_token: optional<string>
224
+
225
+
service:
226
+
auth: false
227
+
base-path: /
228
+
endpoints:
229
+
getTokenWithClientCredentials:
230
+
path: /token
231
+
method: POST
232
+
request:
233
+
name: GetTokenRequest
234
+
body:
235
+
properties:
236
+
client_id: string
237
+
client_secret: string
238
+
audience: literal<"https://api.example.com">
239
+
grant_type: literal<"client_credentials">
240
+
scope: optional<string>
241
+
response: TokenResponse
242
+
```
243
+
244
+
<Info>If your OAuth server is hosted at a different URL than your main API, you can use [multi-URL environments](/api-definitions/ferndef/api-yml/environments#multiple-urls-per-environment) to specify separate base URLs for authentication and API calls.</Info>
206
245
207
246
With this, all of the OAuth logic happens automatically in the generated SDKs. As long as you configure these settings, your
208
247
client will automatically retrieve an access token and refresh it as needed.
0 commit comments