go.bigb.es/go-bitwarden
Documentation
Index
- type APIError
- type Attachment
- type AttachmentsAPI
- type AttachmentsService
- type Card
- type Client
- func NewClient(opts ...ClientOption) *Client
- func (*Client) Attachments() AttachmentsAPI
- func (*Client) Collections() CollectionsAPI
- func (*Client) Folders() FoldersAPI
- func (*Client) Generate(ctx context.Context, opts GenerateOptions) (string, error)
- func (*Client) Items() ItemsAPI
- func (*Client) Lock(ctx context.Context) error
- func (*Client) OrgCollections() OrgCollectionsAPI
- func (*Client) OrgMembers() OrgMembersAPI
- func (*Client) Organizations() OrganizationsAPI
- func (*Client) Send() SendAPI
- func (*Client) Status(ctx context.Context) (*Status, error)
- func (*Client) Sync(ctx context.Context) error
- func (*Client) Unlock(ctx context.Context, password string) error
- type ClientOption
- type Collection
- type CollectionsAPI
- type CollectionsService
- type ConfirmRequest
- type DirectAttachmentsService
- func (*DirectAttachmentsService) Create(ctx context.Context, itemID, filename string, file io.Reader) (*Item, error)
- func (*DirectAttachmentsService) Delete(ctx context.Context, attachmentID, itemID string) error
- func (*DirectAttachmentsService) Get(ctx context.Context, attachmentID, itemID string) ([]byte, error)
- type DirectClient
- func NewDirectClient(serverURL, email, password string, opts ...DirectClientOption) *DirectClient
- func (*DirectClient) Attachments() AttachmentsAPI
- func (*DirectClient) Collections() CollectionsAPI
- func (*DirectClient) Folders() FoldersAPI
- func (*DirectClient) Generate(ctx context.Context, opts GenerateOptions) (string, error)
- func (*DirectClient) GetAPIKey(ctx context.Context) (clientID, clientSecret string, err error)
- func (*DirectClient) Items() ItemsAPI
- func (*DirectClient) Lock(ctx context.Context) error
- func (*DirectClient) Login(ctx context.Context) error
- func (*DirectClient) OrgCollections() OrgCollectionsAPI
- func (*DirectClient) OrgMembers() OrgMembersAPI
- func (*DirectClient) Organizations() OrganizationsAPI
- func (*DirectClient) Register(ctx context.Context, name string, cfg crypto.DeriveKeyConfig) error
- func (*DirectClient) Send() SendAPI
- func (*DirectClient) ServerURL() string
- func (*DirectClient) SetNotificationsLogger(l *log.Logger)
- func (*DirectClient) StartNotifications(ctx context.Context) error
- func (*DirectClient) Status(ctx context.Context) (*Status, error)
- func (*DirectClient) StopNotifications() error
- func (*DirectClient) Sync(ctx context.Context) error
- func (*DirectClient) Unlock(ctx context.Context, password string) error
- type DirectClientOption
- func WithAPIKey(clientID, clientSecret string) DirectClientOption
- func WithDeviceInfo(name, identifier string, deviceType int) DirectClientOption
- func WithDirectHTTPClient(hc *http.Client) DirectClientOption
- func WithIdentityURL(url string) DirectClientOption
- func WithNotificationHandler(h NotificationHandler) DirectClientOption
- func WithTwoFactorProvider(p api.TwoFactorProvider) DirectClientOption
- type DirectCollectionsService
- type DirectFoldersService
- func (*DirectFoldersService) Create(ctx context.Context, folder Folder) (*Folder, error)
- func (*DirectFoldersService) Delete(ctx context.Context, id string) error
- func (*DirectFoldersService) Get(ctx context.Context, id string) (*Folder, error)
- func (*DirectFoldersService) List(ctx context.Context, search string) ([]Folder, error)
- func (*DirectFoldersService) Update(ctx context.Context, id string, folder Folder) (*Folder, error)
- type DirectItemsService
- func (*DirectItemsService) Create(ctx context.Context, item Item) (*Item, error)
- func (*DirectItemsService) Delete(ctx context.Context, id string) error
- func (*DirectItemsService) Get(ctx context.Context, id string) (*Item, error)
- func (*DirectItemsService) List(ctx context.Context, filter ListFilter) ([]Item, error)
- func (*DirectItemsService) Move(ctx context.Context, id, organizationID string, collectionIDs []string) error
- func (*DirectItemsService) Restore(ctx context.Context, id string) error
- func (*DirectItemsService) Update(ctx context.Context, id string, item Item) (*Item, error)
- type DirectOrgCollectionsService
- func (*DirectOrgCollectionsService) Create(ctx context.Context, collection OrgCollection) (*OrgCollection, error)
- func (*DirectOrgCollectionsService) Delete(ctx context.Context, id string) error
- func (*DirectOrgCollectionsService) Get(ctx context.Context, id string) (*OrgCollection, error)
- func (*DirectOrgCollectionsService) List(ctx context.Context, organizationID string, search string) ([]OrgCollection, error)
- func (*DirectOrgCollectionsService) Update(ctx context.Context, id string, collection OrgCollection) (*OrgCollection, error)
- type DirectOrgMembersService
- type DirectOrganizationsService
- type DirectSendService
- func (*DirectSendService) Create(ctx context.Context, send Send) (*Send, error)
- func (*DirectSendService) Delete(ctx context.Context, id string) error
- func (*DirectSendService) Get(ctx context.Context, id string) (*Send, error)
- func (*DirectSendService) List(ctx context.Context) ([]Send, error)
- func (*DirectSendService) RemovePassword(ctx context.Context, id string) (*Send, error)
- func (*DirectSendService) Update(ctx context.Context, id string, send Send) (*Send, error)
- type Duration
- type Field
- type FieldType
- type Folder
- type FoldersAPI
- type FoldersService
- func (*FoldersService) Create(ctx context.Context, folder Folder) (*Folder, error)
- func (*FoldersService) Delete(ctx context.Context, id string) error
- func (*FoldersService) Get(ctx context.Context, id string) (*Folder, error)
- func (*FoldersService) List(ctx context.Context, search string) ([]Folder, error)
- func (*FoldersService) Update(ctx context.Context, id string, folder Folder) (*Folder, error)
- type GenerateOptions
- type GenerateResponse
- type Identity
- type Item
- type ItemType
- type ItemsAPI
- type ItemsService
- func (*ItemsService) Create(ctx context.Context, item Item) (*Item, error)
- func (*ItemsService) Delete(ctx context.Context, id string) error
- func (*ItemsService) Get(ctx context.Context, id string) (*Item, error)
- func (*ItemsService) List(ctx context.Context, filter ListFilter) ([]Item, error)
- func (*ItemsService) Move(ctx context.Context, id, organizationID string, collectionIDs []string) error
- func (*ItemsService) Restore(ctx context.Context, id string) error
- func (*ItemsService) Update(ctx context.Context, id string, item Item) (*Item, error)
- type ListFilter
- type ListResponse
- type Login
- type LoginURI
- type MessageResponse
- type MoveRequest
- type NotFoundError
- type NotificationHandler
- type NotificationPayload
- type NotificationType
- type ObjectResponse
- type OrgCollection
- type OrgCollectionsAPI
- type OrgCollectionsService
- func (*OrgCollectionsService) Create(ctx context.Context, collection OrgCollection) (*OrgCollection, error)
- func (*OrgCollectionsService) Delete(ctx context.Context, id string) error
- func (*OrgCollectionsService) Get(ctx context.Context, id string) (*OrgCollection, error)
- func (*OrgCollectionsService) List(ctx context.Context, organizationID string, search string) ([]OrgCollection, error)
- func (*OrgCollectionsService) Update(ctx context.Context, id string, collection OrgCollection) (*OrgCollection, error)
- type OrgMember
- type OrgMembersAPI
- type OrgMembersService
- type Organization
- type OrganizationsAPI
- type OrganizationsService
- type PasswordHistory
- type SecureNote
- type Send
- type SendAPI
- type SendFile
- type SendService
- func (*SendService) Create(ctx context.Context, send Send) (*Send, error)
- func (*SendService) Delete(ctx context.Context, id string) error
- func (*SendService) Get(ctx context.Context, id string) (*Send, error)
- func (*SendService) List(ctx context.Context) ([]Send, error)
- func (*SendService) RemovePassword(ctx context.Context, id string) (*Send, error)
- func (*SendService) Update(ctx context.Context, id string, send Send) (*Send, error)
- type SendText
- type SendType
- type Status
- type StatusResponse
- type SyncResponse
- type TemplateType
- type URIMatchType
- type UnlockRequest
- type VaultClient
- type VaultLockedError
Constants
const ( NotifSyncCipherUpdate = api.NotifSyncCipherUpdate NotifSyncCipherCreate = api.NotifSyncCipherCreate NotifSyncLoginDelete = api.NotifSyncLoginDelete NotifSyncFolderDelete = api.NotifSyncFolderDelete NotifSyncCiphers = api.NotifSyncCiphers NotifSyncVault = api.NotifSyncVault NotifSyncOrgKeys = api.NotifSyncOrgKeys NotifSyncFolderCreate = api.NotifSyncFolderCreate NotifSyncFolderUpdate = api.NotifSyncFolderUpdate NotifSyncCipherDelete = api.NotifSyncCipherDelete NotifSyncSettings = api.NotifSyncSettings NotifLogOut = api.NotifLogOut NotifSyncSendCreate = api.NotifSyncSendCreate NotifSyncSendUpdate = api.NotifSyncSendUpdate NotifSyncSendDelete = api.NotifSyncSendDelete NotifAuthRequest = api.NotifAuthRequest NotifAuthRequestResponse = api.NotifAuthRequestResponse )
Notification type constants.
Types
type APIError struct { StatusCode int Message string }
APIError represents an error response from the bw serve API.
type Attachment struct { ID string `json:"id"` FileName string `json:"fileName"` Size string `json:"size"` SizeName string `json:"sizeName"` URL string `json:"url"` }
Attachment represents a file attachment on a vault item.
type AttachmentsAPI interface { // Create uploads a file attachment to a vault item. Create(ctx context.Context, itemID, filename string, file io.Reader) (*Item, error) // Get downloads a file attachment's contents. Get(ctx context.Context, attachmentID, itemID string) ([]byte, error) // Delete removes a file attachment from a vault item. Delete(ctx context.Context, attachmentID, itemID string) error }
AttachmentsAPI defines operations on file attachments for vault items.
type AttachmentsService struct { // contains filtered or unexported fields }
AttachmentsService handles file attachment operations.
func (s *AttachmentsService) Create(ctx context.Context, itemID, filename string, file io.Reader) (*Item, error)
Create uploads a file attachment to a vault item.
func (s *AttachmentsService) Delete(ctx context.Context, attachmentID, itemID string) error
Delete removes an attachment by ID from a vault item.
func (s *AttachmentsService) Get(ctx context.Context, attachmentID, itemID string) ([]byte, error)
Get downloads an attachment by ID from a vault item. Returns the raw file contents.
type Card struct { CardholderName string `json:"cardholderName,omitempty"` Brand string `json:"brand,omitempty"` Number string `json:"number,omitempty"` ExpMonth string `json:"expMonth,omitempty"` ExpYear string `json:"expYear,omitempty"` Code string `json:"code,omitempty"` }
Card represents card-specific fields of a vault item.
type Client struct { // contains filtered or unexported fields }
Client provides access to a Bitwarden vault via the bw serve API. It requires the Bitwarden CLI to be running in serve mode (bw serve). Client implements the VaultClient interface.
For direct server communication without the CLI, use DirectClient instead.
NewClient creates a new Bitwarden vault management client that communicates via the bw serve API. The client is created in a locked state and must be unlocked using Unlock() before accessing vault data.
Options can be provided to customize the client behavior:
client := bitwarden.NewClient(
bitwarden.WithBaseURL("http://localhost:8087"),
bitwarden.WithHTTPClient(customHTTPClient),
)
func (c *Client) Attachments() AttachmentsAPI
Attachments returns the attachments service for file attachment operations.
func (c *Client) Collections() CollectionsAPI
Collections returns the collections service for accessing user collections.
func (c *Client) Folders() FoldersAPI
Folders returns the folders service for organizing vault items.
func (c *Client) Generate(ctx context.Context, opts GenerateOptions) (string, error)
Generate generates a password or passphrase based on the provided options. Use GenerateOptions to configure password length, character sets, or passphrase settings.
Items returns the vault items (ciphers) service for CRUD operations on vault items.
func (c *Client) Lock(ctx context.Context) error
Lock locks the vault, clearing encryption keys from memory. After locking, Unlock must be called before accessing vault data.
func (c *Client) OrgCollections() OrgCollectionsAPI
OrgCollections returns the organization collections service for managing org collections.
func (c *Client) OrgMembers() OrgMembersAPI
OrgMembers returns the organization members service for member management.
func (c *Client) Organizations() OrganizationsAPI
Organizations returns the organizations service for listing user organizations.
Send returns the Bitwarden Send service for creating secure shares.
func (c *Client) Status(ctx context.Context) (*Status, error)
Status returns the current status of the Bitwarden CLI including lock state, user information, and server URL.
func (c *Client) Sync(ctx context.Context) error
Sync triggers a vault synchronization with the server. This downloads the latest vault data and updates the local cache.
func (c *Client) Unlock(ctx context.Context, password string) error
Unlock unlocks the vault with the given master password. The vault must be unlocked before accessing any vault data.
type ClientOption func(*Client)
ClientOption configures the Client using the functional options pattern.
func WithBaseURL(u string) ClientOption
WithBaseURL sets the base URL for the bw serve API. Default is "http://localhost:8087".
func WithHTTPClient(hc *http.Client) ClientOption
WithHTTPClient sets a custom http.Client for API requests. Use this to configure timeouts, proxies, or custom transport.
type Collection struct { Object string `json:"object,omitempty"` ID string `json:"id,omitempty"` OrganizationID string `json:"organizationId,omitempty"` Name string `json:"name"` ExternalID string `json:"externalId,omitempty"` }
Collection represents a vault collection.
type CollectionsAPI interface { // List retrieves collections visible to the user with optional filtering. List(ctx context.Context, organizationID, search string) ([]Collection, error) // Get retrieves a single collection by its ID. Get(ctx context.Context, id string) (*Collection, error) }
CollectionsAPI defines read-only operations on user collections. Collections are groups of items owned by organizations.
type CollectionsService struct { // contains filtered or unexported fields }
CollectionsService handles collection operations (read-only for user collections).
func (s *CollectionsService) Get(ctx context.Context, id string) (*Collection, error)
Get returns a single collection by ID.
func (s *CollectionsService) List(ctx context.Context, organizationID, search string) ([]Collection, error)
List returns all collections, optionally filtered.
type ConfirmRequest struct { OrganizationID string `json:"organizationId"` }
ConfirmRequest is the body for POST /confirm/org-member/:id.
type DirectAttachmentsService struct { // contains filtered or unexported fields }
DirectAttachmentsService handles attachment operations via the direct server API.
func (s *DirectAttachmentsService) Create(ctx context.Context, itemID, filename string, file io.Reader) (*Item, error)
func (s *DirectAttachmentsService) Delete(ctx context.Context, attachmentID, itemID string) error
func (s *DirectAttachmentsService) Get(ctx context.Context, attachmentID, itemID string) ([]byte, error)
type DirectClient struct { // contains filtered or unexported fields }
DirectClient communicates directly with a Bitwarden/Vaultwarden server, handling authentication and end-to-end encryption entirely in Go without requiring the Bitwarden CLI. This is useful for applications that need to integrate Bitwarden functionality without external dependencies.
DirectClient implements the VaultClient interface and provides full access to vault operations including items, folders, collections, organizations, Send, and attachments.
Security considerations:
- The master password is kept in memory for re-authentication
- Encryption keys are derived from the master password using PBKDF2 or Argon2id
- All vault data is encrypted/decrypted locally
- Keys can be cleared from memory using Lock()
func NewDirectClient(serverURL, email, password string, opts ...DirectClientOption) *DirectClient
NewDirectClient creates a new client that communicates directly with the Bitwarden/Vaultwarden server without requiring the CLI. The client handles authentication and end-to-end encryption automatically.
Parameters:
- serverURL: The base URL of the Bitwarden/Vaultwarden server (e.g., "https://vault.bitwarden.com")
- email: The user's email address for authentication
- password: The master password for vault decryption
- opts: Optional configuration using With* functions
The client is created in a locked state. Call Login() first, then Unlock() or call Unlock() directly which handles both authentication and key derivation.
Example:
client := bitwarden.NewDirectClient(
"https://vault.bitwarden.com",
"user@example.com",
"master-password",
bitwarden.WithTwoFactorProvider(my2FAHandler),
)
err := client.Unlock(context.Background(), "master-password")
client.Sync(context.Background())
func (dc *DirectClient) Attachments() AttachmentsAPI
Attachments returns the attachments service for file attachment operations.
func (dc *DirectClient) Collections() CollectionsAPI
Collections returns the collections service for accessing user collections.
func (dc *DirectClient) Folders() FoldersAPI
Folders returns the folders service for organizing vault items.
func (dc *DirectClient) Generate(ctx context.Context, opts GenerateOptions) (string, error)
Generate generates a password or passphrase locally using cryptographically secure random number generation. This does not require server communication. Use GenerateOptions to configure the password complexity or passphrase settings.
func (dc *DirectClient) GetAPIKey(ctx context.Context) (clientID, clientSecret string, err error)
GetAPIKey retrieves an API key for the current user. The client must be logged in (have a valid access token). The API key can be used for authenticating without 2FA in automated environments.
Returns:
- clientID: The API key identifier (typically "user.<uuid>")
- clientSecret: The API key secret
func (dc *DirectClient) Items() ItemsAPI
Items returns the vault items (ciphers) service for CRUD operations on vault items.
func (dc *DirectClient) Lock(ctx context.Context) error
Lock clears the encryption keys and cached vault data from memory. If real-time notifications are running, they are stopped. After locking, Unlock must be called before accessing vault data again.
func (dc *DirectClient) Login(ctx context.Context) error
Login authenticates with the Bitwarden server using the configured credentials. This must be called before other operations (or use Unlock which calls Login internally).
If an API key was configured via WithAPIKey, it uses client_credentials grant which bypasses 2FA requirements. Otherwise, it uses the standard password grant which may trigger the 2FA callback if two-factor is enabled on the account.
After successful login, the encryption keys are available but the vault data still needs to be synced using Sync().
func (dc *DirectClient) OrgCollections() OrgCollectionsAPI
OrgCollections returns the organization collections service for managing org collections.
func (dc *DirectClient) OrgMembers() OrgMembersAPI
OrgMembers returns the organization members service for member management.
func (dc *DirectClient) Organizations() OrganizationsAPI
Organizations returns the organizations service for listing user organizations.
func (dc *DirectClient) Register(ctx context.Context, name string, cfg crypto.DeriveKeyConfig) error
Register creates a new Bitwarden account on the server. This is typically only used for testing or automated account provisioning. The cfg parameter specifies the key derivation function configuration (PBKDF2 or Argon2id).
func (dc *DirectClient) Send() SendAPI
Send returns the Bitwarden Send service for creating secure shares.
func (dc *DirectClient) ServerURL() string
ServerURL returns the configured Bitwarden/Vaultwarden server URL.
func (dc *DirectClient) SetNotificationsLogger(l *log.Logger)
SetNotificationsLogger sets a logger for notification debug output.
func (dc *DirectClient) StartNotifications(ctx context.Context) error
StartNotifications connects to the server's WebSocket notification hub. Notifications trigger automatic cache invalidation. If a NotificationHandler was configured via WithNotificationHandler, it is also called. The provided context controls the connection lifetime.
func (dc *DirectClient) Status(ctx context.Context) (*Status, error)
Status returns the current client status including lock state, user information, and server URL. This does not require the vault to be unlocked.
func (dc *DirectClient) StopNotifications() error
StopNotifications disconnects from the notification hub.
func (dc *DirectClient) Sync(ctx context.Context) error
Sync downloads the vault data from the server and decrypts it locally. The vault must be unlocked before calling Sync. After sync, the decrypted data is available through the various service APIs (Items, Folders, etc.).
Sync also loads organization keys and populates the local cache for faster access.
func (dc *DirectClient) Unlock(ctx context.Context, password string) error
Unlock re-authenticates with the server and re-derives the encryption keys from the master password. This combines Login and key derivation into one step.
If 2FA is enabled, the configured TwoFactorProvider callback will be invoked. After unlock, call Sync to download and decrypt the vault data.
type DirectClientOption func(*DirectClient)
DirectClientOption configures the DirectClient using the functional options pattern.
func WithAPIKey(clientID, clientSecret string) DirectClientOption
WithAPIKey configures API key authentication using the client_credentials grant. API keys can be generated in the Bitwarden web vault and bypass 2FA requirements, but the master password is still required for vault decryption. The clientID is typically in the format "user.<user_uuid>".
Example:
client := bitwarden.NewDirectClient(
serverURL, email, masterPassword,
bitwarden.WithAPIKey("user.abc-123", "secret-key"),
)
func WithDeviceInfo(name, identifier string, deviceType int) DirectClientOption
WithDeviceInfo sets device information for token requests. This information appears in the Bitwarden account's device list. If not provided, default device info will be used.
WithDirectHTTPClient sets a custom http.Client for direct server communication. Use this to configure timeouts, proxies, or custom transport.
func WithIdentityURL(url string) DirectClientOption
WithIdentityURL sets a separate identity URL for authentication. This is typically used for Bitwarden cloud where identity and API URLs differ. For self-hosted Vaultwarden, this is usually not needed.
WithNotificationHandler sets a callback invoked on each notification. If not set, notifications only trigger cache invalidation.
WithTwoFactorProvider sets a callback function for handling two-factor authentication. The callback receives the available 2FA providers and should return the selected provider type and code. This is called during Login/Unlock if 2FA is enabled.
type DirectCollectionsService struct { // contains filtered or unexported fields }
DirectCollectionsService handles collection operations via the direct server API.
func (s *DirectCollectionsService) Get(ctx context.Context, id string) (*Collection, error)
func (s *DirectCollectionsService) List(ctx context.Context, organizationID, search string) ([]Collection, error)
type DirectFoldersService struct { // contains filtered or unexported fields }
DirectFoldersService handles folder operations via the direct server API.
func (s *DirectFoldersService) Create(ctx context.Context, folder Folder) (*Folder, error)
func (s *DirectFoldersService) Delete(ctx context.Context, id string) error
func (s *DirectFoldersService) Get(ctx context.Context, id string) (*Folder, error)
func (s *DirectFoldersService) List(ctx context.Context, search string) ([]Folder, error)
func (s *DirectFoldersService) Update(ctx context.Context, id string, folder Folder) (*Folder, error)
type DirectItemsService struct { // contains filtered or unexported fields }
DirectItemsService handles vault item operations via the direct server API.
func (s *DirectItemsService) Create(ctx context.Context, item Item) (*Item, error)
func (s *DirectItemsService) Delete(ctx context.Context, id string) error
func (s *DirectItemsService) Get(ctx context.Context, id string) (*Item, error)
func (s *DirectItemsService) List(ctx context.Context, filter ListFilter) ([]Item, error)
func (s *DirectItemsService) Move(ctx context.Context, id, organizationID string, collectionIDs []string) error
func (s *DirectItemsService) Restore(ctx context.Context, id string) error
func (s *DirectItemsService) Update(ctx context.Context, id string, item Item) (*Item, error)
type DirectOrgCollectionsService struct { // contains filtered or unexported fields }
DirectOrgCollectionsService handles organization collection operations.
func (s *DirectOrgCollectionsService) Create(ctx context.Context, collection OrgCollection) (*OrgCollection, error)
func (s *DirectOrgCollectionsService) Delete(ctx context.Context, id string) error
func (s *DirectOrgCollectionsService) Get(ctx context.Context, id string) (*OrgCollection, error)
func (s *DirectOrgCollectionsService) List(ctx context.Context, organizationID string, search string) ([]OrgCollection, error)
func (s *DirectOrgCollectionsService) Update(ctx context.Context, id string, collection OrgCollection) (*OrgCollection, error)
type DirectOrgMembersService struct { // contains filtered or unexported fields }
DirectOrgMembersService handles organization member operations.
func (s *DirectOrgMembersService) Confirm(ctx context.Context, id, organizationID string) error
func (s *DirectOrgMembersService) List(ctx context.Context, organizationID string) ([]OrgMember, error)
type DirectOrganizationsService struct { // contains filtered or unexported fields }
DirectOrganizationsService handles organization operations via the direct server API.
func (s *DirectOrganizationsService) Get(ctx context.Context, id string) (*Organization, error)
func (s *DirectOrganizationsService) List(ctx context.Context, search string) ([]Organization, error)
type DirectSendService struct { // contains filtered or unexported fields }
DirectSendService handles Send operations via the direct server API.
func (s *DirectSendService) Create(ctx context.Context, send Send) (*Send, error)
func (s *DirectSendService) Delete(ctx context.Context, id string) error
func (s *DirectSendService) Get(ctx context.Context, id string) (*Send, error)
func (s *DirectSendService) List(ctx context.Context) ([]Send, error)
func (s *DirectSendService) RemovePassword(ctx context.Context, id string) (*Send, error)
func (s *DirectSendService) Update(ctx context.Context, id string, send Send) (*Send, error)
type Field struct { Name string `json:"name"` Value string `json:"value"` Type FieldType `json:"type"` LinkedID *int `json:"linkedId,omitempty"` }
Field represents a custom field on a vault item.
type FieldType int
FieldType represents the type of a custom field.
const ( FieldTypeText FieldType = 0 FieldTypeHidden FieldType = 1 FieldTypeBoolean FieldType = 2 FieldTypeLinked FieldType = 3 )
type Folder struct { Object string `json:"object,omitempty"` ID string `json:"id,omitempty"` Name string `json:"name"` }
Folder represents a vault folder.
type FoldersAPI interface { // List retrieves folders with optional search filter. List(ctx context.Context, search string) ([]Folder, error) // Get retrieves a single folder by its ID. Get(ctx context.Context, id string) (*Folder, error) // Create adds a new folder to the vault. Create(ctx context.Context, folder Folder) (*Folder, error) // Update modifies an existing folder. Update(ctx context.Context, id string, folder Folder) (*Folder, error) // Delete removes a folder from the vault. Delete(ctx context.Context, id string) error }
FoldersAPI defines operations on folders for organizing vault items.
type FoldersService struct { // contains filtered or unexported fields }
FoldersService handles folder operations.
func (s *FoldersService) Create(ctx context.Context, folder Folder) (*Folder, error)
Create creates a new folder.
func (s *FoldersService) Delete(ctx context.Context, id string) error
Delete deletes a folder.
func (s *FoldersService) Get(ctx context.Context, id string) (*Folder, error)
Get returns a single folder by ID.
func (s *FoldersService) List(ctx context.Context, search string) ([]Folder, error)
List returns all folders, optionally filtered by search.
func (s *FoldersService) Update(ctx context.Context, id string, folder Folder) (*Folder, error)
Update updates an existing folder.
type GenerateOptions struct { Lowercase *bool `json:"lowercase,omitempty"` Uppercase *bool `json:"uppercase,omitempty"` Number *bool `json:"number,omitempty"` Special *bool `json:"special,omitempty"` Length *int `json:"length,omitempty"` Passphrase *bool `json:"passphrase,omitempty"` Words *int `json:"words,omitempty"` Separator *string `json:"separator,omitempty"` Capitalize *bool `json:"capitalize,omitempty"` IncludeNumber *bool `json:"includeNumber,omitempty"` }
GenerateOptions holds password/passphrase generation options.
type GenerateResponse struct { Success bool `json:"success"` Data struct { Object string `json:"object"` Data string `json:"data"` } `json:"data"` }
GenerateResponse wraps the /generate endpoint response.
type Identity struct { Title string `json:"title,omitempty"` FirstName string `json:"firstName,omitempty"` MiddleName string `json:"middleName,omitempty"` LastName string `json:"lastName,omitempty"` Address1 string `json:"address1,omitempty"` Address2 string `json:"address2,omitempty"` Address3 string `json:"address3,omitempty"` City string `json:"city,omitempty"` State string `json:"state,omitempty"` PostalCode string `json:"postalCode,omitempty"` Country string `json:"country,omitempty"` Company string `json:"company,omitempty"` Email string `json:"email,omitempty"` Phone string `json:"phone,omitempty"` SSN string `json:"ssn,omitempty"` Username string `json:"username,omitempty"` PassportNumber string `json:"passportNumber,omitempty"` LicenseNumber string `json:"licenseNumber,omitempty"` }
Identity represents identity-specific fields of a vault item.
type Item struct { Object string `json:"object,omitempty"` ID string `json:"id,omitempty"` OrganizationID string `json:"organizationId,omitempty"` FolderID *string `json:"folderId,omitempty"` Type ItemType `json:"type"` Reprompt int `json:"reprompt"` Name string `json:"name"` Notes string `json:"notes,omitempty"` Favorite bool `json:"favorite"` Login *Login `json:"login,omitempty"` Card *Card `json:"card,omitempty"` Identity *Identity `json:"identity,omitempty"` SecureNote *SecureNote `json:"secureNote,omitempty"` Fields []Field `json:"fields,omitempty"` PasswordHistory []PasswordHistory `json:"passwordHistory,omitempty"` Attachments []Attachment `json:"attachments,omitempty"` CollectionIDs []string `json:"collectionIds,omitempty"` RevisionDate string `json:"revisionDate,omitempty"` CreationDate string `json:"creationDate,omitempty"` DeletedDate *string `json:"deletedDate,omitempty"` }
Item represents a vault item (cipher).
type ItemType int
ItemType represents the type of a vault item.
const ( ItemTypeLogin ItemType = 1 ItemTypeSecureNote ItemType = 2 ItemTypeCard ItemType = 3 ItemTypeIdentity ItemType = 4 ItemTypeSSHKey ItemType = 5 )
type ItemsAPI interface { // List retrieves items from the vault with optional filtering. List(ctx context.Context, filter ListFilter) ([]Item, error) // Get retrieves a single item by its ID. Get(ctx context.Context, id string) (*Item, error) // Create adds a new item to the vault. Create(ctx context.Context, item Item) (*Item, error) // Update modifies an existing item. Update(ctx context.Context, id string, item Item) (*Item, error) // Delete removes an item (moves to trash). Delete(ctx context.Context, id string) error // Restore recovers a deleted item from the trash. Restore(ctx context.Context, id string) error // Move transfers an item to an organization with specified collections. Move(ctx context.Context, id, organizationID string, collectionIDs []string) error }
ItemsAPI defines operations on vault items (ciphers). Items are the primary data type in a vault and can be logins, secure notes, cards, identities, or SSH keys.
type ItemsService struct { // contains filtered or unexported fields }
ItemsService handles vault item operations.
func (s *ItemsService) Create(ctx context.Context, item Item) (*Item, error)
Create creates a new vault item.
func (s *ItemsService) Delete(ctx context.Context, id string) error
Delete deletes a vault item (soft delete).
func (s *ItemsService) Get(ctx context.Context, id string) (*Item, error)
Get returns a single vault item by ID.
func (s *ItemsService) List(ctx context.Context, filter ListFilter) ([]Item, error)
List returns vault items matching the given filters.
func (s *ItemsService) Move(ctx context.Context, id, organizationID string, collectionIDs []string) error
Move moves a vault item to an organization with the given collection IDs.
func (s *ItemsService) Restore(ctx context.Context, id string) error
Restore restores a soft-deleted vault item.
func (s *ItemsService) Update(ctx context.Context, id string, item Item) (*Item, error)
Update updates an existing vault item.
type ListFilter struct { Search string OrganizationID string CollectionID string FolderID string URL string Trash bool }
ListFilter holds common filter parameters for list operations.
type ListResponse[T any] struct { Success bool `json:"success"` Data struct { Object string `json:"object"` Data []T `json:"data"` } `json:"data"` }
ListResponse is a generic list response wrapper.
type Login struct { URIs []LoginURI `json:"uris,omitempty"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` TOTP string `json:"totp,omitempty"` }
Login represents login-specific fields of a vault item.
type LoginURI struct { Match *URIMatchType `json:"match,omitempty"` URI string `json:"uri"` }
LoginURI represents a URI attached to a login item.
type MessageResponse struct { Success bool `json:"success"` Data struct { Title string `json:"title"` Message string `json:"message"` Raw string `json:"raw"` } `json:"data"` }
MessageResponse is a generic message response from the API.
type MoveRequest struct { CollectionIDs []string `json:"collectionIds"` }
MoveRequest is the body for POST /move/:id/:organizationId.
type NotFoundError struct { Object string ID string }
NotFoundError is returned when the requested object is not found.
func (e *NotFoundError) Error() string
type NotificationHandler func(notifType NotificationType, payload NotificationPayload)
NotificationHandler is called when a server notification is received. It runs in a background goroutine — implementations must be safe for concurrent use.
type NotificationPayload struct { ID string UserID string OrganizationID string CollectionIDs []string RevisionDate string }
NotificationPayload contains details of a server notification.
NotificationType represents the type of server notification.
type ObjectResponse[T any] struct { Success bool `json:"success"` Data T `json:"data"` }
ObjectResponse is a generic single-object response wrapper.
type OrgCollection struct { Object string `json:"object,omitempty"` ID string `json:"id,omitempty"` OrganizationID string `json:"organizationId,omitempty"` Name string `json:"name"` ExternalID string `json:"externalId,omitempty"` Groups []string `json:"groups,omitempty"` }
OrgCollection represents an organization collection with additional details.
type OrgCollectionsAPI interface { // List retrieves collections in an organization with optional search. List(ctx context.Context, organizationID string, search string) ([]OrgCollection, error) // Get retrieves a single organization collection by its ID. Get(ctx context.Context, id string) (*OrgCollection, error) // Create adds a new collection to the organization. Create(ctx context.Context, collection OrgCollection) (*OrgCollection, error) // Update modifies an existing organization collection. Update(ctx context.Context, id string, collection OrgCollection) (*OrgCollection, error) // Delete removes a collection from the organization. Delete(ctx context.Context, id string) error }
OrgCollectionsAPI defines operations on organization collections. Users with appropriate permissions can create, update, and delete org collections.
type OrgCollectionsService struct { // contains filtered or unexported fields }
OrgCollectionsService handles organization collection operations.
func (s *OrgCollectionsService) Create(ctx context.Context, collection OrgCollection) (*OrgCollection, error)
Create creates a new organization collection.
func (s *OrgCollectionsService) Delete(ctx context.Context, id string) error
Delete deletes an organization collection.
func (s *OrgCollectionsService) Get(ctx context.Context, id string) (*OrgCollection, error)
Get returns a single organization collection by ID.
func (s *OrgCollectionsService) List(ctx context.Context, organizationID string, search string) ([]OrgCollection, error)
List returns all organization collections. organizationID is required.
func (s *OrgCollectionsService) Update(ctx context.Context, id string, collection OrgCollection) (*OrgCollection, error)
Update updates an existing organization collection.
type OrgMember struct { Object string `json:"object,omitempty"` ID string `json:"id,omitempty"` Name string `json:"name"` Email string `json:"email"` Status int `json:"status"` Type int `json:"type"` TwoStep bool `json:"twoFactorEnabled"` }
OrgMember represents an organization member.
type OrgMembersAPI interface { // List retrieves all members in an organization. List(ctx context.Context, organizationID string) ([]OrgMember, error) // Confirm accepts a pending member into the organization. Confirm(ctx context.Context, id, organizationID string) error }
OrgMembersAPI defines operations on organization members.
type OrgMembersService struct { // contains filtered or unexported fields }
OrgMembersService handles organization member operations.
func (s *OrgMembersService) Confirm(ctx context.Context, id, organizationID string) error
Confirm confirms an invited organization member.
func (s *OrgMembersService) List(ctx context.Context, organizationID string) ([]OrgMember, error)
List returns all members of an organization.
type Organization struct { Object string `json:"object,omitempty"` ID string `json:"id,omitempty"` Name string `json:"name"` Status int `json:"status"` Type int `json:"type"` Enabled bool `json:"enabled"` }
Organization represents an organization.
type OrganizationsAPI interface { // List retrieves organizations the user belongs to with optional search. List(ctx context.Context, search string) ([]Organization, error) // Get retrieves a single organization by its ID. Get(ctx context.Context, id string) (*Organization, error) }
OrganizationsAPI defines read-only operations on organizations.
type OrganizationsService struct { // contains filtered or unexported fields }
OrganizationsService handles organization operations (read-only).
func (s *OrganizationsService) Get(ctx context.Context, id string) (*Organization, error)
Get returns a single organization by ID.
func (s *OrganizationsService) List(ctx context.Context, search string) ([]Organization, error)
List returns all organizations, optionally filtered by search.
type PasswordHistory struct { LastUsedDate string `json:"lastUsedDate"` Password string `json:"password"` }
PasswordHistory represents a password history entry.
type SecureNote struct { Type int `json:"type"` }
SecureNote represents secure note-specific fields.
type Send struct { Object string `json:"object,omitempty"` ID string `json:"id,omitempty"` AccessID string `json:"accessId,omitempty"` Type SendType `json:"type"` Name string `json:"name"` Notes string `json:"notes,omitempty"` File *SendFile `json:"file,omitempty"` Text *SendText `json:"text,omitempty"` Key string `json:"key,omitempty"` MaxAccessCount *int `json:"maxAccessCount,omitempty"` AccessCount int `json:"accessCount,omitempty"` Password string `json:"password,omitempty"` Disabled bool `json:"disabled"` RevisionDate string `json:"revisionDate,omitempty"` DeletionDate string `json:"deletionDate"` ExpirationDate *string `json:"expirationDate,omitempty"` HideEmail bool `json:"hideEmail"` }
Send represents a Bitwarden Send object.
type SendAPI interface { // List retrieves all Sends owned by the user. List(ctx context.Context) ([]Send, error) // Get retrieves a single Send by its ID. Get(ctx context.Context, id string) (*Send, error) // Create adds a new Send to the vault. Create(ctx context.Context, send Send) (*Send, error) // Update modifies an existing Send. Update(ctx context.Context, id string, send Send) (*Send, error) // Delete removes a Send from the vault. Delete(ctx context.Context, id string) error // RemovePassword removes the password protection from a Send. RemovePassword(ctx context.Context, id string) (*Send, error) }
SendAPI defines operations on Bitwarden Send objects. Send allows secure sharing of data (text or files) with anyone, even non-Bitwarden users.
type SendFile struct { ID string `json:"id,omitempty"` FileName string `json:"fileName"` Size string `json:"size,omitempty"` SizeName string `json:"sizeName,omitempty"` }
SendFile represents file details in a Send.
type SendService struct { // contains filtered or unexported fields }
SendService handles Bitwarden Send operations.
func (s *SendService) Create(ctx context.Context, send Send) (*Send, error)
Create creates a new Send.
func (s *SendService) Delete(ctx context.Context, id string) error
Delete deletes a Send.
func (s *SendService) Get(ctx context.Context, id string) (*Send, error)
Get returns a single Send by ID.
func (s *SendService) List(ctx context.Context) ([]Send, error)
List returns all Send items.
func (s *SendService) RemovePassword(ctx context.Context, id string) (*Send, error)
RemovePassword removes password protection from a Send.
func (s *SendService) Update(ctx context.Context, id string, send Send) (*Send, error)
Update updates an existing Send.
type SendText struct { Text string `json:"text"` Hidden bool `json:"hidden"` }
SendText represents text details in a Send.
type SendType int
SendType represents the type of a Send.
const ( SendTypeText SendType = 0 SendTypeFile SendType = 1 )
type Status struct { ServerURL string `json:"serverUrl"` LastSync string `json:"lastSync"` UserEmail string `json:"userEmail"` UserID string `json:"userId"` Status string `json:"status"` }
Status represents the response from /status.
type StatusResponse struct { Success bool `json:"success"` Data json.RawMessage `json:"data"` }
StatusResponse wraps the status endpoint response.
type SyncResponse struct { Success bool `json:"success"` Data struct { Title string `json:"title"` Message string `json:"message"` } `json:"data"` }
SyncResponse wraps the sync endpoint response.
type TemplateType string
TemplateType represents the type of template to retrieve.
const ( TemplateItem TemplateType = "item" TemplateItemField TemplateType = "item.field" TemplateItemLogin TemplateType = "item.login" TemplateItemCard TemplateType = "item.card" TemplateItemIdentity TemplateType = "item.identity" TemplateItemSecureNote TemplateType = "item.securenote" TemplateFolder TemplateType = "folder" TemplateCollection TemplateType = "collection" TemplateSend TemplateType = "send" TemplateSendText TemplateType = "send.text" TemplateSendFile TemplateType = "send.file" )
type URIMatchType int
URIMatchType represents the URI match detection type.
const ( URIMatchBaseDomain URIMatchType = 0 URIMatchHost URIMatchType = 1 URIMatchStartsWith URIMatchType = 2 URIMatchRegex URIMatchType = 3 URIMatchExact URIMatchType = 4 URIMatchNever URIMatchType = 5 )
type UnlockRequest struct { Password string `json:"password"` }
UnlockRequest is the body for POST /unlock.
type VaultClient interface { // Status returns the current vault status including lock state and user info. Status(ctx context.Context) (*Status, error) // Sync downloads the latest vault data from the server. Sync(ctx context.Context) error // Lock clears encryption keys and vault data from memory. Lock(ctx context.Context) error // Unlock authenticates and derives encryption keys from the password. Unlock(ctx context.Context, password string) error // Generate creates a password or passphrase based on the provided options. Generate(ctx context.Context, opts GenerateOptions) (string, error) // Items returns the vault items (ciphers) API. Items() ItemsAPI // Folders returns the folders API. Folders() FoldersAPI // Collections returns the user collections API. Collections() CollectionsAPI // OrgCollections returns the organization collections API. OrgCollections() OrgCollectionsAPI // Organizations returns the organizations API. Organizations() OrganizationsAPI // OrgMembers returns the organization members API. OrgMembers() OrgMembersAPI // Send returns the Bitwarden Send API. Send() SendAPI // Attachments returns the file attachments API. Attachments() AttachmentsAPI }
VaultClient defines the unified interface for interacting with a Bitwarden vault. Both Client (CLI-based via bw serve) and DirectClient (direct server communication) implement this interface, allowing applications to work with either mode seamlessly.
The interface provides methods for vault lifecycle management (Status, Sync, Lock, Unlock), password generation, and access to various vault services through sub-APIs.
type VaultLockedError struct{}
VaultLockedError is returned when the vault is locked.
func (e *VaultLockedError) Error() string
Directories
| Path | Synopsis |
|---|---|
| crypto | |
| example | |
| internal/api |
Source Files
- attachments.go
- cipher_crypto.go
- client.go
- collections.go
- direct_attachments.go
- direct_client.go
- direct_collections.go
- direct_folders.go
- direct_items.go
- direct_notifications.go
- direct_organizations.go
- direct_send.go
- doc.go
- errors.go
- folders.go
- generate.go
- http.go
- interfaces.go
- items.go
- models.go
- org_collections.go
- org_members.go
- organizations.go
- send.go
- vault_cache.go
- wordlist.go
Package bitwarden provides a comprehensive Go client library for Bitwarden and Vaultwarden password managers. It supports both CLI-based communication (via bw serve) and direct server communication with end-to-end encryption.
The library provides two client modes:
Both clients implement the VaultClient interface, providing a unified API for vault operations including items, folders, collections, organizations, Send, and attachments.
Basic usage with Client:
Basic usage with DirectClient:
client := bitwarden.NewDirectClient( "https://vault.bitwarden.com", "user@example.com", "master-password", ) err := client.Unlock(context.Background(), "master-password") client.Sync(context.Background()) items, _ := client.Items().List(context.Background(), nil)