Authentication
Model auth schemes for JSON-RPC APIs including bearer, basic, and api key authentication
Authentication in OpenRPC can be configured at the server level or method level, depending on your JSON-RPC implementation. Unlike REST APIs, JSON-RPC typically handles authentication through the transport layer (HTTP headers) or within the JSON-RPC request payload.
HTTP Transport Authentication
When using HTTP as the transport for JSON-RPC, you can use standard HTTP authentication schemes.
Bearer Token Authentication
Configure bearer token authentication for HTTP-based JSON-RPC:
This generates SDK methods that require a token:
API Key Authentication
Configure API key authentication:
Usage in SDK:
Basic Authentication
Configure basic authentication:
Usage in SDK:
Method-Level Authentication
Some JSON-RPC implementations may require different authentication for specific methods:
WebSocket Authentication
For WebSocket transport, authentication typically happens during connection establishment:
Custom Authentication Parameters
For JSON-RPC APIs that handle authentication within the request payload:
Fern Extensions for Authentication
Use Fern extensions to customize authentication behavior:
This allows users to set authentication via environment variables or constructor parameters, making the SDK more flexible and secure.
Error Handling for Authentication
Define standardized error responses for authentication failures:
These error codes follow JSON-RPC 2.0 conventions while providing clear authentication feedback to API consumers.