Simple security schemes

Basic HTTP authentication

Basic HTTP authentication is supported in all languages.

Define type: http and 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:
- drinks
components:
securitySchemes:
auth:
type: http
scheme: basic
security:
- 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 and 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: header
security:
- 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 and 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:
- drinks
components:
securitySchemes:
auth:
type: http
scheme: bearer
security:
- 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();