Skip to content

Commit

Permalink
Merge pull request Teekeks#307 from Latent-Logic/oauth-log-auth-url
Browse files Browse the repository at this point in the history
Allow not auto-opening browser for oauth workflow
  • Loading branch information
Teekeks authored Dec 19, 2024
2 parents f09e710 + 67e2333 commit db1c5e3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions twitchAPI/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ async def authenticate(self,
callback_func: Optional[Callable[[str, str], None]] = None,
user_token: Optional[str] = None,
browser_name: Optional[str] = None,
browser_new: int = 2):
browser_new: int = 2,
use_browser: bool = True):
"""Start the user authentication flow\n
If callback_func is not set, authenticate will wait till the authentication process finished and then return
the access_token and the refresh_token
Expand All @@ -446,6 +447,8 @@ async def authenticate(self,
:param browser_new: controls in which way the link will be opened in the browser.
See `the webbrowser documentation <https://docs.python.org/3/library/webbrowser.html#webbrowser.open>`__ for more info
|default|:code:`2`
:param use_browser: controls if a browser should be opened by default or if the url to authenticate via should printed to the log
|default|:code: True
:return: None if callback_func is set, otherwise access_token and refresh_token
:raises ~twitchAPI.type.TwitchAPIException: if authentication fails
:rtype: None or (str, str)
Expand All @@ -460,9 +463,12 @@ async def authenticate(self,
# wait for the server to start up
while not self._server_running:
await asyncio.sleep(0.01)
# open in browser
browser = webbrowser.get(browser_name)
browser.open(self._build_auth_url(), new=browser_new)
if use_browser:
# open in browser
browser = webbrowser.get(browser_name)
browser.open(self._build_auth_url(), new=browser_new)
else:
self.logger.info(f"To authenticate open: {self._build_auth_url()}")
while self._user_token is None:
await asyncio.sleep(0.01)
# now we need to actually get the correct token
Expand Down

0 comments on commit db1c5e3

Please sign in to comment.