Simple Security Schemes
Basic HTTP Authentication
Basic HTTP authentication is supported in all languages.
Define type: http
& scheme: basic
to generate authentication that prompts users for a username and password when instantiating the SDK. The SDK will encode the username and password into a Base64 string and pass it in the Authorization
header.
paths: /drinks: get: operationId: listDrinks summary: Get a list of drinks. description: Get a list of drinks, if authenticated this will include stock levels and product codes otherwise it will only include public information. tags: - drinkscomponents: securitySchemes: auth: type: http scheme: basicsecurity: - auth: []
import { SDK } from "speakeasy";async function run() { const sdk = new SDK({ security: { username: "<YOUR_USERNAME_HERE>", password: "<YOUR_PASSWORD_HERE>", }, }); const result = await sdk.drinks.listDrinks(); // Handle the result console.log(result);}run();
API Key Authentication
API key authentication is supported in all languages.
Define type: apiKey
& in: [header,query]
to generate authentication that prompts users for a key when instantiating the SDK. The SDK passes the key in a header or query parameter, depending on the in
property, and uses the name
field as the header or key name.
paths: /drinks: get: operationId: listDrinks summary: Get a list of drinks. description: Get a list of drinks, if authenticated this will include stock levels and product codes otherwise it will only include public information. tags: - drinks responses: "200": description: OK #...components: securitySchemes: api_key: type: apiKey name: api_key in: headersecurity: - api_key: []
import { SDK } from "speakeasy";async function run() { const sdk = new SDK({ apiKey: "<YOUR_API_KEY_HERE>", }); const result = await sdk.drinks.listDrinks(); // Handle the result console.log(result);}run();
Bearer Token Authentication
Bearer token authentication is supported in all languages.
Define type: http
& scheme: bearer
to generate authentication that prompts users for a token when instantiating the SDK.
The SDK will pass the token in the Authorization
header using the Bearer
scheme, appending the Bearer
prefix to the token if not already present.
paths: /drinks: get: operationId: listDrinks summary: Get a list of drinks. description: Get a list of drinks, if authenticated this will include stock levels and product codes otherwise it will only include public information. tags: - drinkscomponents: securitySchemes: auth: type: http scheme: bearersecurity: - auth: []
import { SDK } from "speakeasy";async function run() { const sdk = new SDK({ auth: "<YOUR_BEARER_TOKEN_HERE>", }); const result = await sdk.drinks.listDrinks(); // Handle the result console.log(result);}run();