Overview
The Auth0 Go SDK provides two mechanisms for working with fields that aren’t included in the generated types:- ExtraProperties - Available on select request/response types for capturing additional fields
- WithBodyProperties - Request option for adding custom fields to any request body
- Working with custom metadata fields
- Using advanced configuration options not yet in the SDK
- Handling fields that may be added to the Auth0 API
- Accessing beta or experimental API features
ExtraProperties Field
Some SDK types include anExtraProperties field (map[string]interface{}) that works in both directions:
- In Requests: Send additional fields to Auth0
- In Responses: Capture additional fields returned by Auth0
Setting ExtraProperties in Requests
Add custom fields directly to request structures:Nested ExtraProperties Example
Complex nested structures work seamlessly:Reading ExtraProperties from Responses
Access additional fields returned by Auth0:WithBodyProperties Request Option
TheWithBodyProperties option allows adding custom fields to any request body, even for types without ExtraProperties:
Setting Fields to Null
UseWithBodyProperties to explicitly set fields to null:
ExtraProperties vs WithBodyProperties
ExtraProperties
When to use:
- Type has
ExtraPropertiesfield - Need to read extra fields from responses
- Want type-safe structure access
- More idiomatic Go code
- Access to response extra fields
- Clear structure in code
WithBodyProperties
When to use:
- Type lacks
ExtraPropertiesfield - Need to set fields to null
- Adding fields to any request
- Works with any request type
- Can override standard fields
- Flexible for one-off needs
Combining Both Approaches
You can use both mechanisms together:Type Assertions and Safety
When reading fromExtraProperties, always use type assertions safely:
JSON Number Handling
Real-World Examples
Custom Client Metadata
Connection Configuration
Best Practices
Document Custom Fields
Maintain documentation of any custom fields you use, including their purpose, type, and valid values.
Related Topics
- Request Options - Other request configuration options
- Custom Token Sources - Advanced authentication
- Error Handling - Handle API errors