devicecheck

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 14 Imported by: 0

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/v2

Getting started

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

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)
Options

WithCustomHttpClient - set your custom http client WithCustomBaseURLs - change base url (this option more priority)

client := New(creds, cfg, WithCustomBaseURLs("https://google.com/api/v1"))
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, options ...Option) *Client

New returns a new DeviceCheck API client.

func (*Client) QueryTwoBits

func (client *Client) QueryTwoBits(ctx context.Context, 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(ctx context.Context, deviceToken string, bit0, bit1 bool) error

UpdateTwoBits updates two bits for device token.

func (*Client) ValidateDeviceToken

func (client *Client) ValidateDeviceToken(ctx context.Context, 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 Option

type Option func(a *api)

func WithCustomBaseURLs

func WithCustomBaseURLs(url string) Option

WithCustomBaseURLs - change base url (this option more priority)

func WithCustomHttpClient

func WithCustomHttpClient(httpClient *http.Client) Option

WithCustomHttpClient - set your custom http client

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