SDKs
Security callbacks
Instead of providing credentials once during SDK instantiation, pass a custom authentication function that allows end users to manage secrets dynamically. Custom authentication functions can be used to automatically refresh tokens or retrieve secrets from a secret store.
Language support
Section titled “Language support”Language
TypeScript
Status
✅
Python
Status
✅
Go
Status
✅
C#
Status
✅
Java
Status
✅
PHP
Status
✅
Ruby
Status
✅
Example: Bearer authentication
Section titled “Example: Bearer authentication”In this example, bearer authentication is used as the only security scheme:
security: - bearerAuth: []components: securitySchemes: bearerAuth: type: http scheme: bearerThe callback function passed when initializing the SDK acts as a security source and is called whenever a request is made, allowing tokens to be refreshed if needed.
import { SDK } from "<packageName>";import { Security } from "<packageName>/models"; const sdk = new SDK({ security: async (): Promise<Security> => { // refresh token here const token = "<YOUR_JWT>"; return { bearerAuth: token }; },});import requestsimport sdkfrom sdk.components import Security def callback() -> Security: # refresh token here token = "<YOUR_JWT>" return Security(bearer_auth=token) s = sdk.SDK(security=with_authorization(callback))import ( "context" sdk "speakeasy" "speakeasy/components") s := sdk.New( sdk.WithSecuritySource(func(ctx context.Context) (components.Security, error) { // refresh token here token := "<YOUR_JWT>" return components.Security{BearerAuth: token}, nil }),)import dev.speakeasyapi.speakeasy.SDK;import dev.speakeasyapi.speakeasy.SecuritySource;import dev.speakeasyapi.speakeasy.models.components.Security; class BearerSource implements SecuritySource { public Security getSecurity() { // refresh token here return Security.builder() .bearerAuth("<YOUR_JWT>") .build(); }} _____________________________________ import dev.speakeasyapi.speakeasy.SDK;import dev.speakeasyapi.speakeasy.SecuritySource;import dev.speakeasyapi.speakeasy.models.components.Security; SDK s = SDK.builder() .securitySource(new BearerSource()) .build();using Speakeasy;using Speakeasy.Models.Components; Func<Security> tokenSource = () =>{ // refresh token here var token = "<YOUR_JWT>" return new Security { BearerAuth = token}} var sdk = new SDK(securitySource: tokenSource);use Speakeasy\Speakeasy; $sdk = Speakeasy\SDK::builder() ->setSecuritySource( function (): Security { //refresh token here var token = "<YOUR_JWT>"; return new Security(bearerAuth: $token); } )->build(); try { $res = $sdk->drinks->listDrinks(); if ($res->Drinks != null) { // handle response }} catch (Errors\ErrorThrowable $e) { // handle exception}require 'speakeasy' sdk = Speakeasy::SDK.new( security_source: -> { # Refresh token here token = '<YOUR_JWT>' Models::Components::Security.new(bearer_auth: token) }) res = sdk.drinks.list_drinks