Documentation
¶
Overview ¶
Package auth has the responsibility to handle the authentication to the Remarkable Cloud API.
For this purpose, it provides a *http.Client that can be used with the api package. This *http.Client will hold the authentication process that will allow the api package to interact with the Remarkable API without worrying about auth. We do take advantage of a custom http.Transport that is by default attached to the http.Client and that will act as a middleware to attach HTTP auth headers.
This separation means that in the future, another auth could be implemented if Remarkable decides to change / improve it. As well, the api package is clearer because not cluttered by any auth processes.
Index ¶
Constants ¶
const ClientTimeout time.Duration = time.Second * 10
ClientTimeout is the timeout set for the http.Client that auth is providing.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth struct { // Refresh can be used to force a refresh of the UserToken. Refresh bool // contains filtered or unexported fields }
Auth is a structure containing authentication gears to fetch and hold tokens for interacting authenticated with the Remarkable Cloud API.
func NewFromStore ¶
func NewFromStore(ts TokenStore) *Auth
func (*Auth) Client ¶
Client returns a configured http.Client that will hold a custom Transport with authentication capabilities to the Remarkable Cloud API.
func (*Auth) RegisterDevice ¶
RegisterDevice will make an HTTP call to the Remarkable API using the provided code to register a new device. The code should be gathered at https://my.remarkable.com/generator-device. The DeviceToken is then attached to the Auth instance.
type FileTokenStore ¶
type FileTokenStore struct {
Path string
}
FileTokenStore implements TokenStore by fetching and saving tokens to a plain file.
func (*FileTokenStore) Load ¶
func (ft *FileTokenStore) Load() (TokenSet, error)
Load will return a TokenSet with content populated from a yaml file containing the values.
func (*FileTokenStore) Save ¶
func (ft *FileTokenStore) Save(t TokenSet) error
Save will persist a TokenSet into a yaml file.
type TokenSet ¶
type TokenSet struct { // DeviceToken is a token that gets returned after // registering a device to the API. It can be fetched using the RegisterDevice method // or can be set manually for caching purposes. DeviceToken string `yaml:"devicetoken"` // UserToken is a token that gets returned as a second step, by the help of a previously // fetched DeviceToken and is actually used to make the proper authenticated // HTTP calls to the Remarkable API. Set to empty to force fetching it again. UserToken string `yaml:"usertoken"` }
TokenSet contains tokens needed for the Remarkable Cloud authentication.
type TokenStore ¶
TokenStore is an interface that will allow to load and save tokens needed for the Remarkable Cloud API.
type Transport ¶
type Transport struct { // Auth supplies the token to add to outgoing requests' // Authorization headers. Auth *Auth // Base is the base RoundTripper used to make HTTP requests. // If nil, http.DefaultTransport is used. Base http.RoundTripper // contains filtered or unexported fields }
Transport is an http.RoundTripper that makes requests to the Remarkable Cloud API wrapping a base RoundTripper and adding an Authorization header with a token from the supplied Auth
func (*Transport) RoundTrip ¶
RoundTrip authorizes and authenticates the request with an access token from Transport's Auth.
RoundTrip makes sure req.Body is closed anyway. RoundTrip is cloning the original request to respect the RoundTripper contract.
In order to avoid having two authenticating requests at the same time we make use of a Mutex.