Overview
Authentication forms allow plugins to collect structured connection credentials through a user-friendly interface. Instead of a single DSN text field, plugins can define multiple forms with typed fields (text, password, number, select, checkbox, file path). Auth forms are returned by theauthforms command and rendered as tabbed interfaces in the QueryBox connection dialog.
AuthForms Response Structure
Field Types
QueryBox supports six field types, exported as constants inpkg/plugin/plugin.go:97-102:
Field Type Reference
| Type | Constant | Input Type | Use Case |
|---|---|---|---|
| Text | AuthFieldText | Single-line text | Host, username, database name |
| Number | AuthFieldNumber | Numeric input | Port numbers |
| Password | AuthFieldPassword | Masked text | Passwords, API keys |
| Select | AuthFieldSelect | Dropdown | TLS modes, regions, protocols |
| Checkbox | AuthFieldCheckbox | Boolean | Enable TLS, SSL verify |
| File Path | AuthFieldFilePath | File picker | Local database files, certificates |
Basic Example
Fromplugins/template/main.go:53-60:
Multiple Forms
Plugins can provide multiple authentication methods. Each form appears as a separate tab in the UI.Example: MySQL (Basic + DSN)
Fromplugins/mysql/main.go:39-64:
Example: Redis (Basic + URL)
Fromplugins/redis/main.go:40-60:
Advanced Field Types
Select Dropdowns
Provide a list of predefined options:Checkboxes
Boolean toggles (stored as “true” or “false” strings):File Path Picker
For local database files or certificates:Processing Form Data
When a user submits a form, QueryBox serializes the values as JSON and stores them in thecredential_blob field of the connection map:
Parsing Credential Blob
Fromplugins/mysql/main.go:76-144:
Best Practices
Provide Sensible Defaults
Set default values for common fields to reduce user input:Mark Required Fields
Use theRequired flag to enforce mandatory inputs:
Use Placeholders as Examples
Help users understand the expected format:Offer Multiple Connection Methods
Provide both simple and advanced forms:- Basic: Individual fields for common parameters (easier for beginners)
- DSN/URL: Single connection string (faster for experts)
Handle Legacy Connections
Support both new credential_blob format and legacy DSN keys:Validate Input Early
UseTestConnection to validate credentials before saving:
Fallback Behavior
Plugins that do not implementauthforms fall back to a single text input for a DSN or credential string. To provide a better user experience, always implement AuthForms even if you only offer a single simple form.
Example: MongoDB
Fromplugins/mongodb/main.go:43-65: