A Go library to allow an end user to authorize a third-party Trakt application access to their account using the device method.
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.
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.
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.
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.
This project is licensed under the Apache 2.0 license, a copy of which can be found in LICENSE.