devicecheck

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2021 License: MIT Imports: 14 Imported by: 1

README

device-check-go

📱 iOS DeviceCheck SDK for Go - query and modify the per-device bits

Installation

go get github.com/rinchsan/device-check-go

Getting started

Initialize SDK
import "github.com/rinchsan/device-check-go"

cred := devicecheck.NewCredentialFile("/path/to/private/key/file") // You can create credential also from raw string/bytes
cfg := devicecheck.NewConfig("ISSUER", "KEY_ID", devicecheck.Development)
client := devicecheck.New(cred, cfg)
Use DeviceCheck API
Query two bits
var result devicecheck.QueryTwoBitsResult
if err := client.QueryTwoBits("DEVICE_TOKEN", &result); err != nil {
	switch {
	// Note that QueryTwoBits returns ErrBitStateNotFound error if no bits found
	case errors.Is(err, devicecheck.ErrBitStateNotFound):
		// handle ErrBitStateNotFound error
	default:
		// handle other errors
	}
}
Update two bits
if err := client.UpdateTwoBits("DEVICE_TOKEN", true, true); err != nil {
	// handle errors
}
Validate device token
if err := client.ValidateDeviceToken("DEVICE_TOKEN"); err != nil {
	// handle errors
}

Apple documentation

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadRequest         = errors.New("bad request")
	ErrUnauthorized       = errors.New("invalid or expired token")
	ErrForbidden          = errors.New("action not allowed")
	ErrMethodNotAllowed   = errors.New("method not allowed")
	ErrTooManyRequests    = errors.New("too many requests")
	ErrServer             = errors.New("server error")
	ErrServiceUnavailable = errors.New("service unavailable")
	ErrUnknown            = errors.New("unknown error")
	ErrBitStateNotFound   = errors.New("bit state not found")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides methods to use DeviceCheck API.

func New

func New(cred Credential, cfg Config) *Client

New returns a new DeviceCheck API client.

func NewWithHTTPClient

func NewWithHTTPClient(httpClient *http.Client, cred Credential, cfg Config) *Client

NewWithHTTPClient returns a new DeviceCheck API client with specified http client.

func (*Client) QueryTwoBits

func (client *Client) QueryTwoBits(deviceToken string, result *QueryTwoBitsResult) error

QueryTwoBits queries two bits for device token. Returns ErrBitStateNotFound if the bits have not been set.

func (*Client) UpdateTwoBits

func (client *Client) UpdateTwoBits(deviceToken string, bit0, bit1 bool) error

UpdateTwoBits updates two bits for device token.

func (*Client) ValidateDeviceToken

func (client *Client) ValidateDeviceToken(deviceToken string) error

ValidateDeviceToken validates a device for device token.

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config provides configuration for DeviceCheck API.

func NewConfig

func NewConfig(issuer, keyID string, env Environment) Config

NewConfig returns a new configuration.

type Credential

type Credential interface {
	// contains filtered or unexported methods
}

Credential provides credential for DeviceCheck API.

func NewCredentialBytes

func NewCredentialBytes(raw []byte) Credential

NewCredentialBytes returns credential from private key bytes.

func NewCredentialFile

func NewCredentialFile(filename string) Credential

NewCredentialFile returns credential from private key file.

func NewCredentialString

func NewCredentialString(str string) Credential

NewCredentialString returns credential from private key string.

type Environment

type Environment int

Environment specifies DeviceCheck API environment.

const (
	// Development specifies Apple's development environment.
	Development Environment = iota + 1
	// Production specifies Apple's production environment.
	Production
)

type QueryTwoBitsResult

type QueryTwoBitsResult struct {
	Bit0           bool `json:"bit0"`
	Bit1           bool `json:"bit1"`
	LastUpdateTime Time `json:"last_update_time"`
}

QueryTwoBitsResult provides a result of query-two-bits method.

type Time

type Time struct {
	time.Time
}

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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