sdk

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Not /healthz: Cloud Run answers that path itself and never forwards it to us.
	RouteHealth = "/health"

	// Authentication endpoints
	RouteV1Login          = "/v1/login"
	RouteV1Refresh        = "/v1/refresh"
	RouteV1Register       = "/v1/register"
	RouteV1VerifyEmail    = "/v1/verify-email"
	RouteV1ForgotPassword = "/v1/forgot-password"
	RouteV1ResetPassword  = "/v1/reset-password"

	// OAuth/SSO endpoints
	RouteV1OAuthLogin    = "/v1/oauth/login"    // Individual OAuth (Google, GitHub, etc.)
	RouteV1SSOLogin      = "/v1/sso/login"      // Corporate SSO (domain-based routing)
	RouteV1OAuthCallback = "/v1/oauth/callback" // OAuth callback handler

	// OAuth provider configuration (authenticated)
	RouteV1OAuthProviders      = "/v1/oauth/providers"
	RouteV1OAuthProvider       = "/v1/oauth/providers/{providerID}"
	RouteV1OAuthSupportedTypes = "/v1/oauth/supported-types" // Public endpoint

	// RBAC endpoints (authenticated)
	RouteV1Permissions = "/v1/permissions" // List all system permissions

	// Role management
	RouteV1Roles = "/v1/roles"
	RouteV1Role  = "/v1/roles/{roleID}"

	// Role permissions
	RouteV1RolePermissions = "/v1/roles/{roleID}/permissions"
	RouteV1RolePermission  = "/v1/roles/{roleID}/permissions/{permissionID}"

	// User endpoints
	RouteV1Me = "/v1/users/me"

	// User roles
	RouteV1UserRoles = "/v1/users/{userID}/roles"
	RouteV1UserRole  = "/v1/users/{userID}/roles/{roleID}"

	// User direct permissions
	RouteV1UserPermissions = "/v1/users/{userID}/permissions"
	RouteV1UserPermission  = "/v1/users/{userID}/permissions/{permissionID}"

	// MFA endpoints
	RouteV1MFASetup           = "/v1/mfa/setup"                   // Start MFA setup (authenticated)
	RouteV1MFAEnable          = "/v1/mfa/enable"                  // Verify and enable MFA (authenticated)
	RouteV1MFAVerify          = "/v1/mfa/verify"                  // Verify MFA code during login
	RouteV1MFADisable         = "/v1/mfa/disable"                 // Disable MFA (authenticated)
	RouteV1MFAStatus          = "/v1/mfa/status"                  // Get MFA status (authenticated)
	RouteV1MFARegenerateCodes = "/v1/mfa/backup-codes/regenerate" // Regenerate backup codes (authenticated)

	// Required MFA setup endpoints (unauthenticated, uses setup token)
	RouteV1MFARequiredSetup  = "/v1/mfa/required-setup"  // Start MFA setup when role requires it
	RouteV1MFARequiredEnable = "/v1/mfa/required-enable" // Enable MFA and complete login

	// Session management endpoints (authenticated)
	RouteV1Sessions    = "/v1/sessions"             // List active sessions, revoke all
	RouteV1SessionByID = "/v1/sessions/{sessionID}" // Revoke specific session
)

API route constants shared between server and SDK clients

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
}

APIError is returned when the server responds with an HTTP error status code

func (*APIError) Error

func (e *APIError) Error() string

type BackupCodesResponse

type BackupCodesResponse struct {
	BackupCodes []string `json:"backup_codes"`
}

BackupCodesResponse contains new backup codes

type CreateOIDCProviderRequest

type CreateOIDCProviderRequest struct {
	ProviderName             string   `json:"provider_name"`
	IssuerURL                string   `json:"issuer_url"`
	ClientID                 string   `json:"client_id,omitempty"`     // Optional: for manual registration
	ClientSecret             string   `json:"client_secret,omitempty"` // Optional: for manual registration
	AccessToken              string   `json:"access_token,omitempty"`  // Optional: for authenticated dynamic registration
	Scopes                   []string `json:"scopes,omitempty"`
	Enabled                  bool     `json:"enabled"`
	AllowedDomains           []string `json:"allowed_domains"`
	AutoCreateUsers          bool     `json:"auto_create_users"`
	RequireEmailVerification bool     `json:"require_email_verification"`
}

CreateOIDCProviderRequest represents the request to create an OIDC provider

func (*CreateOIDCProviderRequest) Validate

Validate validates the create OIDC provider request

type CreateRoleRequest

type CreateRoleRequest struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	MFARequired bool   `json:"mfa_required"`
}

CreateRoleRequest represents the request to create a new role

func (*CreateRoleRequest) Validate

func (r *CreateRoleRequest) Validate(ctx context.Context) error

Validate validates the create role request

type CreateUserRequest

type CreateUserRequest struct {
	Email   string      `json:"email"`
	RoleIDs []uuid.UUID `json:"role_ids,omitempty"` // Optional list of role IDs to assign
}

CreateUserRequest represents the request to create a user Note: tenant_id is extracted from context and sent via gRPC metadata

func (*CreateUserRequest) Validate

func (r *CreateUserRequest) Validate(ctx context.Context) error

Validate validates the create user request

type CreateUserResponse

type CreateUserResponse struct {
	UserID            uuid.UUID `json:"user_id"`
	Email             string    `json:"email"`
	TenantID          uuid.UUID `json:"tenant_id"`
	VerificationToken string    `json:"verification_token"` // Empty for SSO users, set for non-SSO users
}

CreateUserResponse represents the response from creating a user

type DeleteOIDCProviderRequest

type DeleteOIDCProviderRequest struct {
	ProviderID uuid.UUID `json:"-"` // From URL parameter
}

DeleteOIDCProviderRequest represents the request to delete an OIDC provider

func (*DeleteOIDCProviderRequest) Validate

Validate validates the delete OIDC provider request

type DeleteRoleRequest

type DeleteRoleRequest struct {
	RoleID uuid.UUID `json:"-"`
}

DeleteRoleRequest represents the request to delete a role

func (*DeleteRoleRequest) Validate

func (r *DeleteRoleRequest) Validate(ctx context.Context) error

Validate validates the delete role request

type DirectPermission

type DirectPermission struct {
	PermissionID uuid.UUID        `json:"permission_id"`
	Effect       PermissionEffect `json:"effect"`
}

DirectPermission represents a direct permission to set for a user

type DirectPermissionsResponse

type DirectPermissionsResponse struct {
	Permissions []EffectivePermission `json:"permissions"`
}

DirectPermissionsResponse represents the response with direct permissions for a user

type DisableMFARequest

type DisableMFARequest struct {
	Password string `json:"password"`
	Code     string `json:"code"` // TOTP code or backup code
}

DisableMFARequest disables MFA

func (*DisableMFARequest) Validate

func (r *DisableMFARequest) Validate(ctx context.Context) error

Validate validates the disable MFA request

type EffectivePermission

type EffectivePermission struct {
	Permission Permission       `json:"permission"`
	Effect     PermissionEffect `json:"effect"`
}

EffectivePermission represents a direct permission assigned to a user

type EnableMFARequest

type EnableMFARequest struct {
	Code string `json:"code"`
}

EnableMFARequest verifies TOTP code during setup

func (*EnableMFARequest) Validate

func (r *EnableMFARequest) Validate(ctx context.Context) error

Validate validates the enable MFA request

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse represents an error response

type ForgotPasswordRequest

type ForgotPasswordRequest struct {
	Email string `json:"email"`
}

ForgotPasswordRequest represents the forgot password request body

func (*ForgotPasswordRequest) Validate

func (r *ForgotPasswordRequest) Validate(ctx context.Context) error

Validate validates the forgot password request

type ForgotPasswordResponse

type ForgotPasswordResponse struct {
	Message string `json:"message"`
}

ForgotPasswordResponse represents the forgot password response

type GRPCClient

type GRPCClient struct {
	// contains filtered or unexported fields
}

GRPCClient is a gRPC client for the heimdall API

func NewGRPCClient

func NewGRPCClient(address string, opts ...GRPCClientOption) (*GRPCClient, error)

NewGRPCClient creates a new gRPC client for the heimdall API address should be in the format "host:port" (e.g., "localhost:9090")

func (*GRPCClient) Close

func (c *GRPCClient) Close() error

Close closes the gRPC connection

func (*GRPCClient) CreateUser

CreateUser creates a new user for a tenant Note: tenant_id is extracted from context and sent via gRPC metadata by the client interceptor

type GRPCClientOption

type GRPCClientOption func(*grpcClientConfig)

GRPCClientOption is a functional option for configuring the gRPC client

func WithDialOptions

func WithDialOptions(opts ...grpc.DialOption) GRPCClientOption

WithDialOptions allows setting custom gRPC dial options

func WithTimeout

func WithTimeout(timeout time.Duration) GRPCClientOption

WithTimeout sets the default timeout for gRPC calls

type GetDirectPermissionsRequest

type GetDirectPermissionsRequest struct {
	UserID uuid.UUID `json:"-"`
}

GetDirectPermissionsRequest represents the request to get direct permissions for a user

func (*GetDirectPermissionsRequest) Validate

Validate validates the get user permissions request

type GetOIDCProviderRequest

type GetOIDCProviderRequest struct {
	ProviderID uuid.UUID `json:"-"` // From URL parameter
}

GetOIDCProviderRequest represents the request to get an OIDC provider by ID

func (*GetOIDCProviderRequest) Validate

func (r *GetOIDCProviderRequest) Validate(ctx context.Context) error

Validate validates the get OIDC provider request

type GetRolePermissionsRequest

type GetRolePermissionsRequest struct {
	RoleID uuid.UUID `json:"-"`
}

GetRolePermissionsRequest represents the request to get permissions for a role

func (*GetRolePermissionsRequest) Validate

Validate validates the get role permissions request

type GetRoleRequest

type GetRoleRequest struct {
	RoleID uuid.UUID `json:"-"`
}

GetRoleRequest represents the request to get a role

func (*GetRoleRequest) Validate

func (r *GetRoleRequest) Validate(ctx context.Context) error

Validate validates the get role request

type GetUserRolesRequest

type GetUserRolesRequest struct {
	UserID uuid.UUID `json:"-"`
}

GetUserRolesRequest represents the request to get roles for a user

func (*GetUserRolesRequest) Validate

func (r *GetUserRolesRequest) Validate(ctx context.Context) error

Validate validates the get user roles request

type HTTPClient

type HTTPClient struct {
	*http.Client // Embedded for direct access to http.Client methods
	// contains filtered or unexported fields
}

HTTPClient is an HTTP client for the heimdall API

func NewHTTPClient

func NewHTTPClient(baseURL string, opts ...Option) (*HTTPClient, error)

NewHTTPClient creates a new heimdall API client The client automatically handles cookies for refresh token management

func (*HTTPClient) CreateOIDCProvider

func (c *HTTPClient) CreateOIDCProvider(ctx context.Context, req CreateOIDCProviderRequest) (*OIDCProvider, error)

CreateOIDCProvider creates a new OIDC provider configuration for corporate SSO

func (*HTTPClient) CreateRole

func (c *HTTPClient) CreateRole(ctx context.Context, req CreateRoleRequest) (*Role, error)

CreateRole creates a new role

func (*HTTPClient) DeleteOIDCProvider

func (c *HTTPClient) DeleteOIDCProvider(ctx context.Context, req DeleteOIDCProviderRequest) error

DeleteOIDCProvider deletes an OIDC provider

func (*HTTPClient) DeleteRole

func (c *HTTPClient) DeleteRole(ctx context.Context, req DeleteRoleRequest) error

DeleteRole deletes a role

func (*HTTPClient) DisableMFA

func (c *HTTPClient) DisableMFA(ctx context.Context, req DisableMFARequest) error

DisableMFA disables MFA for the authenticated user

func (*HTTPClient) EnableMFA

func (c *HTTPClient) EnableMFA(ctx context.Context, req EnableMFARequest) error

EnableMFA validates TOTP code and enables MFA

func (*HTTPClient) ForgotPassword

ForgotPassword initiates the password reset process

func (*HTTPClient) GetDirectPermissions

GetDirectPermissions retrieves direct permissions assigned to a user

func (*HTTPClient) GetMFAStatus

func (c *HTTPClient) GetMFAStatus(ctx context.Context) (*MFAStatus, error)

GetMFAStatus retrieves MFA status for the authenticated user

func (*HTTPClient) GetMe

func (c *HTTPClient) GetMe(ctx context.Context) (*User, error)

GetMe retrieves the current authenticated user's profile

func (*HTTPClient) GetOIDCProvider

func (c *HTTPClient) GetOIDCProvider(ctx context.Context, req GetOIDCProviderRequest) (*OIDCProvider, error)

GetOIDCProvider retrieves an OIDC provider by ID

func (*HTTPClient) GetRole

func (c *HTTPClient) GetRole(ctx context.Context, req GetRoleRequest) (*Role, error)

GetRole retrieves a role by ID

func (*HTTPClient) GetRolePermissions

func (c *HTTPClient) GetRolePermissions(ctx context.Context, req GetRolePermissionsRequest) (*PermissionsResponse, error)

GetRolePermissions retrieves all permissions for a role

func (*HTTPClient) GetUserRoles

func (c *HTTPClient) GetUserRoles(ctx context.Context, req GetUserRolesRequest) (*RolesResponse, error)

GetUserRoles retrieves all roles for a user

func (*HTTPClient) Health

func (c *HTTPClient) Health(ctx context.Context) error

Health checks the health of the heimdall API. Returns nil if healthy, error if unhealthy or unreachable.

func (*HTTPClient) ListOIDCProviders

func (c *HTTPClient) ListOIDCProviders(ctx context.Context) (*OIDCProvidersResponse, error)

ListOIDCProviders lists all OIDC providers for the tenant

func (*HTTPClient) ListPermissions

func (c *HTTPClient) ListPermissions(ctx context.Context) (*PermissionsResponse, error)

ListPermissions retrieves all system permissions

func (*HTTPClient) ListRoles

func (c *HTTPClient) ListRoles(ctx context.Context) (*RolesResponse, error)

ListRoles retrieves all roles for the tenant

func (*HTTPClient) ListSessions

func (c *HTTPClient) ListSessions(ctx context.Context) (*SessionsResponse, error)

ListSessions retrieves all active sessions for the authenticated user

func (*HTTPClient) ListSupportedProviders

func (c *HTTPClient) ListSupportedProviders(ctx context.Context) (*OIDCProviderTypesResponse, error)

ListSupportedProviders returns the list of OAuth providers available for individual login

func (*HTTPClient) Login

func (c *HTTPClient) Login(ctx context.Context, req LoginRequest) (*LoginResponse, error)

Login authenticates a user and returns an access token The access token is automatically set on the client for subsequent authenticated requests The refresh token is automatically stored in the client's cookie jar If MFA is required, returns MFAChallengeToken or MFASetupToken instead of AccessToken

func (*HTTPClient) Logout

func (c *HTTPClient) Logout(ctx context.Context) (*LogoutResponse, error)

Logout logs out the current user by revoking the refresh token

func (*HTTPClient) OAuthLogin

func (c *HTTPClient) OAuthLogin(ctx context.Context, req OIDCLoginRequest) (*OIDCAuthResponse, error)

OAuthLogin initiates an OAuth login flow Returns the authorization URL that the user should be redirected to

func (*HTTPClient) RefreshToken

func (c *HTTPClient) RefreshToken(ctx context.Context) (*LoginResponse, error)

RefreshToken refreshes the access token using the refresh token cookie The access token is automatically set on the client for subsequent authenticated requests The refresh token cookie must have been set by a previous Login call

func (*HTTPClient) RegenerateBackupCodes

func (c *HTTPClient) RegenerateBackupCodes(ctx context.Context, req RegenerateBackupCodesRequest) (*BackupCodesResponse, error)

RegenerateBackupCodes generates new backup codes (requires password)

func (*HTTPClient) Register

func (c *HTTPClient) Register(ctx context.Context, req RegisterRequest) (*RegisterResponse, error)

Register registers a new user account

func (*HTTPClient) RequiredMFAEnable

func (c *HTTPClient) RequiredMFAEnable(ctx context.Context, req RequiredMFAEnableRequest) (*LoginResponse, error)

RequiredMFAEnable enables MFA after required setup and issues an MFA challenge token After this succeeds, call VerifyMFACode to complete the login flow

func (*HTTPClient) RequiredMFASetup

func (c *HTTPClient) RequiredMFASetup(ctx context.Context, req RequiredMFASetupRequest) (*MFASetupResponse, error)

RequiredMFASetup initiates MFA setup when a user's role requires MFA but they haven't set it up Returns the TOTP secret, QR code, and backup codes

func (*HTTPClient) ResetPassword

ResetPassword resets a user's password using the reset token

func (*HTTPClient) RevokeAllSessions

func (c *HTTPClient) RevokeAllSessions(ctx context.Context) error

RevokeAllSessions revokes all sessions for the authenticated user (sign out everywhere)

func (*HTTPClient) RevokeSession

func (c *HTTPClient) RevokeSession(ctx context.Context, req RevokeSessionRequest) error

RevokeSession revokes a specific session by ID

func (*HTTPClient) SSOLogin

func (c *HTTPClient) SSOLogin(ctx context.Context, req SSOLoginRequest) (*OIDCAuthResponse, error)

SSOLogin initiates a corporate SSO login flow Returns the authorization URL that the user should be redirected to

func (*HTTPClient) SetDirectPermissions

func (c *HTTPClient) SetDirectPermissions(ctx context.Context, req SetDirectPermissionsRequest) error

SetDirectPermissions sets all permissions for a user

func (*HTTPClient) SetRolePermissions

func (c *HTTPClient) SetRolePermissions(ctx context.Context, req SetRolePermissionsRequest) error

SetRolePermissions sets all permissions for a role (bulk update)

func (*HTTPClient) SetUserRoles

func (c *HTTPClient) SetUserRoles(ctx context.Context, req SetUserRolesRequest) error

SetUserRoles sets all roles for a user

func (*HTTPClient) SetupMFA

func (c *HTTPClient) SetupMFA(ctx context.Context) (*MFASetupResponse, error)

SetupMFA initiates MFA setup by generating TOTP secret, QR code, and backup codes

func (*HTTPClient) UpdateOIDCProvider

func (c *HTTPClient) UpdateOIDCProvider(ctx context.Context, req UpdateOIDCProviderRequest) (*OIDCProvider, error)

UpdateOIDCProvider updates an OIDC provider configuration

func (*HTTPClient) UpdateRole

func (c *HTTPClient) UpdateRole(ctx context.Context, req UpdateRoleRequest) (*Role, error)

UpdateRole updates a role

func (*HTTPClient) VerifyEmail

func (c *HTTPClient) VerifyEmail(ctx context.Context, req VerifyEmailRequest) (*LoginResponse, error)

VerifyEmail verifies a user's email address using the verification token The access token is automatically set on the client for subsequent authenticated requests Returns a LoginResponse with access token on successful verification May return MFAChallengeToken or MFASetupToken if user's role requires MFA

func (*HTTPClient) VerifyMFACode

func (c *HTTPClient) VerifyMFACode(ctx context.Context, req VerifyMFACodeRequest) (*LoginResponse, error)

VerifyMFACode verifies MFA code during login and completes authentication The access token is automatically set on the client for subsequent authenticated requests

type HealthResponse added in v0.4.0

type HealthResponse struct {
	Status string `json:"status"`
}

HealthResponse represents the health check response

type LoginRequest

type LoginRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

LoginRequest represents the login request body

func (*LoginRequest) Validate

func (r *LoginRequest) Validate(ctx context.Context) error

Validate validates the login request

type LoginResponse

type LoginResponse struct {
	AccessToken       string `json:"access_token,omitempty"`        // Set when login is complete
	MFAChallengeToken string `json:"mfa_challenge_token,omitempty"` // Set when MFA verification is required
	MFASetupToken     string `json:"mfa_setup_token,omitempty"`     // Set when role requires MFA but user hasn't set it up
	TokenType         string `json:"token_type,omitempty"`          // "Bearer" for access tokens, omitted for challenge/setup tokens
	ExpiresIn         int    `json:"expires_in"`                    // Seconds until access token expires (OAuth 2.0 standard)
	RefreshExpiresIn  int    `json:"refresh_expires_in,omitempty"`  // Seconds until refresh token expires (extension to standard)
}

LoginResponse represents the login response Note: refresh_token is sent via HTTP-only cookie, not in JSON body

type LogoutResponse

type LogoutResponse struct {
	Message string `json:"message"`
}

LogoutResponse represents the logout response

type MFASetupResponse

type MFASetupResponse struct {
	Secret      string   `json:"secret"`
	QRCode      string   `json:"qr_code"`
	BackupCodes []string `json:"backup_codes"`
}

MFASetupResponse contains secret, QR code, and backup codes for MFA setup

type MFAStatus

type MFAStatus struct {
	VerifiedAt           *time.Time `json:"verified_at,omitempty"`
	BackupCodesRemaining int        `json:"backup_codes_remaining"`
}

MFAStatus represents current MFA state

type OIDCAuthResponse

type OIDCAuthResponse struct {
	AuthorizationURL string `json:"authorization_url"`
}

OIDCAuthResponse represents the OIDC authentication response with authorization URL

type OIDCLoginRequest

type OIDCLoginRequest struct {
	ProviderType OIDCProviderType `json:"provider_type"`
}

OIDCLoginRequest represents the individual OAuth login request body

func (*OIDCLoginRequest) Validate

func (r *OIDCLoginRequest) Validate(ctx context.Context) error

Validate validates the OIDC login request

type OIDCProvider

type OIDCProvider struct {
	ID                       uuid.UUID              `json:"id"`
	ProviderName             string                 `json:"provider_name"`
	IssuerURL                string                 `json:"issuer_url"`
	ClientID                 string                 `json:"client_id"`
	Scopes                   []string               `json:"scopes"`
	Enabled                  bool                   `json:"enabled"`
	AllowedDomains           []string               `json:"allowed_domains"`
	AutoCreateUsers          bool                   `json:"auto_create_users"`
	RequireEmailVerification bool                   `json:"require_email_verification"`
	RegistrationMethod       OIDCRegistrationMethod `json:"registration_method"`
	ClientIDIssuedAt         *time.Time             `json:"client_id_issued_at,omitempty"`
	ClientSecretExpiresAt    *time.Time             `json:"client_secret_expires_at,omitempty"`
}

OIDCProvider represents an OIDC provider configuration (includes secrets)

type OIDCProviderType

type OIDCProviderType string

OIDCProviderType represents an OIDC provider type

const (
	OIDCProviderTypeGoogle    OIDCProviderType = "google"
	OIDCProviderTypeMicrosoft OIDCProviderType = "microsoft"
	OIDCProviderTypeGitHub    OIDCProviderType = "github"
	OIDCProviderTypeOkta      OIDCProviderType = "okta"
)

func (OIDCProviderType) DisplayName

func (p OIDCProviderType) DisplayName() string

DisplayName returns a human-readable name for the provider

func (OIDCProviderType) IsValid

func (p OIDCProviderType) IsValid() bool

IsValid checks if the provider type is one of the defined valid types

func (OIDCProviderType) String

func (p OIDCProviderType) String() string

String returns the string representation of the provider type

type OIDCProviderTypeInfo

type OIDCProviderTypeInfo struct {
	Type        OIDCProviderType `json:"type"`
	DisplayName string           `json:"display_name"`
}

OIDCProviderTypeInfo represents information about a supported OAuth provider type

type OIDCProviderTypesResponse

type OIDCProviderTypesResponse struct {
	Providers []OIDCProviderTypeInfo `json:"providers"`
}

OIDCProviderTypesResponse represents the response with supported OIDC provider types

type OIDCProvidersResponse

type OIDCProvidersResponse struct {
	Providers []OIDCProvider `json:"providers"`
}

OIDCProvidersResponse represents the response with a list of OIDC providers

type OIDCRegistrationMethod

type OIDCRegistrationMethod string

OIDCRegistrationMethod represents how an OIDC provider was registered

const (
	OIDCRegistrationMethodManual  OIDCRegistrationMethod = "manual"
	OIDCRegistrationMethodDynamic OIDCRegistrationMethod = "dynamic"
)

type Option

type Option func(*HTTPClient)

Option is a functional option for configuring the HTTPClient

func WithCookieJar

func WithCookieJar(jar *cookiejar.Jar) Option

WithCookieJar configures the client with a specific cookie jar. Useful for tests that need to inspect cookies (e.g., capturing refresh tokens).

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient allows setting a custom http.Client Note: If you provide a custom client for refresh token support, ensure it has a cookie jar configured

func WithInsecureSkipVerify

func WithInsecureSkipVerify() Option

WithInsecureSkipVerify configures the client to skip TLS certificate verification This is useful for development with self-signed certificates

type Permission

type Permission struct {
	ID          uuid.UUID `json:"id"`
	Name        string    `json:"name"`
	Description string    `json:"description"`
}

Permission represents a system permission

type PermissionEffect

type PermissionEffect string

PermissionEffect represents the effect of a permission (allow/deny)

const (
	PermissionAllow PermissionEffect = "allow"
	PermissionDeny  PermissionEffect = "deny"
)

type PermissionsResponse

type PermissionsResponse struct {
	Permissions []Permission `json:"permissions"`
}

PermissionsResponse represents the response with a list of permissions

type RegenerateBackupCodesRequest

type RegenerateBackupCodesRequest struct {
	Password string `json:"password"`
}

RegenerateBackupCodesRequest regenerates backup codes

func (*RegenerateBackupCodesRequest) Validate

Validate validates the regenerate backup codes request

type RegisterRequest

type RegisterRequest struct {
	Email     string `json:"email"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
}

RegisterRequest represents the registration request body Password is set during email verification, not during initial registration

func (*RegisterRequest) Validate

func (r *RegisterRequest) Validate(ctx context.Context) error

Validate validates the registration request

type RegisterResponse

type RegisterResponse struct {
	UserID  uuid.UUID `json:"user_id"`
	Email   string    `json:"email"`
	Message string    `json:"message"`
}

RegisterResponse represents the registration response

type RequiredMFAEnableRequest

type RequiredMFAEnableRequest struct {
	SetupToken string `json:"setup_token"` // Setup token from login response
	Code       string `json:"code"`        // TOTP code to verify setup
}

RequiredMFAEnableRequest enables MFA after required setup

func (*RequiredMFAEnableRequest) Validate

func (r *RequiredMFAEnableRequest) Validate(ctx context.Context) error

Validate validates the required MFA enable request

type RequiredMFASetupRequest

type RequiredMFASetupRequest struct {
	SetupToken string `json:"setup_token"` // Setup token from login response
}

RequiredMFASetupRequest initiates MFA setup when role requires it

func (*RequiredMFASetupRequest) Validate

func (r *RequiredMFASetupRequest) Validate(ctx context.Context) error

Validate validates the required MFA setup request

type ResetPasswordRequest

type ResetPasswordRequest struct {
	Token       string `json:"token"`
	NewPassword string `json:"new_password"`
}

ResetPasswordRequest represents the reset password request body

func (*ResetPasswordRequest) Validate

func (r *ResetPasswordRequest) Validate(ctx context.Context) error

Validate validates the reset password request

type ResetPasswordResponse

type ResetPasswordResponse struct {
	Message string `json:"message"`
}

ResetPasswordResponse represents the reset password response

type RevokeSessionRequest

type RevokeSessionRequest struct {
	SessionID uuid.UUID `json:"-"` // From URL parameter
}

RevokeSessionRequest represents the request to revoke a specific session

func (*RevokeSessionRequest) Validate

func (r *RevokeSessionRequest) Validate(ctx context.Context) error

Validate validates the revoke session request

type Role

type Role struct {
	ID          uuid.UUID `json:"id"`
	Name        string    `json:"name"`
	Description string    `json:"description"`
	MFARequired bool      `json:"mfa_required"`
}

Role represents a role with its metadata

type RolesResponse

type RolesResponse struct {
	Roles []Role `json:"roles"`
}

RolesResponse represents the response with a list of roles

type SSOLoginRequest

type SSOLoginRequest struct {
	Email string `json:"email"`
}

SSOLoginRequest represents the corporate SSO login request body

func (*SSOLoginRequest) Validate

func (r *SSOLoginRequest) Validate(ctx context.Context) error

Validate validates the SSO login request

type Session

type Session struct {
	ID         uuid.UUID `json:"id"`
	UserAgent  string    `json:"user_agent"`
	IPAddress  string    `json:"ip_address"`
	CreatedAt  time.Time `json:"created_at"`
	LastUsedAt time.Time `json:"last_used_at"`
}

Session represents an active session in API responses

type SessionsResponse

type SessionsResponse struct {
	Sessions []Session `json:"sessions"`
}

SessionsResponse represents the response with a list of sessions

type SetDirectPermissionsRequest

type SetDirectPermissionsRequest struct {
	UserID      uuid.UUID          `json:"-"`
	Permissions []DirectPermission `json:"permissions"`
}

SetDirectPermissionsRequest represents the request to set all direct permissions for a user

func (*SetDirectPermissionsRequest) Validate

Validate validates the set user permissions request

type SetRolePermissionsRequest

type SetRolePermissionsRequest struct {
	RoleID        uuid.UUID   `json:"-"`
	PermissionIDs []uuid.UUID `json:"permission_ids"`
}

SetRolePermissionsRequest represents the request to set all permissions for a role

func (*SetRolePermissionsRequest) Validate

Validate validates the set role permissions request

type SetUserRolesRequest

type SetUserRolesRequest struct {
	UserID  uuid.UUID   `json:"-"`
	RoleIDs []uuid.UUID `json:"role_ids"`
}

SetUserRolesRequest represents the request to set all roles for a user

func (*SetUserRolesRequest) Validate

func (r *SetUserRolesRequest) Validate(ctx context.Context) error

Validate validates the set user roles request

type UpdateOIDCProviderRequest

type UpdateOIDCProviderRequest struct {
	ProviderID               uuid.UUID `json:"-"`                                    // From URL parameter, not JSON body
	ProviderName             *string   `json:"provider_name,omitempty"`              // Optional: update display name
	ClientSecret             *string   `json:"client_secret,omitempty"`              // Optional: rotate secret
	Scopes                   []string  `json:"scopes,omitempty"`                     // Optional: nil = keep, [] = clear, non-empty = update
	Enabled                  *bool     `json:"enabled,omitempty"`                    // Optional: update enabled status
	AllowedDomains           []string  `json:"allowed_domains,omitempty"`            // Optional: nil = keep, non-nil = update
	AutoCreateUsers          *bool     `json:"auto_create_users,omitempty"`          // Optional: update auto-create users flag
	RequireEmailVerification *bool     `json:"require_email_verification,omitempty"` // Optional: update email verification requirement
}

UpdateOIDCProviderRequest represents the request to update an OIDC provider All fields are optional pointers to support partial updates

func (*UpdateOIDCProviderRequest) Validate

Validate validates the update OIDC provider request

type UpdateRoleRequest

type UpdateRoleRequest struct {
	RoleID      uuid.UUID `json:"-"`
	Name        *string   `json:"name,omitempty"`
	Description *string   `json:"description,omitempty"`
	MFARequired *bool     `json:"mfa_required,omitempty"`
}

UpdateRoleRequest represents the request to update a role (supports partial updates)

func (*UpdateRoleRequest) Validate

func (r *UpdateRoleRequest) Validate(ctx context.Context) error

Validate validates the update role request

type User

type User struct {
	ID        uuid.UUID `json:"id"`
	TenantID  uuid.UUID `json:"tenant_id"`
	Email     string    `json:"email"`
	FirstName string    `json:"first_name"`
	LastName  string    `json:"last_name"`
	Status    string    `json:"status"`
}

User represents a user in API responses

type VerifyEmailRequest

type VerifyEmailRequest struct {
	Token    string `json:"token"`
	Password string `json:"password"`
}

VerifyEmailRequest represents the email verification request body User proves email ownership and sets their password

func (*VerifyEmailRequest) Validate

func (r *VerifyEmailRequest) Validate(ctx context.Context) error

Validate validates the verify email request

type VerifyMFACodeRequest

type VerifyMFACodeRequest struct {
	ChallengeToken string `json:"challenge_token"` // Challenge token from initial login
	Code           string `json:"code"`            // TOTP code (6 digits) or backup code (8 digits)
	TrustDevice    bool   `json:"trust_device"`    // Optional: trust this device for 30 days (skip MFA on next login)
}

VerifyMFACodeRequest verifies MFA code

func (*VerifyMFACodeRequest) Validate

func (r *VerifyMFACodeRequest) Validate(ctx context.Context) error

Validate validates the verify MFA code request

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL