yubiotp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package yubiotp provides a client for the OTP validation server (YubiCloud or self-hosted) and the validation server implementation.

See https://developers.yubico.com/OTP/.

Index

Constants

View Source
const (
	StatusOK                  = Status("OK")
	StatusBadOTP              = Status("BAD_OTP")
	StatusReplayedOTP         = Status("REPLAYED_OTP")
	StatusBadSignature        = Status("BAD_SIGNATURE")
	StatusMissingParameter    = Status("MISSING_PARAMETER")
	StatusNoSuchClient        = Status("NO_SUCH_CLIENT")
	StatusOperationNotAllowed = Status("OPERATION_NOT_ALLOWED")
	StatusBackendError        = Status("BACKEND_ERROR")
	StatusNotEnoughAnswers    = Status("NOT_ENOUGH_ANSWERS")
	StatusReplayedRequest     = Status("REPLAYED_REQUEST")
)

Known validation statuses.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Client represents validation server's client.

It can be used with both YubiCloud and self-hosted servers.

See:

func NewClient

func NewClient(clientID, secretKey string) (*Client, error)

NewClient creates a new client with given client ID (required by YubiCloud, use "1" if unknown) and base64-encoded secret key (optional).

func (*Client) SetURL

func (c *Client) SetURL(rawurl string) error

SetURL sets self-hosted validation server URL, or resets it to use YubiCloud if empty.

func (*Client) Validate

func (c *Client) Validate(ctx context.Context, otp string) (*Response, error)

Validate calls validation server to check OTP.

In case of validation or any other error, error is returned. Non-nil response may be returned if it was parsed, even if validation failed.

type Response

type Response struct {
	OTP            string
	Nonce          string
	H              []byte
	T              time.Time
	Status         Status
	Timestamp      int32 // actually, unsigned 24 bit
	SessionCounter int
	SessionUse     int
	Sl             string
}

Response represents validation server's response.

type Status

type Status string

Status represents validation status, as returned by the server.

func (Status) Error

func (s Status) Error() string

Jump to

Keyboard shortcuts

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