Overview
All request option functions return aRequestOption type that can be passed to API methods. Multiple options can be combined by passing them as separate arguments.
Example:
Authentication Options
WithToken
Authorization: Bearer <token> request header with a static token.
Note: If a TokenSource is also configured (via WithClientCredentials, WithClientCredentialsPrivateKeyJwt, or WithTokenSource), the TokenSource takes priority and this static token will be ignored.
Example:
WithClientCredentials
WithClientCredentialsAndAudience
WithClientCredentialsPrivateKeyJwt
WithClientCredentialsPrivateKeyJwtAndAudience
WithTokenSource
oauth2.TokenSource for acquiring access tokens. This allows users to provide their own token management strategy, such as caching tokens across multiple services or using a custom token provider.
The SDK calls TokenSource.Token() on every request to obtain the access token. If token caching is desired, wrap the source with oauth2.ReuseTokenSource:
WithToken.
Example:
HTTP Configuration
WithBaseURL
WithHTTPClient
WithHTTPHeader
http.Header to the request. The headers are cloned so they can’t be modified after the option call.
Example:
WithMaxAttempts
Request Parameters
WithQueryParameters
WithBodyProperties
Debugging and Diagnostics
WithDebug
WithUserAgent
WithAuth0ClientEnvEntry
WithNoAuth0ClientInfo
Advanced Options
WithCustomDomainHeader
WithInsecure
Combining Multiple Options
You can pass multiple request options to customize the behavior of a single API call:Best Practices
- Use request options sparingly: Most API calls work fine with default settings. Only use options when you need custom behavior.
- Prefer client-level configuration: If you need the same option for all requests, configure it at the client level instead of passing it to every method.
- Be careful with authentication options: Token source options are mutually exclusive. Only use one per request.
- Don’t use WithInsecure in production: This option is for testing only and should never be used in production environments.
- Enable debug logging carefully: Debug mode logs sensitive information. Only enable it during development.
See Also
- Pointer Helpers - Helper functions for pointer types
- Error Types - Handle API errors