Skip to content

Commit

Permalink
chore(cli): plumb token header and token prefix oAuth (#5207)
Browse files Browse the repository at this point in the history
* plumb top level roles to FDR

* updated changelog

* add org id to run preview server

* plumbed header key

* changed name to token header

* chore: update changelog

* updated fdr

* changelog formatting

* chore: update changelog

* added example of setting the token-header and prefix, and added note to documentation

* chore: update changelog

* push fixture test and address comments

* chore: update changelog

* added yaml example to documentation

* fix merge conflicts

---------

Co-authored-by: fern-bot <[email protected]>
Co-authored-by: fern-bot <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent d71fe3d commit 6ca385c
Show file tree
Hide file tree
Showing 48 changed files with 492 additions and 60 deletions.
10 changes: 10 additions & 0 deletions api-yml.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,16 @@
}
]
},
"token-header": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"get-token": {
"$ref": "#/definitions/auth.OAuthGetTokenEndpointSchema"
},
Expand Down
20 changes: 20 additions & 0 deletions fern.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2656,6 +2656,26 @@
"type": "null"
}
]
},
"transport": {
"oneOf": [
{
"$ref": "#/definitions/service.ServiceTransport"
},
{
"type": "null"
}
]
},
"source": {
"oneOf": [
{
"$ref": "#/definitions/source.SourceSchema"
},
{
"type": "null"
}
]
}
},
"required": [
Expand Down
7 changes: 6 additions & 1 deletion fern/apis/fern-definition/definition/auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ types:
scopes: optional<list<string>>
client-id-env: optional<string>
client-secret-env: optional<string>
token-prefix: optional<string>
token-prefix:
type: optional<string>
docs: Sets the token header value prefix. Defaults to 'Bearer'
token-header:
type: optional<string>
docs: Sets the token header key name. Defaults to 'Authorization'
get-token: OAuthGetTokenEndpointSchema
refresh-token: optional<OAuthRefreshTokenEndpointSchema>

Expand Down
2 changes: 2 additions & 0 deletions fern/apis/fern-definition/definition/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ types:
errors: optional<ResponseErrorsSchema>
examples: optional<list<examples.ExampleEndpointCallSchema>>
pagination: optional<Pagination>
transport: optional<ServiceTransport>
source: optional<source.SourceSchema>

HttpMethodSchema:
enum:
Expand Down
18 changes: 17 additions & 1 deletion fern/pages/api-definition/fern-definition/auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,20 @@ If the `expires-in` property is set, the generated OAuth token provider will aut
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.
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>`:

```yaml api.yml {5-6}
auth-schemes:
OAuthScheme:
scheme: oauth
type: client-credentials
token-header: Fern-Authorization
token-prefix: Fern-Bearer
get-token:
...
```
10 changes: 10 additions & 0 deletions generators-yml.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@
}
]
},
"token-header": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"get-token": {
"$ref": "#/definitions/fernDefinition.auth.OAuthGetTokenEndpointSchema"
},
Expand Down
20 changes: 20 additions & 0 deletions package-yml.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2676,6 +2676,26 @@
"type": "null"
}
]
},
"transport": {
"oneOf": [
{
"$ref": "#/definitions/service.ServiceTransport"
},
{
"type": "null"
}
]
},
"source": {
"oneOf": [
{
"$ref": "#/definitions/source.SourceSchema"
},
{
"type": "null"
}
]
}
},
"required": [
Expand Down
18 changes: 18 additions & 0 deletions packages/cli/cli/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
- changelogEntry:
- summary: |
OAuth Client Credential Auth Scheme now supports the ability to optionally
set token header and prefix fields for use with docs playground.
```yml api.yml
auth-schemes:
OAuth:
scheme: oauth
type: client-credentials
token-header: Fern-Authorization
token-prefix: Fern-Bearer
...
```
type: feat
irVersion: 53
version: 0.45.0-rc48

- changelogEntry:
- summary: |
Support SDK generation provided comma-delineated content-type values in OpenAPI specs.
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/configuration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@fern-api/fs-utils": "workspace:*",
"@fern-api/task-context": "workspace:*",
"@fern-api/fern-definition-schema": "workspace:*",
"@fern-fern/fdr-cjs-sdk": "0.123.0-c32499d0e",
"@fern-fern/fdr-cjs-sdk": "0.126.1-444264056",
"@fern-fern/fiddle-sdk": "0.0.584",
"@fern-fern/generators-sdk": "0.114.0-5745f9e74",
"find-up": "^6.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/docs-importers/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@fern-api/configuration": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/task-context": "workspace:*",
"@fern-fern/fdr-cjs-sdk": "0.123.0-c32499d0e",
"@fern-fern/fdr-cjs-sdk": "0.126.1-444264056",
"js-yaml": "^4.1.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/docs-importers/mintlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@fern-api/task-context": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/logger": "workspace:*",
"@fern-fern/fdr-cjs-sdk": "0.123.0-c32499d0e",
"@fern-fern/fdr-cjs-sdk": "0.126.1-444264056",
"gray-matter": "^4.0.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/docs-markdown-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"@fern-api/fs-utils": "workspace:*",
"@fern-api/task-context": "workspace:*",
"@fern-fern/fdr-cjs-sdk": "0.123.0-c32499d0e",
"@fern-fern/fdr-cjs-sdk": "0.126.1-444264056",
"gray-matter": "^4.0.3",
"mdast-util-from-markdown": "^2.0.1",
"mdast-util-mdx": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/docs-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@fern-api/docs-resolver": "workspace:*",
"@fern-api/fdr-sdk": "0.123.0-c32499d0e",
"@fern-api/fdr-sdk": "0.126.1-444264056",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/ir-sdk": "workspace:*",
"@fern-api/logger": "workspace:*",
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/docs-preview/src/runPreviewServer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { wrapWithHttps } from "@fern-api/docs-resolver";
import { DocsV1Read, DocsV2Read } from "@fern-api/fdr-sdk";
import { FernNavigation, DocsV1Read, DocsV2Read } from "@fern-api/fdr-sdk";
import { dirname, doesPathExist, AbsoluteFilePath } from "@fern-api/fs-utils";
import { Project } from "@fern-api/project-loader";
import { TaskContext } from "@fern-api/task-context";
Expand Down Expand Up @@ -189,7 +189,8 @@ export async function runPreviewServer({
basePath: instance.pathname
},
definition,
lightModeEnabled: definition.config.colorsV3?.type !== "dark"
lightModeEnabled: definition.config.colorsV3?.type !== "dark",
orgId: FernNavigation.OrgId(initialProject.config.organization)
};
res.send(response);
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/docs-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"@fern-api/configuration": "workspace:*",
"@fern-api/core-utils": "workspace:*",
"@fern-api/docs-markdown-utils": "workspace:*",
"@fern-api/fdr-sdk": "0.123.0-c32499d0e",
"@fern-api/ui-core-utils": "0.123.0-c32499d0e",
"@fern-api/fdr-sdk": "0.126.1-444264056",
"@fern-api/ui-core-utils": "0.126.1-444264056",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/ir-generator": "workspace:*",
"@fern-api/ir-sdk": "workspace:*",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/docs-resolver/src/DocsDefinitionResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ export class DocsDefinitionResolver {
pointsTo: undefined,
authed: undefined,
viewers: undefined,
orphaned: undefined
orphaned: undefined,
roles: this.parsedDocsConfig.roles?.map((role) => FernNavigation.RoleId(role))
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/ete-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@fern-api/configuration": "workspace:*",
"@fern-fern/fdr-cjs-sdk": "0.123.0-c32499d0e",
"@fern-fern/fdr-cjs-sdk": "0.126.1-444264056",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/logging-execa": "workspace:*",
"@fern-typescript/fetcher": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/ete-tests/src/tests/docs-dev/docsDev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("fern docs dev", () => {
const responseBody = JSON.parse(responseText) as FdrCjsSdk.docs.v2.read.LoadDocsForUrlResponse;
expect(typeof responseBody === "object").toEqual(true);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(Object.keys(responseBody as any)).toEqual(["baseUrl", "definition", "lightModeEnabled"]);
expect(Object.keys(responseBody as any)).toEqual(["baseUrl", "definition", "lightModeEnabled", "orgId"]);

// const root = FernNavigation.utils.convertLoadDocsForUrlResponse(responseBody);
// const pageIds = new Set(Object.keys(responseBody.definition.pages));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export interface OAuthSchemeSchema extends FernDefinition.WithDocsSchema {
scopes?: string[];
"client-id-env"?: string;
"client-secret-env"?: string;
/** Sets the token header value prefix. Defaults to 'Bearer' */
"token-prefix"?: string;
/** Sets the token header key name. Defaults to 'Authorization' */
"token-header"?: string;
"get-token": FernDefinition.OAuthGetTokenEndpointSchema;
"refresh-token"?: FernDefinition.OAuthRefreshTokenEndpointSchema;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const OAuthSchemeSchema: core.serialization.ObjectSchema<
"client-id-env": core.serialization.string().optional(),
"client-secret-env": core.serialization.string().optional(),
"token-prefix": core.serialization.string().optional(),
"token-header": core.serialization.string().optional(),
"get-token": OAuthGetTokenEndpointSchema,
"refresh-token": OAuthRefreshTokenEndpointSchema.optional(),
})
Expand All @@ -33,6 +34,7 @@ export declare namespace OAuthSchemeSchema {
"client-id-env"?: string | null;
"client-secret-env"?: string | null;
"token-prefix"?: string | null;
"token-header"?: string | null;
"get-token": OAuthGetTokenEndpointSchema.Raw;
"refresh-token"?: OAuthRefreshTokenEndpointSchema.Raw | null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"clientIdEnvVar": "MY_CLIENT_ID",
"clientSecretEnvVar": "MY_CLIENT_SECRET",
"tokenPrefix": null,
"tokenHeader": null,
"scopes": null,
"tokenEndpoint": {
"endpointReference": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"clientIdEnvVar": null,
"clientSecretEnvVar": null,
"tokenPrefix": null,
"tokenHeader": null,
"scopes": null,
"tokenEndpoint": {
"endpointReference": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"clientIdEnvVar": "CLIENT_ID",
"clientSecretEnvVar": "CLIENT_SECRET",
"tokenPrefix": null,
"tokenHeader": null,
"scopes": null,
"tokenEndpoint": {
"endpointReference": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"clientIdEnvVar": null,
"clientSecretEnvVar": null,
"tokenPrefix": null,
"tokenHeader": null,
"scopes": null,
"tokenEndpoint": {
"endpointReference": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"clientIdEnvVar": null,
"clientSecretEnvVar": null,
"tokenPrefix": null,
"tokenHeader": null,
"scopes": null,
"tokenEndpoint": {
"endpointReference": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export async function convertOAuthClientCredentials({
clientIdEnvVar: oauthScheme["client-id-env"],
clientSecretEnvVar: oauthScheme["client-secret-env"],
tokenPrefix: oauthScheme["token-prefix"],
tokenHeader: oauthScheme["token-header"],
scopes: oauthScheme.scopes,
tokenEndpoint: oauthTokenEndpoint,
refreshEndpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@fern-api/core-utils": "workspace:*",
"@fern-api/docs-resolver": "workspace:*",
"@fern-api/logging-execa": "workspace:*",
"@fern-fern/fdr-cjs-sdk": "0.123.0-c32499d0e",
"@fern-fern/fdr-cjs-sdk": "0.126.1-444264056",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/ir-generator": "workspace:*",
"@fern-api/ir-migrations": "workspace:*",
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/lazy-fern-workspace/src/api-yml.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,16 @@
}
]
},
"token-header": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"get-token": {
"$ref": "#/definitions/auth.OAuthGetTokenEndpointSchema"
},
Expand Down
20 changes: 20 additions & 0 deletions packages/cli/lazy-fern-workspace/src/fern.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2656,6 +2656,26 @@
"type": "null"
}
]
},
"transport": {
"oneOf": [
{
"$ref": "#/definitions/service.ServiceTransport"
},
{
"type": "null"
}
]
},
"source": {
"oneOf": [
{
"$ref": "#/definitions/source.SourceSchema"
},
{
"type": "null"
}
]
}
},
"required": [
Expand Down
Loading

0 comments on commit 6ca385c

Please sign in to comment.