mfa

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidType        = errors.New("type must be present and 'sms' or 'totp'")
	ErrIncompleteArgs     = errors.New("need to specify both totp_issuer and totp_user when type is totp")
	ErrNoPhoneNumber      = errors.New("need to specify phone_number when type is sms")
	ErrMissingAuthId      = errors.New("authentication_factor_id' is a required parameter")
	ErrMissingChallengeId = errors.New("challenge_factor_id' is a required parameter")
)

This represents the list of errors that could be raised when using the mfa package

View Source
var (
	DefaultClient = &Client{
		Endpoint: "https://api.workos.com",
	}
)

DefaultClient is the client used by SetAPIKey and mfa functions.

Functions

func DeleteFactor

func DeleteFactor(
	ctx context.Context,
	opts DeleteFactorOpts,
) error

DeleteFactor deletes a factor by ID.

func SetAPIKey

func SetAPIKey(apiKey string)

SetAPIKey sets the WorkOS API key for mfa requests.

func VerifyFactor deprecated

func VerifyFactor(
	ctx context.Context,
	opts VerifyChallengeOpts,
) (interface{}, error)

Deprecated: Use VerifyChallenge instead

Types

type Challenge

type Challenge struct {
	// The authentication challenge's unique ID
	ID string `json:"id"`

	// The name of the response type.
	Object string `json:"object"`

	// The timestamp of when the request was created.
	CreatedAt string `json:"created_at"`

	// The timestamp of when the request was updated.
	UpdatedAt string `json:"updated_at"`

	// The timestamp of when the request expires.
	ExpiresAt string `json:"expires_at"`

	// The authentication factor Id used to create the request.
	FactorID string `json:"authentication_factor_id"`
}

func ChallengeFactor

func ChallengeFactor(
	ctx context.Context,
	opts ChallengeFactorOpts,
) (Challenge, error)

ChallengeFactor Initiates the authentication process for the newly created MFA authorization factor.

type ChallengeFactorOpts

type ChallengeFactorOpts struct {
	// ID of the authorization factor.
	FactorID string

	// Parameter to customize the message for sms type factors. Must include "{{code}}" if used (opt).
	SMSTemplate string
}

type Client

type Client struct {
	// The WorkOS API Key. It can be found in https://dashboard.workos.com/api-keys.
	APIKey string

	// Defaults to http.Client.
	HTTPClient *http.Client

	// The endpoint to WorkOS API. Defaults to https://api.workos.com.
	Endpoint string

	// The function used to encode in JSON. Defaults to json.Marshal.
	JSONEncode func(v interface{}) ([]byte, error)
	// contains filtered or unexported fields
}

Client represents a client that performs MFA requests to the WorkOS API.

func (*Client) ChallengeFactor

func (c *Client) ChallengeFactor(
	ctx context.Context,
	opts ChallengeFactorOpts,
) (Challenge, error)

Initiates the authentication process for the newly created MFA authorization factor, referred to as a challenge.

func (*Client) DeleteFactor

func (c *Client) DeleteFactor(
	ctx context.Context,
	opts DeleteFactorOpts,
) error

Deletes an authentication factor.

func (*Client) EnrollFactor

func (c *Client) EnrollFactor(
	ctx context.Context,
	opts EnrollFactorOpts,
) (Factor, error)

Create an Authentication Factor.

func (*Client) GetFactor

func (c *Client) GetFactor(
	ctx context.Context,
	opts GetFactorOpts,
) (Factor, error)

Retrieves an authentication factor.

func (*Client) VerifyChallenge

func (c *Client) VerifyChallenge(
	ctx context.Context,
	opts VerifyChallengeOpts,
) (VerifyChallengeResponse, error)

Verifies the one time password provided by the end-user.

func (*Client) VerifyFactor deprecated

func (c *Client) VerifyFactor(ctx context.Context, opts VerifyChallengeOpts) (interface{}, error)

Deprecated: Use VerifyChallenge instead.

type DeleteFactorOpts

type DeleteFactorOpts struct {
	// ID of factor to be deleted
	FactorID string
}

type EnrollFactorOpts

type EnrollFactorOpts struct {

	// Type of factor to be enrolled (sms or totp).
	Type FactorType

	// Name of the Organization.
	TOTPIssuer string

	// Email of user.
	TOTPUser string

	// Phone Number of the User.
	PhoneNumber string
}

EnrollFactorOpts contains the options to create an Authentication Factor.

type Factor

type Factor struct {
	// The authentication factor's unique ID
	ID string `json:"id"`

	// The name of the response type
	Object string `json:"object"`

	// The timestamp of when the request was created.
	CreatedAt string `json:"created_at"`

	// The timestamp of when the request was updated.
	UpdatedAt string `json:"updated_at"`

	// The type of request either 'sms' or 'totp'
	Type FactorType `json:"type"`

	// Details of the totp response will be 'null' if using sms
	TOTP TOTPDetails `json:"totp"`

	// Details of the sms response will be 'null' if using totp
	SMS SMSDetails `json:"sms"`
}

func EnrollFactor

func EnrollFactor(
	ctx context.Context,
	opts EnrollFactorOpts,
) (Factor, error)

EnrollFactor creates a MFA authorization factor.

func GetFactor

func GetFactor(
	ctx context.Context,
	opts GetFactorOpts,
) (Factor, error)

GetFactor gets a factor by ID.

type FactorType

type FactorType string

Type represents the type of Authentication Factor

const (
	SMS  FactorType = "sms"
	TOTP FactorType = "totp"
)

Constants that enumerate the available Types.

type GetFactorOpts

type GetFactorOpts struct {
	// ID of the factor.
	FactorID string
}

type RawVerifyChallengeResponse

type RawVerifyChallengeResponse struct {
	VerifyChallengeResponse
	VerifyChallengeResponseError
}

type SMSDetails

type SMSDetails struct {
	PhoneNumber string `json:"phone_number"`
}

type TOTPDetails

type TOTPDetails struct {
	QRCode string `json:"qr_code"`
	Secret string `json:"secret"`
	URI    string `json:"uri"`
}

type VerificationResponseError

type VerificationResponseError struct {
	Code    string
	Message string
}

func (VerificationResponseError) Error

type VerifyChallengeOpts

type VerifyChallengeOpts struct {
	// The ID of the authentication challenge that provided the user the verification code.
	ChallengeID string

	// The verification code sent to and provided by the end user.
	Code string
}

type VerifyChallengeResponse

type VerifyChallengeResponse struct {
	// Return details of the request
	Challenge Challenge `json:"challenge"`

	// Boolean returning if request is valid
	Valid bool `json:"valid"`
}

func VerifyChallenge

func VerifyChallenge(
	ctx context.Context,
	opts VerifyChallengeOpts,
) (VerifyChallengeResponse, error)

VerifyChallenge verifies the one time password provided by the end-user.

type VerifyChallengeResponseError

type VerifyChallengeResponseError struct {
	// Returns string of error code on response with valid: false
	Code string `json:"code"`

	// Returns string of message on response with valid: false
	Message string `json:"message"`
}

Jump to

Keyboard shortcuts

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