Kest

Search

Search the documentation

OpenAPI

Security

Describe how clients authenticate.

Mark endpoints with @ApiBearerAuth (or protect them with @Authenticated / @Roles), and declare how a client authenticates when you turn the docs on:

app.http(adapter) {
    useDocs {
        title = "Shop API"
        security {
            bearer()                                                         // Authorization: Bearer <JWT>
            apiKey("X-API-Key")                                              // a key in a header (location = "query" or "cookie" also work)
            basic()                                                          // Authorization: Basic ...
            oauth2("https://idp.example/authorize", "https://idp.example/token", mapOf("read" to "Read data"))
            openIdConnect("https://idp.example/.well-known/openid-configuration")
        }
    }
}

The schemes appear under components.securitySchemes in /docs/openapi.json, and every secured operation lists them as alternatives (any one is enough). With no security { } block a bearer token is assumed.

Postman, Swagger UI and code generators read this and offer the right sign-in. The built-in reference site's Authorize button sends a bearer token; the other schemes are described in the export but not yet in its sandbox.

Read more