@@ -433,7 +433,8 @@ async def authenticate(self,
433
433
user_token : Optional [str ] = None ,
434
434
browser_name : Optional [str ] = None ,
435
435
browser_new : int = 2 ,
436
- use_browser : bool = True ):
436
+ use_browser : bool = True ,
437
+ auth_url_callback : Optional [Callable [[str ], Awaitable [None ]]] = None ):
437
438
"""Start the user authentication flow\n
438
439
If callback_func is not set, authenticate will wait till the authentication process finished and then return
439
440
the access_token and the refresh_token
@@ -447,8 +448,14 @@ async def authenticate(self,
447
448
:param browser_new: controls in which way the link will be opened in the browser.
448
449
See `the webbrowser documentation <https://docs.python.org/3/library/webbrowser.html#webbrowser.open>`__ for more info
449
450
|default|:code:`2`
450
- :param use_browser: controls if a browser should be opened by default or if the url to authenticate via should printed to the log
451
- |default|:code: True
451
+ :param use_browser: controls if a browser should be opened.
452
+ If set to :const:`False`, the browser will not be opened and the URL to be opened will either be printed to the info log or
453
+ send to the specified callback function (controlled by :const:`~twitchAPI.oauth.UserAuthenticator.authenticate.params.auth_url_callback`)
454
+ |default|:code:`True`
455
+ :param auth_url_callback: a async callback that will be called with the url to be used for the authentication flow should
456
+ :const:`~twitchAPI.oauth.UserAuthenticator.authenticate.params.use_browser` be :const:`False`.
457
+ If left as None, the URL will instead be printed to the info log
458
+ |default|:code:`None`
452
459
:return: None if callback_func is set, otherwise access_token and refresh_token
453
460
:raises ~twitchAPI.type.TwitchAPIException: if authentication fails
454
461
:rtype: None or (str, str)
@@ -468,7 +475,10 @@ async def authenticate(self,
468
475
browser = webbrowser .get (browser_name )
469
476
browser .open (self ._build_auth_url (), new = browser_new )
470
477
else :
471
- self .logger .info (f"To authenticate open: { self ._build_auth_url ()} " )
478
+ if auth_url_callback is not None :
479
+ await auth_url_callback (self ._build_auth_url ())
480
+ else :
481
+ self .logger .info (f"To authenticate open: { self ._build_auth_url ()} " )
472
482
while self ._user_token is None :
473
483
await asyncio .sleep (0.01 )
474
484
# now we need to actually get the correct token
0 commit comments