authy

package module
v0.0.0-...-44d7425 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2020 License: MIT Imports: 9 Imported by: 0

README

authy-go

Authy Client for Golang

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	ApiSecret string
	ApiFormat string //xml or json defaults to json if not provided
}

type AuthyUser

type AuthyUser struct {
	Email           string `url:"user[email],omitempty"`
	Cellphone       string `url:"user[cellphone]"`
	CountryCode     string `url:"user[country_code]"`
	SendInstallLink bool   `url:"send_install_link_via_sms,omitempty"`
}

AuthyUser is for use when creating users with Authy API the new user endpoitn expects at lease the cellphone and country code params

type Client

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

Client for interacting with the Authy API

func NewClient

func NewClient(a App) *Client

NewClient returns a client to make requests to the Authy API

func (*Client) CheckOTPToken

func (c *Client) CheckOTPToken(authyUserID int64, token string) (bool, error)

CheckOTPToken checks with authy API whether the provided token is valid in order to grant access - response can't use standard response message with this endpoint because it returns "true" rather than true for json values - could write a customer UnmarshalJSON for the struct to clean it up this method is really ugly because the authy API sends back different types for true (string) and false (bool) it currently throws an error on unmarshal instead of denying based on the reading of the response

func (*Client) CreateUser

func (c *Client) CreateUser(au AuthyUser) (int64, error)

CreateUser creates a user - must provide cellphone number and country code for request to be processed

func (*Client) Get

func (c *Client) Get(relPath string, resource interface{}) error

Get takes a relative path to which it makes a GET request and returns reads the response data into the resource provided

func (*Client) GetAppInfo

func (c *Client) GetAppInfo() (*ResponseMessage, error)

GetAppInfo gets the app info for the provided API secret

func (*Client) NewRequest

func (c *Client) NewRequest(method, relPath string, body interface{}) (*http.Request, error)

NewRequest creates a new request with the given method, path and marshals the given body into url encoded data

func (*Client) Post

func (c *Client) Post(relPath string, body interface{}, resource interface{}) error

Post to Authy API based on path provided

func (*Client) RemoveUser

func (c *Client) RemoveUser(authyUserID int64) error

RemoveUser removes a user from Authy API

func (*Client) SendOTP

func (c *Client) SendOTP(authyUserID int64) (*ResponseMessage, error)

SendOTP triggers a OTP to be sent to the user based on their authy ID requires a user to be already added to authy

func (*Client) SendOTPWithAction

func (c *Client) SendOTPWithAction(authyUserID int64, action, actionMessage string) (*ResponseMessage, error)

SendOTPWithAction triggers a OTP to be sent to the user based with a custom message on their authy ID requires a user to be already added to authy https://www.twilio.com/docs/authy/api/one-time-passwords

func (*Client) UserStatus

func (c *Client) UserStatus(authyUserID int64) (*ResponseMessage, error)

UserStatus requests the current status of the provided user ID in the authy API

type ResponseMessage

type ResponseMessage struct {
	App     authyAppInfo `json:"app"`
	User    user         `json:"user"`
	Status  status       `json:"status"`
	Device  device       `json:"device"`
	Token   string       `json:"token"`
	Message string       `json:"message"`
	Success bool         `json:"success"`
}

ResponseMessage is the wrapper for the data returned by the authy API

Jump to

Keyboard shortcuts

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