[28] #800 Change Trakt Auth Process

pull/811/head
meisnate12 3 years ago
parent c12aa54fec
commit 0b99b1994d

@ -1 +1 @@
1.16.2-develop27
1.16.2-develop28

@ -115,6 +115,7 @@ sonarr: # Can be individually specified
trakt:
client_id: ################################################################
client_secret: ################################################################
pin:
authorization:
# everything below is autofilled by the script
access_token:

@ -4,6 +4,8 @@ Configuring [Radarr](https://radarr.video/) is optional but will allow you to se
Radarr V2 may work, but it is not supported please upgrade to V3 if you can.
Items in your List Exclusions will be ignored by PMM.
A `radarr` mapping can be either in the root of the config file as global mapping for all libraries, or you can specify the `radarr` mapping individually per library.
Below is a `radarr` mapping example and the full set of attributes:

@ -4,6 +4,8 @@ Configuring [Sonarr](https://sonarr.tv/) is optional but will allow you to send
Sonarr V2 may work, but it is not supported please upgrade to V3 if you can.
Items in your List Exclusions will be ignored by PMM.
A `sonarr` mapping can be either in the root of the config file as global mapping for all libraries, or you can specify the `sonarr` mapping individually per library.
Below is a `sonarr` mapping example and the full set of attributes:

@ -9,6 +9,7 @@ Below is a `trakt` mapping example and the full set of attributes:
trakt:
client_id: ################################################################
client_secret: ################################################################
pin:
authorization:
access_token:
token_type:
@ -22,22 +23,17 @@ trakt:
|:----------------|:--------------------------------|:-------:|:--------:|
| `client_id` | Trakt Application Client ID | N/A | ✅ |
| `client_secret` | Trakt Application Client Secret | N/A | ✅ |
| `pin` | Trakt Pin | None | ❌ |
* All other attributes will be filled in by the script.
* To connect to Trakt.tv you must create a Trakt application and supply the script the `client id` and `client secret` provided, please do the following:
* To connect to Trakt.tv you must create a Trakt application and supply the script the `client_id`, `client_secret`, and `pin` provided, please do the following:
1. [Click here to create a Trakt API application.](https://trakt.tv/oauth/applications/new)
2. Enter a `Name` for the application.
3. Enter `urn:ietf:wg:oauth:2.0:oob` for `Redirect uri`.
4. Click the `SAVE APP` button.
5. Record the `Client ID` and `Client Secret`.
5. Record the `Client ID` and `Client Secret` as `client_id` and `client_secret` in your Configuration File.
6. Navigate to `https://trakt.tv/oauth/authorize?response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_id=<<CLIENT_ID>>` replacing `<<CLIENT_ID>>` with your Client ID.
7. Record the `PIN` as `pin` in your Configuration File.
* On the first run, the script will walk the user through the OAuth flow by producing a Trakt URL for the user to follow. Once authenticated at the Trakt URL, the user needs to return the code to the script. If the code is correct, the script will populate the `authorization` sub-attributes to use in subsequent runs.
<h4>OAuth Flow using Docker</h4>
To authenticate Trakt the first time, you need run the container with the `-it` flags in order to walk through the OAuth flow mentioned above. Once you have the Trakt authentication data saved into the YAML, you'll be able to run the container normally.
<h4>OAuth Flow using unRAID Docker</h4>
Directions on how to authenticate Trakt on unRAID can be found on the [unRAID Walkthrough](../home/guides/unraid.md#advanced-installation-authenticating-trakt-or-myanimelist) page.
* Run the script shortly after obtaining your pin I don't know if it expires at any point or not.

@ -430,6 +430,7 @@ class ConfigFile:
self.Trakt = Trakt(self, {
"client_id": check_for_attribute(self.data, "client_id", parent="trakt", throw=True),
"client_secret": check_for_attribute(self.data, "client_secret", parent="trakt", throw=True),
"pin": check_for_attribute(self.data, "pin", parent="trakt", default_is_none=True),
"config_path": self.config_path,
"authorization": self.data["trakt"]["authorization"] if "authorization" in self.data["trakt"] else None
})

@ -6,7 +6,6 @@ from ruamel import yaml
logger = util.logger
redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
redirect_uri_encoded = redirect_uri.replace(":", "%3A")
base_url = "https://api.trakt.tv"
builders = [
"trakt_collected_daily", "trakt_collected_weekly", "trakt_collected_monthly", "trakt_collected_yearly", "trakt_collected_all",
@ -33,6 +32,7 @@ class Trakt:
self.config = config
self.client_id = params["client_id"]
self.client_secret = params["client_secret"]
self.pin = params["pin"]
self.config_path = params["config_path"]
self.authorization = params["authorization"]
logger.secret(self.client_secret)
@ -41,13 +41,16 @@ class Trakt:
self._authorization()
def _authorization(self):
url = f"https://trakt.tv/oauth/authorize?response_type=code&client_id={self.client_id}&redirect_uri={redirect_uri_encoded}"
logger.info(f"Navigate to: {url}")
logger.info("If you get an OAuth error your client_id or client_secret is invalid")
webbrowser.open(url, new=2)
try: pin = util.logger_input("Trakt pin (case insensitive)", timeout=300).strip()
except TimeoutExpired: raise Failed("Input Timeout: Trakt pin required.")
if not pin: raise Failed("Trakt Error: No input Trakt pin required.")
if self.pin:
pin = self.pin
else:
url = f"https://trakt.tv/oauth/authorize?response_type=code&redirect_uri={redirect_uri}&client_id={self.client_id}"
logger.info(f"Navigate to: {url}")
logger.info("If you get an OAuth error your client_id or client_secret is invalid")
webbrowser.open(url, new=2)
try: pin = util.logger_input("Trakt pin (case insensitive)", timeout=300).strip()
except TimeoutExpired: raise Failed("Input Timeout: Trakt pin required.")
if not pin: raise Failed("Trakt Error: Trakt pin required.")
json = {
"code": pin,
"client_id": self.client_id,
@ -94,6 +97,7 @@ class Trakt:
if self.authorization != authorization and not self.config.read_only:
yaml.YAML().allow_duplicate_keys = True
config, ind, bsi = yaml.util.load_yaml_guess_indent(open(self.config_path))
config["trakt"]["pin"] = None
config["trakt"]["authorization"] = {
"access_token": authorization["access_token"],
"token_type": authorization["token_type"],

Loading…
Cancel
Save