@logto/api
v1.36.0
Published
Logto API types and clients.
Readme
@logto/api
A TypeScript SDK for interacting with Logto's Management API using client credentials authentication.
Installation
npm install @logto/apiQuick start
Prerequisites
Before using this SDK, you need to:
- Create a machine-to-machine application in your Logto Console
- Grant the application access to the Management API
- Note down the client ID and client secret
For detailed setup instructions, visit: https://a.logto.io/m2m-mapi
Basic usage
Logto Cloud
import { createManagementApi } from '@logto/api/management';
// For Logto Cloud
const { apiClient } = createManagementApi('your-tenant-id', {
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
});
// Make API calls
const response = await apiClient.GET('/api/users');
console.log(response.data);Self-hosted / OSS
import { createManagementApi } from '@logto/api/management';
const { apiClient } = createManagementApi('default', {
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
baseUrl: 'https://your-logto-instance.com',
apiIndicator: 'https://your-logto-instance.com/api',
});Custom authentication
For advanced use cases where you need full control over the authentication logic, use createApiClient:
import { createApiClient } from '@logto/api/management';
const client = createApiClient({
baseUrl: 'https://your-logto-instance.com',
getToken: async () => {
// Your custom token retrieval logic
return getYourToken();
},
});
// Type-safe API calls
const response = await client.GET('/api/applications/{id}', {
params: { path: { id: 'your-app-id' } },
});API documentation
For detailed API documentation, refer to the Logto Management API documentation.
Development
To avoid unnecessary build time in CI, full type generation only happens before publishing. The build script will generate mock types if no types are found.
To explicitly generate types, run:
pnpm generate-typesThis will start a local Docker Compose environment, generate types by fetching the OpenAPI endpoints, and then shut down the environment.
