youtube-deno
youtube-deno copied to clipboard
Add support for refreshing access tokens
Currently, the response_type
parameter is set by default to token
. This means we can't refresh the access token obtained.
To refresh access tokens, access_type=offline
has to be additionally passed while making the oauth request, which does not work with response_type=token
. Instead, response_type
must be set to code
.
It is desired that if the user enters the refresh token (if they have it), youtube-deno handles the refresh flow and generates the new access token internally.
To achieve this:
- Remove the default value of
response_type
from here and let the user enter it as a required parameter. - Change the second argument of the YouTube class to an object type, which can take three types of values:
{access_token: "some-token"}
,{refresh_token: "some-token"}
, or{auth_code: "some-code"}
. - If the access_token is directly passed, store it to the
this.token
class variable. Else if refresh_token is passed, trigger the refresh flow and the returned access token is stored inthis.token
. If auth_code is passed, exchange it for access_token and store it inthis.token
.