DeviceCodeReauthorizer
in package
implements
ReauthorizerInterface
Signs in again with Google's device flow: shows a code, then waits for someone to enter it at `google.com/device` with the account that should be signed in.
The prompt callback receives {verification_uri, user_code, expires_in, interval} and decides how to show it: a log line, a DM to the bot's owner.
The code lasts about thirty minutes. Polling follows the interval Google asks
for and slows down when told to.
Google lets the device flow ask for only some scopes. Of YouTube's, those are
DEVICE_SCOPES: youtube, which covers reading, posting to and
moderating live chat, and youtube.readonly. Asking for any other fails
before a code is shown.
Tags
Table of Contents
Interfaces
- ReauthorizerInterface
- A way to get a brand-new grant when the existing one can no longer be refreshed: there is no refresh token, or Google revoked it.
Constants
- DEVICE_SCOPES : mixed = [\YouTube\Auth\Scope::YOUTUBE, \YouTube\Auth\Sc...
- The YouTube scopes Google allows a device sign-in to ask for.
Properties
- $clock : ?Closure
- $loop : LoopInterface
- $oauth : OAuth
- $pending : ?PromiseInterface
- The attempt in flight, so concurrent callers share one prompt.
- $prompt : mixed
- $scopes : array<string|int, mixed>
Methods
- __construct() : mixed
- disabled() : ReauthorizerInterface
- A reauthorizer that never succeeds: the default, so a headless client surfaces the original failure instead of waiting on a prompt nobody sees.
-
reauthorize()
: PromiseInterface<string|int, array{access_token: string, refresh_token?: string|null, expires_in?: int|null, expires_at?: int|null, scope?: list
|null, token_type?: string|null}> - now() : int
- poll() : void
- start() : PromiseInterface<string|int, array<string, mixed>>
Constants
DEVICE_SCOPES
The YouTube scopes Google allows a device sign-in to ask for.
public
mixed
DEVICE_SCOPES
= [\YouTube\Auth\Scope::YOUTUBE, \YouTube\Auth\Scope::YOUTUBE_READONLY]
Properties
$clock read-only
private
?Closure
$clock
= null
$loop
private
LoopInterface
$loop
$oauth read-only
private
OAuth
$oauth
$pending
The attempt in flight, so concurrent callers share one prompt.
private
?PromiseInterface
$pending
= null
$prompt
private
mixed
$prompt
= null
$scopes read-only
private
array<string|int, mixed>
$scopes
= [Scope::YOUTUBE]
Methods
__construct()
public
__construct(OAuth $oauth[, array<int, string> $scopes = [Scope::YOUTUBE] ][, callable(array<string, mixed>): void|null $prompt = null ][, ?LoopInterface $loop = null ][, callable(): int|null $clock = null ]) : mixed
Parameters
- $oauth : OAuth
- $scopes : array<int, string> = [Scope::YOUTUBE]
-
The scopes to ask for.
- $prompt : callable(array<string, mixed>): void|null = null
-
Shown the code to enter.
- $loop : ?LoopInterface = null
- $clock : callable(): int|null = null
-
The time as a Unix timestamp, for tests.
disabled()
A reauthorizer that never succeeds: the default, so a headless client surfaces the original failure instead of waiting on a prompt nobody sees.
public
static disabled() : ReauthorizerInterface
Return values
ReauthorizerInterfacereauthorize()
public
reauthorize() : PromiseInterface<string|int, array{access_token: string, refresh_token?: string|null, expires_in?: int|null, expires_at?: int|null, scope?: list|null, token_type?: string|null}>
Return values
PromiseInterface<string|int, array{access_token: string, refresh_token?: string|null, expires_in?: int|null, expires_at?: int|null, scope?: listnow()
private
now() : int
Return values
intpoll()
private
poll(Deferred<string|int, array<string, mixed>> $deferred, string $deviceCode, float $interval, int $deadline) : void
Parameters
- $deferred : Deferred<string|int, array<string, mixed>>
- $deviceCode : string
- $interval : float
- $deadline : int
start()
private
start() : PromiseInterface<string|int, array<string, mixed>>