https://github.com/brenekh/go-traktdeviceauth
A Go library to allow an end user to authorize a third-party Trakt application access to their account using the device method.
https://github.com/brenekh/go-traktdeviceauth
auth authentication device-authentication go go-library golang golang-library trakt trakt-api trakt-tv trakttv
Last synced: about 1 year ago
JSON representation
A Go library to allow an end user to authorize a third-party Trakt application access to their account using the device method.
- Host: GitHub
- URL: https://github.com/brenekh/go-traktdeviceauth
- Owner: BrenekH
- License: apache-2.0
- Created: 2022-01-07T03:57:00.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-10-10T19:39:56.000Z (over 3 years ago)
- Last Synced: 2025-02-16T16:38:39.834Z (over 1 year ago)
- Topics: auth, authentication, device-authentication, go, go-library, golang, golang-library, trakt, trakt-api, trakt-tv, trakttv
- Language: Go
- Homepage: https://pkg.go.dev/github.com/BrenekH/go-traktdeviceauth
- Size: 114 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Trakt Device Auth Library
[](https://pkg.go.dev/github.com/BrenekH/go-traktdeviceauth)

[](https://github.com/BrenekH/go-traktdeviceauth/tree/master/LICENSE)

A Go library to allow an end user to authorize a third-party Trakt application access to their account using the [device method](https://trakt.docs.apiary.io/#reference/authentication-devices/generate-new-device-codes).
## 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](https://trakt.tv/oauth/applications), as shown in the image below.

### Context Functions
Many functions in this library have context counterparts which allow a custom [context.Context](https://pkg.go.dev/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](https://github.com/BrenekH/go-traktdeviceauth/releases/latest).
## Usage
As suggested by the [official API docs](https://trakt.docs.apiary.io/#reference/authentication-devices/generate-new-device-codes), a device and user code pair must be generated as the first step using [GenerateNewCode](https://pkg.go.dev/github.com/BrenekH/go-traktdeviceauth#GenerateNewCode).
Next, the user needs to directed to the returned verification url and instructed to enter the user code into the website.
Finally, [PollForAuthToken](https://pkg.go.dev/github.com/BrenekH/go-traktdeviceauth#GenerateNewCode) 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](https://pkg.go.dev/github.com/BrenekH/go-traktdeviceauth#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](LICENSE).