@@ -202,28 +202,6 @@ def http(self) -> ManagedHTTPClient:
202202 """
203203 return self ._http
204204
205- async def device_code_flow (self , * , scopes : Scopes | None = None ) -> DeviceCodeFlowResponse :
206- """|coro|
207-
208- .. warning::
209-
210- It's not intended to use DCF when storing a ``client-secret`` is a safe and practical option.
211- DCF is intended to be used on user devices where storing your ``client-secret`` is not possible.
212-
213- .. note::
214-
215- When using tokens generated through DCF, the only ``EventSub`` transport available is traditional websockets.
216- Using ``Conduits`` and ``Webhooks`` are not available as they require a ``App Token``.
217-
218- Method which starts a Twitch Device Code Flow.
219-
220- The DCF (Device Code Flow) is used to obtain an access/refresh token pair for use on client-side applications where
221- storing a ``client-secret`` would be unsafe E.g. a users device (Phone, TV, etc...).
222-
223- When using a token
224- """
225- return await self ._http .device_code_flow (scopes = scopes )
226-
227205 async def set_adapter (self , adapter : BaseAdapter [Any ]) -> None :
228206 """|coro|
229207
@@ -436,7 +414,55 @@ async def login_dcf(
436414 scopes : Scopes | None = None ,
437415 force_flow : bool = False ,
438416 ) -> DeviceCodeFlowResponse | None :
439- # TODO: Docs...
417+ """|coro|
418+
419+ .. warning::
420+
421+ DCF is intended to be used when your application cannot safely store a ``client-secret``. E.g. on a users
422+ device (phone, tv, etc...).
423+
424+ .. note::
425+
426+ This method should be called before :meth:`.start_dcf`.
427+
428+ Method to initiate a DCF (Device Code Flow) and setup the :class:`~twitchio.Client`.
429+
430+ If a token has been loaded automcatically via this method, a DCF authorization flow will not be initiated.
431+ You can change this behaviour by setting the ``force_flow`` keyword-only argument to ``True``. This will force the
432+ user to re-authenticate via DCF.
433+
434+ This method works together with :meth:`.start_dcf` to complete the flow and setup the :class:`~twitchio.Client`.
435+ You should call :meth:`.start_dcf` after this method.
436+
437+ Parameters
438+ ----------
439+ load_token: bool
440+ Whether to attempt to load an existing saved token. Defaults to ``True``.
441+ save_token: bool
442+ Whether to save any tokens loaded into the :class:`~twitchio.Client` at close. Defaults to ``True``.
443+ scopes: :class:`~twitchio.Scopes` | ``None``
444+ A :class:`~twitchio.Scopes` object with the required scopes set for the user to authenticate with. If you pass
445+ these to the :class:`~twitchio.Client` constructor you do not need to pass them here.
446+ force_flow: bool
447+ Wtheer to force the user to authenticate, even when an existing token is found and valid. Useful when you
448+ require new scopes or for testing. Defaults to ``False``.
449+
450+ Returns
451+ -------
452+ DeviceCodeFlowResponse
453+ A dict with the keys: ``device_code``, ``expires_in``, ``interval``, ``user_code`` and ``verification_uri``.
454+ None
455+ The Device Code Flow was not initiated; E.g. an existing token was loaded and ``force_flow`` was ``False``.
456+
457+ Raises
458+ ------
459+ RuntimeError
460+ Invalid ``client_id`` was passed to the :class:`~twitchio.Client`.
461+ RuntimeError
462+ You cannot use a ``client_secret`` with DCF.
463+ HTTPException
464+ An error was raised making a request to Twitch.
465+ """
440466 if self ._login_called :
441467 return
442468
@@ -460,7 +486,7 @@ async def login_dcf(
460486 await self ._setup ()
461487
462488 if not self ._http ._tokens :
463- return await self .device_code_flow (scopes = scopes )
489+ return await self ._http . device_code_flow (scopes = scopes )
464490
465491 async def start_dcf (
466492 self ,
@@ -527,11 +553,11 @@ async def start_dcf(
527553 RuntimeError
528554 A valid :class:`~twitchio.User` could not be fetched with the token received.
529555 DeviceCodeFlowException
530- .. .
556+ An exception was raised during a request to Twitch for DCF. Check the device code is valid .
531557 HTTPException
532- .. .
558+ An exception was raised during a request to Twitch .
533559 TimeoutError
534- .. .
560+ Timed-out waiting for the user to complete the DCF .
535561 """
536562 if not self ._login_called :
537563 raise RuntimeError ('Client failed to start: "login_dcf" must be called before "start_dcf".' )
0 commit comments