-
Notifications
You must be signed in to change notification settings - Fork 5
fix: Explicit NEEDS_APPLICATION_ID declaration #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,9 @@ | ||||||||||||||||||||||||||||
| # -*- coding: utf-8 -*- | ||||||||||||||||||||||||||||
| """Authentication methods""" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| __author__ = 'Jon Nappi, Elan Ruusamäe' | ||||||||||||||||||||||||||||
| __author__ = "Jon Nappi, Elan Ruusamäe" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| from getpass import getpass | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| from trakt.config import AuthConfig | ||||||||||||||||||||||||||||
| from trakt.core import DEVICE_AUTH, OAUTH_AUTH, PIN_AUTH, api | ||||||||||||||||||||||||||||
|
|
@@ -20,32 +22,42 @@ def oauth_auth(*args, config, **kwargs): | |||||||||||||||||||||||||||
| return OAuthAdapter(*args, client=api(), config=config, **kwargs).authenticate() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def device_auth(config): | ||||||||||||||||||||||||||||
| def device_auth(*args, config, **kwargs): | ||||||||||||||||||||||||||||
| from trakt.auth.device import DeviceAuthAdapter | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return DeviceAuthAdapter(client=api(), config=config).authenticate() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Expose NEEDS_APPLICATION_ID on wrapper functions so init_auth can detect it | ||||||||||||||||||||||||||||
| pin_auth.NEEDS_APPLICATION_ID = True | ||||||||||||||||||||||||||||
| oauth_auth.NEEDS_APPLICATION_ID = False | ||||||||||||||||||||||||||||
| device_auth.NEEDS_APPLICATION_ID = False | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def get_client_info(app_id: bool, config: AuthConfig): | ||||||||||||||||||||||||||||
| """Helper function to poll the user for Client ID and Client Secret | ||||||||||||||||||||||||||||
| strings | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| :return: A 2-tuple of client_id, client_secret | ||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
| print('If you do not have a client ID and secret. Please visit the ' | ||||||||||||||||||||||||||||
| 'following url to create them.') | ||||||||||||||||||||||||||||
| print('https://trakt.tv/oauth/applications') | ||||||||||||||||||||||||||||
| client_id = input('Please enter your client id: ') | ||||||||||||||||||||||||||||
| client_secret = input('Please enter your client secret: ') | ||||||||||||||||||||||||||||
| print( | ||||||||||||||||||||||||||||
| "If you do not have a client ID and secret. Please visit the " | ||||||||||||||||||||||||||||
| "following url to create them." | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
| print("https://trakt.tv/oauth/applications") | ||||||||||||||||||||||||||||
| client_id = input("Please enter your client id: ") | ||||||||||||||||||||||||||||
| client_secret = getpass("Please enter your client secret: ") | ||||||||||||||||||||||||||||
| if app_id: | ||||||||||||||||||||||||||||
| msg = f'Please enter your application ID ({config.APPLICATION_ID}): ' | ||||||||||||||||||||||||||||
| msg = f"Please enter your application ID ({config.APPLICATION_ID}): " | ||||||||||||||||||||||||||||
| user_input = input(msg) | ||||||||||||||||||||||||||||
| if user_input: | ||||||||||||||||||||||||||||
| config.APPLICATION_ID = user_input | ||||||||||||||||||||||||||||
| return client_id, client_secret | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def init_auth(method: str, *args, client_id=None, client_secret=None, store=False, **kwargs): | ||||||||||||||||||||||||||||
| def init_auth( | ||||||||||||||||||||||||||||
| method: str, *args, client_id=None, client_secret=None, store=False, **kwargs | ||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||
|
Comment on lines
+58
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: store parameter is unused (functional regression). See proposed fix in Lines 86. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| """Run the auth function specified by *AUTH_METHOD* | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| :param store: Boolean flag used to determine if your trakt api auth data | ||||||||||||||||||||||||||||
|
|
@@ -60,16 +72,15 @@ def init_auth(method: str, *args, client_id=None, client_secret=None, store=Fals | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| config = config_factory() | ||||||||||||||||||||||||||||
| adapter = methods.get(method, PIN_AUTH) | ||||||||||||||||||||||||||||
| adapter = methods.get(method, pin_auth) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
| Update client_id, client_secret from input or ask them interactively | ||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
| if client_id is None and client_secret is None: | ||||||||||||||||||||||||||||
| client_id, client_secret = get_client_info(adapter.NEEDS_APPLICATION_ID, config) | ||||||||||||||||||||||||||||
| client_id, client_secret = get_client_info( | ||||||||||||||||||||||||||||
| getattr(adapter, "NEEDS_APPLICATION_ID", False), config | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
| config.CLIENT_ID, config.CLIENT_SECRET = client_id, client_secret | ||||||||||||||||||||||||||||
|
Comment on lines
80
to
84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Prompt when either client_id or client_secret is missing; keep provided values intact. - if client_id is None and client_secret is None:
- client_id, client_secret = get_client_info(
- getattr(adapter, "NEEDS_APPLICATION_ID", False), config
- )
+ if client_id is None or client_secret is None:
+ entered_id, entered_secret = get_client_info(
+ getattr(adapter, "NEEDS_APPLICATION_ID", False), config
+ )
+ client_id = client_id or entered_id
+ client_secret = client_secret or entered_secret📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| adapter(*args, config=config, **kwargs) | ||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Return adapter result and persist when requested. - adapter(*args, config=config, **kwargs)
+ result = adapter(*args, config=config, **kwargs)
+ if store:
+ config.store()
+ return result📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if store: | ||||||||||||||||||||||||||||
| config.store() | ||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Make prompts resilient and reuse existing config values.
Allow pressing Enter to keep preloaded values; don’t force retyping secrets.
📝 Committable suggestion
🤖 Prompt for AI Agents