mfa

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2022 License: MIT Imports: 12 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 added in v1.19.0

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 VerifyChallenge added in v1.13.0

func VerifyChallenge(
	ctx context.Context,
	opts VerifyOpts,
) (interface{}, error)

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

func VerifyFactor deprecated

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

Deprecated: Use VerifyChallenge instead

Types

type ChallengeOpts

type ChallengeOpts struct {
	// ID of the authorization factor.
	AuthenticationFactorID string

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

type ChallengeResponse

type ChallengeResponse 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.
	AuthenticationFactorID string `json:"authentication_factor_id"`
}

func ChallengeFactor

func ChallengeFactor(
	ctx context.Context,
	opts ChallengeOpts,
) (ChallengeResponse, error)

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

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 ChallengeOpts,
) (ChallengeResponse, error)

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

func (*Client) DeleteFactor added in v1.19.0

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 GetEnrollOpts,
) (EnrollResponse, error)

Create an Authentication Factor.

func (*Client) GetFactor added in v1.19.0

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

Retrieves an authentication factor.

func (*Client) VerifyChallenge added in v1.13.0

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

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

func (*Client) VerifyFactor deprecated

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

Deprecated: Use VerifyChallenge instead.

type DeleteFactorOpts added in v1.19.0

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

type EnrollResponse

type EnrollResponse 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 string `json:"type"`

	// Details of the totp response will be 'null' if using sms
	Totp map[string]interface{} `json:"totp"`

	// Details of the sms response will be 'null' if using totp
	Sms map[string]interface{} `json:"sms"`
}

func EnrollFactor

func EnrollFactor(
	ctx context.Context,
	opts GetEnrollOpts,
) (EnrollResponse, error)

EnrollFactor creates a MFA authorization factor.

func GetFactor added in v1.19.0

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

GetFactor gets a factor by ID.

type GetEnrollOpts

type GetEnrollOpts struct {
	// Type of factor to be enrolled (sms or totp).
	Type string

	// Name of the Organization.
	TotpIssuer string

	// Email of user.
	TotpUser string

	// Phone Number of the User.
	PhoneNumber string
}

GetEnrollsOpts contains the options to create an Authentication Factor.

type GetFactorOpts added in v1.19.0

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

type RawVerifyResponse

type RawVerifyResponse struct {
	VerifyResponse
	VerifyResponseError
}

type VerifyOpts

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

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

type VerifyResponse

type VerifyResponse struct {
	// Return details of the request
	Challenge map[string]interface{} `json:"challenge"`

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

type VerifyResponseError

type VerifyResponseError 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