Skip to content

A Go library to allow an end user to authorize a third-party Trakt application access to their account using the device method.

License

Notifications You must be signed in to change notification settings

BrenekH/go-traktdeviceauth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Trakt Device Auth Library

GoDoc GitHub release (latest by date) License GitHub go.mod Go version

A Go library to allow an end user to authorize a third-party Trakt application access to their account using the device method.

Conventions

Client ID and Client Secret

Throughout the library, the Client ID and Client Secret are used to tell Trakt which app is requesting access. These values are found in the dashboard for the app on Trakt's website, as shown in the image below.

Client ID and Client Secret on the Trakt Application Dashboard

Context Functions

Many functions in this library have context counterparts which allow a custom context.Context to be used. If you don't know what all this means, you'll probably be fine sticking with the non-context versions.

Installation

As a Go library: go get -u github.com/BrenekH/go-traktdeviceauth

As an executable: go install github.com/BrenekH/go-traktdeviceauth/cmd@latest or download from the latest release.

Usage

As suggested by the official API docs, a device and user code pair must be generated as the first step using GenerateNewCode. Next, the user needs to directed to the returned verification url and instructed to enter the user code into the website. Finally, PollForAuthToken is used to wait for the user to complete authentication or the code to expire.

If the returned access token expires, a new one can be generated with asking the user to re-authenticate by using RefreshAccessToken

Trakt recommends that the AccessToken and RefreshToken be saved in permanent storage so that the user doesn't need to log in every time your program starts.

License

This project is licensed under the Apache 2.0 license, a copy of which can be found in LICENSE.