Documentation
¶
Overview ¶
Package sdk provides a lightweight LessOTP API client and webhook verification helpers.
Index ¶
- func VerifyWebhookSignature(rawBody []byte, signatureHeader string, secret string) bool
- type AuthRequestOptions
- type AuthRequestParams
- type AuthRequestResult
- type Client
- func (c *Client) AuthRequest(ctx context.Context, phoneNumber *string, opts ...AuthRequestOptions) (AuthRequestResult, error)
- func (c *Client) RequestAuth(ctx context.Context, params AuthRequestParams, opts ...AuthRequestOptions) (AuthRequestResult, error)
- func (c *Client) RequestTelegramAuth(ctx context.Context, phoneNumber *string, opts ...AuthRequestOptions) (AuthRequestResult, error)
- func (c *Client) RequestWhatsAppAuth(ctx context.Context, phoneNumber *string, opts ...AuthRequestOptions) (AuthRequestResult, error)
- type Environment
- type Options
- type VerificationChannel
- type VerificationMode
- type VerificationSuccess
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func VerifyWebhookSignature ¶
VerifyWebhookSignature returns true when signatureHeader is a valid HMAC-SHA256 of rawBody using secret. Accepts both raw hex and `sha256=` prefixed values. Always returns a boolean; never panics on malformed input.
Types ¶
type AuthRequestOptions ¶
type AuthRequestOptions struct {
Environment Environment
}
AuthRequestOptions are optional per-request overrides.
type AuthRequestParams ¶ added in v0.2.0
type AuthRequestParams struct {
// Channel defaults to ChannelWhatsApp when empty.
Channel VerificationChannel
// PhoneNumber enables strict mode. Nil means frictionless mode.
PhoneNumber *string
}
AuthRequestParams configure a multi-channel auth request.
type AuthRequestResult ¶
type AuthRequestResult struct {
RequestID string `json:"request_id"`
UniqueCode string `json:"unique_code"`
Channel VerificationChannel `json:"channel"`
WaLink string `json:"wa_link,omitempty"`
TelegramLink string `json:"telegram_link,omitempty"`
TelegramText string `json:"telegram_text,omitempty"`
ExpiresIn int `json:"expires_in"`
Mode VerificationMode `json:"mode"`
}
AuthRequestResult is the normalized response of POST /api/v1/auth/request.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a stateless HTTP client for the LessOTP API. Safe for concurrent use.
func (*Client) AuthRequest ¶
func (c *Client) AuthRequest(ctx context.Context, phoneNumber *string, opts ...AuthRequestOptions) (AuthRequestResult, error)
AuthRequest creates a WhatsApp verification request.
If phoneNumber is nil, the request is frictionless. Otherwise the phoneNumber is sent as strict-mode `phone_number`. The endpoint is selected from AuthRequestOptions.Environment when provided, otherwise the Client's environment. This method is kept for backward compatibility; use RequestAuth or RequestTelegramAuth for explicit multi-channel calls.
func (*Client) RequestAuth ¶ added in v0.2.0
func (c *Client) RequestAuth(ctx context.Context, params AuthRequestParams, opts ...AuthRequestOptions) (AuthRequestResult, error)
RequestAuth creates a multi-channel verification request.
Channel defaults to WhatsApp for backward compatibility. Endpoint selection follows the client environment unless overridden per call.
func (*Client) RequestTelegramAuth ¶ added in v0.2.0
func (c *Client) RequestTelegramAuth(ctx context.Context, phoneNumber *string, opts ...AuthRequestOptions) (AuthRequestResult, error)
RequestTelegramAuth creates a Telegram verification request.
Strict mode: pass phoneNumber. Frictionless mode: pass nil. Telegram users always verify by tapping the official Share phone number button; LessOTP does not accept manually typed phone numbers as Telegram identity.
func (*Client) RequestWhatsAppAuth ¶ added in v0.2.0
func (c *Client) RequestWhatsAppAuth(ctx context.Context, phoneNumber *string, opts ...AuthRequestOptions) (AuthRequestResult, error)
RequestWhatsAppAuth creates a WhatsApp verification request.
type Environment ¶
type Environment string
Environment selects the endpoint family. Production is the default.
const ( EnvironmentProduction Environment = "production" EnvironmentStaging Environment = "staging" )
type Options ¶
type Options struct {
APIKey string
Environment Environment // default: production
BaseURL string // default: https://api.lessotp.com
Timeout time.Duration // default: 10s
HTTPClient *http.Client
}
Options configure a Client. All fields are optional except APIKey.
type VerificationChannel ¶ added in v0.2.0
type VerificationChannel string
VerificationChannel selects the inbound phone authentication channel. WhatsApp is the default for backward compatibility.
const ( ChannelWhatsApp VerificationChannel = "whatsapp" ChannelTelegram VerificationChannel = "telegram" )
type VerificationMode ¶
type VerificationMode string
VerificationMode is the `mode` value returned by LessOTP's auth request API.
const ( ModeStrict VerificationMode = "strict" ModeFrictionless VerificationMode = "frictionless" )
type VerificationSuccess ¶
type VerificationSuccess struct {
Event string `json:"event"`
Channel VerificationChannel `json:"channel,omitempty"`
RequestID string `json:"request_id"`
PhoneNumber string `json:"phone_number"`
TelegramUserID string `json:"telegram_user_id,omitempty"`
TelegramUsername string `json:"telegram_username,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
}
VerificationSuccess represents a `verification.success` webhook payload.
func ParseVerificationSuccess ¶
func ParseVerificationSuccess(rawBody []byte) (VerificationSuccess, error)
ParseVerificationSuccess parses a `verification.success` payload. The caller must verify the signature first using VerifyWebhookSignature.